Skip to content

gh-148874: add flag to CALL to skip periodic check in with#149019

Open
NekoAsakura wants to merge 7 commits intopython:mainfrom
NekoAsakura:gh-148874/with-signal-exit-skip
Open

gh-148874: add flag to CALL to skip periodic check in with#149019
NekoAsakura wants to merge 7 commits intopython:mainfrom
NekoAsakura:gh-148874/with-signal-exit-skip

Conversation

@NekoAsakura
Copy link
Copy Markdown
Contributor

@NekoAsakura NekoAsakura commented Apr 26, 2026

Copy link
Copy Markdown
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good in general, but I've a few comments.

I'd prefer explicit oparg >> 1 and oparg & 1 so the tools can more easily understand offsets.

Comment thread Doc/library/dis.rst Outdated
Calls with keyword arguments are now handled by :opcode:`CALL_KW`.

.. versionchanged:: next
``argc`` is now the oparg shifted right by one.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also explain what the low bit is for.

Comment thread Include/internal/pycore_opcode_utils.h Outdated
#define RESUME_OPARG_LOCATION_MASK 0x7
#define RESUME_OPARG_DEPTH1_MASK 0x8

#define CALL_OPARG_SKIP_PENDING_MASK 0x1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid using macros (or inline functions) for this?
This is sp that our tools can understand the offsets in calls.
The tools can (with a bit of modification) understand oparg >> 1, but CALL_ARGCOUNT will require special casing CALL_ARGCOUNT making it more complex.

(The reason this matters is that we will want to convert fixes sized arrays to scalars in the code generator in the future)

Also, comments anywhere there is masking or shifting would be clearer, IMO, than opaque macros.

Comment thread Lib/dis.py Outdated
elif deop in (CALL, INSTRUMENTED_CALL):
argval = arg >> 1
if arg & 1:
argrepr = f"{argval} + skip_pending"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the term "no interrupt" for jumps, so could you use that here for consistency?

Comment thread Python/bytecodes.c Outdated
ERROR_IF(err != 0);
}

replaced op(_CHECK_PERIODIC_AT_END_PENDING, (--)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
replaced op(_CHECK_PERIODIC_AT_END_PENDING, (--)) {
replaced op(_CHECK_PERIODIC_IF_INTERRUPTIBLE, (--)) {

The meaning of _CHECK_PERIODIC_AT_END_PENDING isn't clear.

Comment thread Python/optimizer.c Outdated
[_FOR_ITER_VIRTUAL] = _FOR_ITER_VIRTUAL_TIER_TWO,
[_ITER_NEXT_LIST] = _ITER_NEXT_LIST_TIER_TWO,
[_CHECK_PERIODIC_AT_END] = _TIER2_RESUME_CHECK,
[_CHECK_PERIODIC_AT_END_PENDING] = _TIER2_RESUME_CHECK,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be replaced by _NOP if oparg & 1 is 0 or _CHECK_PERIODIC_AT_END if oparg & 1 is 1 in the front-end, so I wouldn't expect it to appear here.

We do much the same with _PUSH_NULL_CONDITIONAL, converting it to _NOP or _PUSH_NULL

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Apr 28, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32483173 | 📁 Comparing 40fc50c against main (5d41632)

  🔍 Preview build  

33 files changed · + 1 added · ± 32 modified

+ Added

± Modified

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

Thanks for the review <3

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

A bit of clash with #148831, having a look.

@markshannon
Copy link
Copy Markdown
Member

A bit of clash with #148831, having a look.

Probably the magic number. You'll need to merge in main then increase it again.

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

Yep was fixed in #149121

@markshannon markshannon self-requested a review April 30, 2026 10:36
Copy link
Copy Markdown
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good.

I don't we need a new uop, changing _CHECK_PERIODIC_AT_END should be sufficient.

Comment thread Doc/library/dis.rst Outdated
Comment thread Python/bytecodes.c
ERROR_IF(err != 0);
}

op(_CHECK_PERIODIC_IF_INTERRUPTIBLE, (--)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need a new uop. The if (oparg & 1) { can just be inserted in _CHECK_PERIODIC_AT_END

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, _CHECK_PERIODIC_AT_END is also used by CALL_FUNCTION_EX, CALL_EX_NON_PY_GENERAL, INSTRUMENTED_CALL_FUNCTION_EX, CALL_KW_NON_PY.

*/

#define PYC_MAGIC_NUMBER 3665
#define PYC_MAGIC_NUMBER 3666
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need bumping again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I already bumped it. Current upstream HEAD:

#define PYC_MAGIC_NUMBER 3665

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 30, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Co-authored-by: Mark Shannon <Mark.Shannon@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants