aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-01-24 15:10:17 +0000
committerGitHub <noreply@github.com>2024-01-24 15:10:17 +0000
commit981d172f7f0613d30bef4a8934b361db7fcf0672 (patch)
treebda610af879108b30ba43e39579900e35689543c /Python/bytecodes.c
parent6fadd68da5dd928847264b17f62a5b8b369c1c1e (diff)
downloadcpython-981d172f7f0613d30bef4a8934b361db7fcf0672.tar.gz
cpython-981d172f7f0613d30bef4a8934b361db7fcf0672.zip
GH-112354: `END_FOR` instruction to only pop one value. (GH-114247)
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 18749ce60ec..fef3cd4ff7d 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -265,9 +265,9 @@ dummy_func(
res = NULL;
}
- macro(END_FOR) = POP_TOP + POP_TOP;
+ macro(END_FOR) = POP_TOP;
- inst(INSTRUMENTED_END_FOR, (receiver, value --)) {
+ inst(INSTRUMENTED_END_FOR, (receiver, value -- receiver)) {
TIER_ONE_ONLY
/* Need to create a fake StopIteration error here,
* to conform to PEP 380 */
@@ -2550,8 +2550,8 @@ dummy_func(
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
Py_DECREF(iter);
STACK_SHRINK(1);
- /* Jump forward oparg, then skip following END_FOR instruction */
- JUMPBY(oparg + 1);
+ /* Jump forward oparg, then skip following END_FOR and POP_TOP instruction */
+ JUMPBY(oparg + 2);
DISPATCH();
}
// Common case: no jump, leave it to the code generator
@@ -2599,8 +2599,8 @@ dummy_func(
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
STACK_SHRINK(1);
Py_DECREF(iter);
- /* Skip END_FOR */
- target = next_instr + oparg + 1;
+ /* Skip END_FOR and POP_TOP */
+ target = next_instr + oparg + 2;
}
INSTRUMENTED_JUMP(this_instr, target, PY_MONITORING_EVENT_BRANCH);
}
@@ -2621,8 +2621,8 @@ dummy_func(
}
Py_DECREF(iter);
STACK_SHRINK(1);
- /* Jump forward oparg, then skip following END_FOR instruction */
- JUMPBY(oparg + 1);
+ /* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */
+ JUMPBY(oparg + 2);
DISPATCH();
}
}
@@ -2667,8 +2667,8 @@ dummy_func(
}
Py_DECREF(iter);
STACK_SHRINK(1);
- /* Jump forward oparg, then skip following END_FOR instruction */
- JUMPBY(oparg + 1);
+ /* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */
+ JUMPBY(oparg + 2);
DISPATCH();
}
}
@@ -2709,8 +2709,8 @@ dummy_func(
if (r->len <= 0) {
STACK_SHRINK(1);
Py_DECREF(r);
- // Jump over END_FOR instruction.
- JUMPBY(oparg + 1);
+ // Jump over END_FOR and POP_TOP instructions.
+ JUMPBY(oparg + 2);
DISPATCH();
}
}