Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add explanatory comment
  • Loading branch information
markshannon committed Jan 17, 2024
commit aece1df807ece25d16b5a77fc80680e16be96e7c
8 changes: 8 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3075,6 +3075,10 @@ 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);

Expand Down Expand Up @@ -5391,6 +5395,10 @@ 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);
}
Expand Down