diff options
author | Mark Shannon <mark@hotpy.org> | 2024-01-24 15:10:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 15:10:17 (GMT) |
commit | 981d172f7f0613d30bef4a8934b361db7fcf0672 (patch) | |
tree | bda610af879108b30ba43e39579900e35689543c /Python/compile.c | |
parent | 6fadd68da5dd928847264b17f62a5b8b369c1c1e (diff) | |
download | cpython-981d172f7f0613d30bef4a8934b361db7fcf0672.zip cpython-981d172f7f0613d30bef4a8934b361db7fcf0672.tar.gz cpython-981d172f7f0613d30bef4a8934b361db7fcf0672.tar.bz2 |
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/compile.c')
-rw-r--r-- | Python/compile.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index 2a6291c..7cf05dd 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3075,7 +3075,12 @@ compiler_for(struct compiler *c, stmt_ty s) ADDOP_JUMP(c, NO_LOCATION, JUMP, start); USE_LABEL(c, cleanup); + /* It is important for instrumentation that the `END_FOR` comes first. + * Iteration over a generator will jump to the first of these instructions, + * but a non-generator will jump to a later instruction. + */ ADDOP(c, NO_LOCATION, END_FOR); + ADDOP(c, NO_LOCATION, POP_TOP); compiler_pop_fblock(c, FOR_LOOP, start); @@ -5390,7 +5395,12 @@ compiler_sync_comprehension_generator(struct compiler *c, location loc, ADDOP_JUMP(c, elt_loc, JUMP, start); USE_LABEL(c, anchor); + /* It is important for instrumentation that the `END_FOR` comes first. + * Iteration over a generator will jump to the first of these instructions, + * but a non-generator will jump to a later instruction. + */ ADDOP(c, NO_LOCATION, END_FOR); + ADDOP(c, NO_LOCATION, POP_TOP); } return SUCCESS; |