-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-117270: Add missed change to COMPARE_OP from 3.12 to dis documentation #117272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Christopher-Chianelli
wants to merge
1
commit into
python:main
Choose a base branch
from
Christopher-Chianelli:dis-docs-mains
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
I don't believe this is true. The index is not stored in the most significant bits of
oparg
and to be honest it's not easy to define most significant bits in Python's integer - it's not fixed length.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.
And I don't think the index is ever stored in the four lowest bits - that indicates we have 16 (or at least 9) operations.
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.
Notice that even for 3.13, it did not mention the version change for the operation name shift. I think we can just leave it there and just fix the 3.12 docs.
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.
For opcodes, the arg is a byte unless prefixed by EXTENDED_ARG; for 3.13, it the top 3 bits (hence the shift by 5), for 3.12, it the top 4 bits (with the MSB always 0, and hence, the shift by 4).
No strong opinion on including/excluding the versionchanged; I prefer having it as a record so people looking at the latest docs know code that a breaking change occurred on 3.12 for COMPARE_OP.
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.
And that's a C-level implementation detail that's not exposed or documented. "Top X bits" only works when the variable is fixed-size, and when we are discussing in Python scope,
opname
is not fixed-size because it's anint
. Even in C code,oparg
is often declared asint
oruint16_t
in functions, and it would be super confusing when "top X bits" means the top X bits when it is a byte. I would assume that's why the documentation below used "the fifth-lowest bit" instead of "the fourth-highest bit" - counting from lowest is always well defined, but counting from the highest is not.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.
Would "The cmp_op index now starts at the fifth-lowest bit of oparg." be a better wording?
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.
"start" is also ambiguous in my opinion. It's not clear whether the data goes "high" or "low" starting from a specific position. (That's why I think
cmp_op[opname >> 5]
is the best way to describe the fact as it is).If we have to have a version-changed note, I would prefer something like "The cmp_op index is stored in bit(LSB maybe?) 7 to bit 4" or "The cmp_op index is stored in 8th lowest bit to 5th lowest bit". I believe the index is actually a 3-bit value instead of 4 but that might not be a big issue here. But we do have a 0-index vs 1-index issue.
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.
Maybe "the cmp_op index is now shifted 4 bits to the left"?