Description
Bug report
Bug description:
Repro: Check out this commit, build, and run python -mtest test_monitoring -mtest_implicit_stop_iteration
.
Context: The unspecialized implementation of FOR_ITER
has some built-in opcode fusion, in that it skips the following END_FOR
and POP_TOP
when tp_iternext
returns NULL
. When the iterator is a generator, as it is in ExceptionMonitoringTest.test_implicit_stop_iteration()
, that means we skip the monitor_stop_iteration()
call in INSTRUMENTED_END_FOR
.
test_implicit_stop_iteration()
passes as written, though, because the FOR_ITER
in the helper function has been specialized to FOR_ITER_GEN
by the time the generator finishes, and FOR_ITER_GEN
's implementation doesn't perform the same fusion as FOR_ITER
.
This bug can be exposed by making this change to test_implicit_stop_iteration()
, so the FOR_ITER
stays unspecialized while iterating over the generator in question.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux