GeezerVison is showing github.com — gh-131798: JIT: Narrow the return type of `_BINARY_OP_SUBSCR_STR_INT` to `str` by tomasr8 · Pull Request #132153 · python/cpython
Conversation
tomasr8
commented
Apr 6, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
I tested this by finding another instruction which contains a unicode guard, in this case BINARY_OP_ADD_UNICODE and checking that the guard is removed if one of the operands is the result of _BINARY_OP_SUBSCR_STR_INT. Let me know if there's a better way to test this!
I also noticed that some other uops like _BINARY_OP_ADD_UNICODE check if the operands are constants. Should we add it here as well? I don't know if we gain much from that though, code like 'foo'[0] is not very common.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
I also noticed that some other uops like _BINARY_OP_ADD_UNICODE check if the operands are constants. Should we add it here as well? I don't know if we gain much from that though, code like 'foo'[0] is not very common.
The constant checking is sort of a relic. We don't even do anything with it. So it's fine to leave it out for now.
|
tomasr8 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
brandtbucher
commented
Apr 8, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
I don't know if we gain much from that though, code like 'foo'[0] is not very common.
Just a quick note on this: "constant" here means anything the JIT knows to be a constant value at runtime, not just things that are statically constant in the source. So it could be something like MODULE_GLOBAL[len(foo) - 1], for instance.
The constant checking is sort of a relic. We don't even do anything with it.
I disagree, constant symbols are pretty powerful, and we should be using them more. For example, knowing constant values currently allows us to entirely remove conditional branches, type version checks, etc. @savannahostrowski also added the new _POP_TWO_LOAD_CONST_INLINE_BORROW instruction (and is in the process of using it in the remaining _BINARY_OP_* and _COMPARE_OP_* uops, which allows us to remove these operations entirely when the result is immortal).
I agree that it's probably not worth adding to this uop specifically (at least not without some examples of real-world code it would optimize), but I do think that tracking constant values in general is a good thing.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Want to tidy up the test before I merge?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the clarification about the meaning of constants in the JIT! That's an important distinction to make for sure.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|