[issue41670] ceval traces code differently based with USE_COMPUTED_GOTOS

Ammar Askar report at bugs.python.org
Sun Aug 30 23:44:47 EDT 2020


Ammar Askar <ammar at ammaraskar.com> added the comment:

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 (())
              4 GET_ITER
        >>    6 FOR_ITER                 4 (to 12)
              8 STORE_FAST               0 (i)
             10 JUMP_ABSOLUTE            6

  6     >>   12 POP_BLOCK
             14 LOAD_CONST               2 (1)
             16 RETURN_VALUE

When computed gotos are disabled and there is a tracing function, instructions 0, 2, 4, 14 and 16 hit the `fast_next_opcode` label and have a chance to be traced as line hits. Note that `maybe_call_line_trace` will only cause a line hit if the instruction that starts a line (POP_BLOCK in this case) is being executed.

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 `fast_next_opcode`: https://github.com/python/cpython/blob/c3a651ad2544d7d1be389b63e9a4a58a92a31623/Python/ceval.c#L1054-L1059

When computed gotos are not enabled, there is no similar check for PREDICT (and might be too costly to add) causing this issue: https://github.com/python/cpython/blob/c3a651ad2544d7d1be389b63e9a4a58a92a31623/Python/ceval.c#L1131-L1141

----------
title: Windows and Linux execute the same code differently -> ceval traces code differently based with USE_COMPUTED_GOTOS

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41670>
_______________________________________


More information about the Python-bugs-list mailing list