Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.13a1 3563 (Add CALL_KW and remove KW_NAMES)
# Python 3.13a1 3564 (Removed oparg from YIELD_VALUE, changed oparg values of RESUME)
# Python 3.13a1 3565 (Oparg of YIELD_VALUE indicates whether it is in a yield-from)
# Python 3.13a1 3566 (Emit JUMP_NO_INTERRUPT instead of JUMP for non-loop no-lineno cases)

# Python 3.14 will start with 3600

Expand All @@ -478,7 +479,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3565).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3566).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_compiler_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_if_expression(self):
('TO_BOOL', 0, 1),
('POP_JUMP_IF_FALSE', false_lbl := self.Label(), 1),
('LOAD_CONST', 1, 1),
('JUMP', exit_lbl := self.Label()),
('JUMP_NO_INTERRUPT', exit_lbl := self.Label()),
false_lbl,
('LOAD_CONST', 2, 1),
exit_lbl,
Expand Down
56 changes: 28 additions & 28 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,34 +1742,34 @@ def _prepare_test_cases():
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=328, start_offset=328, starts_line=False, line_number=25, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=330, start_offset=330, starts_line=False, line_number=25, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=332, start_offset=332, starts_line=False, line_number=25, label=None, positions=None),
Instruction(opname='JUMP_BACKWARD', opcode=77, arg=27, argval=284, argrepr='to L11', offset=334, start_offset=334, starts_line=False, line_number=25, label=None, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=338, start_offset=338, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=340, start_offset=340, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=342, start_offset=342, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='PUSH_EXC_INFO', opcode=33, arg=None, argval=None, argrepr='', offset=344, start_offset=344, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=4, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=346, start_offset=346, starts_line=True, line_number=22, label=None, positions=None),
Instruction(opname='CHECK_EXC_MATCH', opcode=7, arg=None, argval=None, argrepr='', offset=356, start_offset=356, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=15, argval=392, argrepr='to L13', offset=358, start_offset=358, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=362, start_offset=362, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=3, argval='print', argrepr='print + NULL', offset=364, start_offset=364, starts_line=True, line_number=23, label=None, positions=None),
Instruction(opname='LOAD_CONST', opcode=83, arg=9, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=374, start_offset=374, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=376, start_offset=376, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=384, start_offset=384, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=386, start_offset=386, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='JUMP_BACKWARD', opcode=77, arg=54, argval=284, argrepr='to L11', offset=388, start_offset=388, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=392, start_offset=392, starts_line=True, line_number=22, label=13, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=394, start_offset=394, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=396, start_offset=396, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=398, start_offset=398, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='PUSH_EXC_INFO', opcode=33, arg=None, argval=None, argrepr='', offset=400, start_offset=400, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=3, argval='print', argrepr='print + NULL', offset=402, start_offset=402, starts_line=True, line_number=28, label=None, positions=None),
Instruction(opname='LOAD_CONST', opcode=83, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=412, start_offset=412, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=414, start_offset=414, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=422, start_offset=422, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=424, start_offset=424, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=426, start_offset=426, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=428, start_offset=428, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=430, start_offset=430, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=78, arg=26, argval=284, argrepr='to L11', offset=334, start_offset=334, starts_line=False, line_number=25, label=None, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=336, start_offset=336, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=338, start_offset=338, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=340, start_offset=340, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='PUSH_EXC_INFO', opcode=33, arg=None, argval=None, argrepr='', offset=342, start_offset=342, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=4, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=344, start_offset=344, starts_line=True, line_number=22, label=None, positions=None),
Instruction(opname='CHECK_EXC_MATCH', opcode=7, arg=None, argval=None, argrepr='', offset=354, start_offset=354, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=14, argval=388, argrepr='to L13', offset=356, start_offset=356, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=360, start_offset=360, starts_line=False, line_number=22, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=3, argval='print', argrepr='print + NULL', offset=362, start_offset=362, starts_line=True, line_number=23, label=None, positions=None),
Instruction(opname='LOAD_CONST', opcode=83, arg=9, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=372, start_offset=372, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=374, start_offset=374, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=382, start_offset=382, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=384, start_offset=384, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=78, arg=52, argval=284, argrepr='to L11', offset=386, start_offset=386, starts_line=False, line_number=23, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=388, start_offset=388, starts_line=True, line_number=22, label=13, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=390, start_offset=390, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=392, start_offset=392, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=394, start_offset=394, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='PUSH_EXC_INFO', opcode=33, arg=None, argval=None, argrepr='', offset=396, start_offset=396, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=91, arg=3, argval='print', argrepr='print + NULL', offset=398, start_offset=398, starts_line=True, line_number=28, label=None, positions=None),
Instruction(opname='LOAD_CONST', opcode=83, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=408, start_offset=408, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=410, start_offset=410, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=418, start_offset=418, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=420, start_offset=420, starts_line=False, line_number=28, label=None, positions=None),
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=422, start_offset=422, starts_line=True, line_number=None, label=None, positions=None),
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=424, start_offset=424, starts_line=False, line_number=None, label=None, positions=None),
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=426, start_offset=426, starts_line=False, line_number=None, label=None, positions=None),
]

# One last piece of inspect fodder to check the default line number handling
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compiler changed so that synthetic jumps which are not at loop end no longer check the eval breaker.
40 changes: 20 additions & 20 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@ compiler_jump_if(struct compiler *c, location loc,
compiler_jump_if(c, loc, e->v.IfExp.test, next2, 0));
RETURN_IF_ERROR(
compiler_jump_if(c, loc, e->v.IfExp.body, next, cond));
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, next2);
RETURN_IF_ERROR(
Expand Down Expand Up @@ -2926,12 +2926,12 @@ compiler_jump_if(struct compiler *c, location loc,
ADDOP(c, LOC(e), TO_BOOL);
ADDOP_JUMP(c, LOC(e), cond ? POP_JUMP_IF_TRUE : POP_JUMP_IF_FALSE, next);
NEW_JUMP_TARGET_LABEL(c, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, cleanup);
ADDOP(c, LOC(e), POP_TOP);
if (!cond) {
ADDOP_JUMP(c, NO_LOCATION, JUMP, next);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, next);
}

USE_LABEL(c, end);
Expand Down Expand Up @@ -2963,7 +2963,7 @@ compiler_ifexp(struct compiler *c, expr_ty e)
compiler_jump_if(c, LOC(e), e->v.IfExp.test, next, 0));

VISIT(c, expr, e->v.IfExp.body);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, next);
VISIT(c, expr, e->v.IfExp.orelse);
Expand Down Expand Up @@ -3041,7 +3041,7 @@ compiler_if(struct compiler *c, stmt_ty s)

VISIT_SEQ(c, stmt, s->v.If.body);
if (asdl_seq_LEN(s->v.If.orelse)) {
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, next);
VISIT_SEQ(c, stmt, s->v.If.orelse);
Expand Down Expand Up @@ -3294,7 +3294,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, FINALLY_TRY, body);
VISIT_SEQ(c, stmt, s->v.Try.finalbody);

ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, exit);
/* `finally` block */

USE_LABEL(c, end);
Expand Down Expand Up @@ -3344,7 +3344,7 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, FINALLY_TRY, body);
VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);

ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, exit);

/* `finally` block */
USE_LABEL(c, end);
Expand Down Expand Up @@ -3419,7 +3419,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
if (s->v.Try.orelse && asdl_seq_LEN(s->v.Try.orelse)) {
VISIT_SEQ(c, stmt, s->v.Try.orelse);
}
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);
n = asdl_seq_LEN(s->v.Try.handlers);

USE_LABEL(c, except);
Expand Down Expand Up @@ -3483,7 +3483,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store));
RETURN_IF_ERROR(
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

/* except: */
USE_LABEL(c, cleanup_end);
Expand Down Expand Up @@ -3511,7 +3511,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_EXCEPT);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);
}

USE_LABEL(c, except);
Expand Down Expand Up @@ -3599,7 +3599,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
VISIT_SEQ(c, stmt, s->v.TryStar.body);
compiler_pop_fblock(c, TRY_EXCEPT, body);
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP_JUMP(c, NO_LOCATION, JUMP, orelse);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, orelse);
Py_ssize_t n = asdl_seq_LEN(s->v.TryStar.handlers);

USE_LABEL(c, except);
Expand Down Expand Up @@ -3681,7 +3681,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
RETURN_IF_ERROR(
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));
}
ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, except);

/* except: */
USE_LABEL(c, cleanup_end);
Expand All @@ -3698,11 +3698,11 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
/* add exception raised to the res list */
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc
ADDOP(c, NO_LOCATION, POP_TOP); // lasti
ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, except_with_error);

USE_LABEL(c, except);
ADDOP(c, NO_LOCATION, NOP); // to hold a propagated location info
ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, except_with_error);

USE_LABEL(c, no_match);
ADDOP(c, loc, POP_TOP); // match (None)
Expand All @@ -3712,7 +3712,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
if (i == n - 1) {
/* Add exc to the list (if not None it's the unhandled part of the EG) */
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 1);
ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, reraise_star);
}
}
/* artificial */
Expand All @@ -3728,7 +3728,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
ADDOP(c, NO_LOCATION, POP_TOP);
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_EXCEPT);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, reraise);
ADDOP(c, NO_LOCATION, POP_BLOCK);
Expand Down Expand Up @@ -4626,7 +4626,7 @@ compiler_compare(struct compiler *c, expr_ty e)
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n));
ADDOP_COMPARE(c, loc, asdl_seq_GET(e->v.Compare.ops, n));
NEW_JUMP_TARGET_LABEL(c, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

USE_LABEL(c, cleanup);
ADDOP_I(c, loc, SWAP, 2);
Expand Down Expand Up @@ -5668,7 +5668,7 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
}
if (state.pushed_locals) {
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP_JUMP(c, NO_LOCATION, JUMP, state.end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, state.end);

// cleanup from an exception inside the comprehension
USE_LABEL(c, state.cleanup);
Expand Down Expand Up @@ -5916,7 +5916,7 @@ compiler_with_except_finish(struct compiler *c, jump_target_label cleanup) {
ADDOP(c, NO_LOCATION, POP_TOP);
ADDOP(c, NO_LOCATION, POP_TOP);
NEW_JUMP_TARGET_LABEL(c, exit);
ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, exit);

USE_LABEL(c, cleanup);
POP_EXCEPT_AND_RERAISE(c, NO_LOCATION);
Expand Down Expand Up @@ -7410,7 +7410,7 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
ADDOP(c, LOC(m->pattern), POP_TOP);
}
VISIT_SEQ(c, stmt, m->body);
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);
// If the pattern fails to match, we want the line number of the
// cleanup to be associated with the failed pattern, not the last line
// of the body
Expand Down
1 change: 1 addition & 0 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
}
break;
case JUMP:
case JUMP_NO_INTERRUPT:
switch (target->i_opcode) {
case JUMP:
i -= jump_thread(inst, target, JUMP);
Expand Down