Skip to content

STOP_ITERATION monitoring event is not triggered by unspecialized bytecode #116090

Closed as not planned
@swtaarrs

Description

@swtaarrs

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

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions