GH-128534: Fix behavior of branch monitoring for async for (GH-130847)

* Both branches in a pair now have a common source and are included in co_branches
This commit is contained in:
Mark Shannon 2025-03-07 14:30:31 +00:00 committed by GitHub
parent e5527f2cdd
commit 89df62c120
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 235 additions and 154 deletions

View file

@ -1341,6 +1341,8 @@ dummy_func(
}
tier1 op(_END_ASYNC_FOR, (awaitable_st, exc_st -- )) {
JUMPBY(0); // Pretend jump as we need source offset for monitoring
(void)oparg;
PyObject *exc = PyStackRef_AsPyObjectBorrow(exc_st);
assert(exc && PyExceptionInstance_Check(exc));
@ -1356,12 +1358,13 @@ dummy_func(
}
}
tier1 op(_MONITOR_BRANCH_RIGHT, ( -- )) {
INSTRUMENTED_JUMP(prev_instr, this_instr+1, PY_MONITORING_EVENT_BRANCH_RIGHT);
tier1 op(_MONITOR_END_ASYNC_FOR, ( -- )) {
assert((next_instr-oparg)->op.code == END_SEND || (next_instr-oparg)->op.code >= MIN_INSTRUMENTED_OPCODE);
INSTRUMENTED_JUMP(next_instr-oparg, this_instr+1, PY_MONITORING_EVENT_BRANCH_RIGHT);
}
macro(INSTRUMENTED_END_ASYNC_FOR) =
_MONITOR_BRANCH_RIGHT +
_MONITOR_END_ASYNC_FOR +
_END_ASYNC_FOR;
macro(END_ASYNC_FOR) = _END_ASYNC_FOR;