From 245656e7f462081988a397b3d77536133d889492 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 6 May 2024 18:29:19 -0700 Subject: [PATCH 1/2] Fix yield assertion when tracing --- Lib/test/test_monitoring.py | 11 +++++++++++ Python/bytecodes.c | 4 +++- Python/executor_cases.c.h | 4 +++- Python/generated_cases.c.h | 4 +++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py index eeb3f88a081750..6974bc5517ae5f 100644 --- a/Lib/test/test_monitoring.py +++ b/Lib/test/test_monitoring.py @@ -656,6 +656,17 @@ def func2(): self.check_lines(func2, [1,2,3,4,5,6]) + def test_generator_with_line(self): + + def f(): + def a(): + yield + def b(): + yield from a() + next(b()) + + self.check_lines(f, [1,3,5,4,2,4]) + class TestDisable(MonitoringTestBase, unittest.TestCase): def gen(self, cond): diff --git a/Python/bytecodes.c b/Python/bytecodes.c index b2a0dc030e20cc..91802a3eee094b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1121,7 +1121,9 @@ dummy_func( /* We don't know which of these is relevant here, so keep them equal */ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE - assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || + assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE || + frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION || + _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER || _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT || _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 5f15f67324292b..347a1e677a0832 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -1137,7 +1137,9 @@ /* We don't know which of these is relevant here, so keep them equal */ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE - assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || + assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE || + frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION || + _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER || _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT || _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 87098b0506522f..d41ad0c1e59c0b 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -6220,7 +6220,9 @@ /* We don't know which of these is relevant here, so keep them equal */ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE - assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || + assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE || + frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION || + _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND || _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER || _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT || _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR); From 5385d923003da7599787d9b2744696ccfefd0c2b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 01:39:25 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst new file mode 100644 index 00000000000000..cd545049f92693 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst @@ -0,0 +1 @@ +Add instrumented opcodes to YIELD_VALUE assertion for tracing cases.