-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Don't use EXTENDED_ARG_QUICK
in unquickened code
#95113
Comments
Yes, I think we should do this. It is how it should have been done all along. It is worth re-reading the discussion in #91945 first. Assuming I understand correctly:
I think we will need to change
to:
As an aside, I prefer |
It's a bit trickier than that. We would also need to teach Thankfully, for all recent CPython versions (3.7 was the furthest back I checked), we haven't ever traced any opcode following an At any rate, the PR I opened for this (#95121) doesn't change anything about the tracing behavior. The only difference between |
I thought we already had fixed tracing to not stomp on the oparg. Apparently not. It is easy enough to do that.
It shouldn't.
I agree. One event per instruction makes more sense than one per code-unit. |
Sorry, can you clarify? (I'm still stuck between the "instruction" and "code-unit" terminology.) Do you think my PR's approach is good, or do you also want to "fix" the tracing behavior (which skips tracing instructions after an |
Never mind, just saw your comment on the PR. |
|
…de (pythonGH-95121). (cherry picked from commit e402b26) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
EXTENDED_ARG_QUICK
is a problematic opcode, and I think we should expose it less than we currently do. It is the only "quickened" opcode emitted by the compiler and found incode.co_code
, which requires us to jump through strange hoops in several places (I'm looking at you,_PyOpcode_Original
). Even weirder, it traces asEXTENDED_ARG
at runtime.dis
documentationopcode
module (which still defines a misleadingly uselessEXTENDED_ARG
constant)HAVE_ARGUMENT
, even though it (obviously) uses its argumentstack_effect
Yet consumers of the bytecode must handle it correctly. We've already seen several bugs in CPython where we wrongly thought that we were handling extended arguments, and code that's been unchanged for years silently stopped working correctly. Let's avoid putting user code through the same pain.
I propose that we only emit the normal
EXTENDED_ARG
in the compiler, like we always have, and use_PyOpcode_Deopt
everywhere that_PyOpcode_Original
is being used now. We'll quickenEXTENDED_ARG
toEXTENDED_ARG_QUICK
just like all of the other*_QUICK
opcode variants. No need to change the magic number or anything, since old code will continue to work fine. AlthoughEXTENDED_ARG
is in theory a tiny bit slower (it deopts the next opcode using_PyOpcode_Deopt
), I doubt this is actually measurable.Thoughts? I really think we should try to do this in 3.11, since it's a relatively simple change.
CC @markshannon, @sweeneyde, @pablogsal
The text was updated successfully, but these errors were encountered: