-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
ceval traces code differently with USE_COMPUTED_GOTOS #85836
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
Comments
Coverage.py bug reports nedbat/coveragepy#1022 and nedbat/coveragepy#959 demonstrate the same Python code, with the same disassembly, executing differently. In https://discuss.python.org/t/same-python-version-different-optimizations-on-different-os/5098, Ammar Askar said:
|
minimal reproducer without coverage: import sys
def f():
try:
for i in []: pass
return 1
except:
return 2
def tracer(frame, event, _):
if event == 'line':
print("executing line {}".format(frame.f_lineno))
return tracer
sys.settrace(tracer)
f() With computed gotos this results in:
but without:
|
So I think this is a weird edge case with a set of opcode predictions (GET_ITER -> FOR_ITER -> POP_BLOCK) going outside of a line boundary. The disassembly of the reproducer above is: 4 0 SETUP_FINALLY 16 (to 18) 5 2 LOAD_CONST 1 (()) 6 >> 12 POP_BLOCK When computed gotos are disabled and there is a tracing function, instructions 0, 2, 4, 14 and 16 hit the When computed gotos are enabled, DISPATCH is a no-op and there is a special case for when tracing is enabled that causes every opcode to go through Lines 1054 to 1059 in c3a651a
When computed gotos are not enabled, there is no similar check for PREDICT (and might be too costly to add) causing this issue: Lines 1131 to 1141 in c3a651a
|
A couple of things to fix here. Firstly, the PREDICTion of POP_BLOCK in FOR_ITER shouldn't be there. POP_BLOCK doesn't normally occur after a loop and hasn't since we removed "pseudo exceptions" from the interpreter a couple of years ago. Secondly, there is the issue of PREDICTs skipping tracing. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: