mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-107901: synthetic jumps which are not at end of loop no longer check the eval breaker (#113721)
This commit is contained in:
parent
bb4c167060
commit
d36a365118
7 changed files with 108 additions and 53 deletions
|
@ -462,6 +462,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# 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
|
||||
|
||||
|
@ -478,7 +479,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# 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
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class IsolatedCodeGenTests(CodegenTestCase):
|
|||
('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,
|
||||
|
|
|
@ -1742,34 +1742,34 @@ expected_opinfo_jumpy = [
|
|||
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
|
||||
|
|
|
@ -1131,6 +1131,46 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase):
|
|||
]
|
||||
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
|
||||
|
||||
def test_unconditional_jump_threading(self):
|
||||
|
||||
def get_insts(lno1, lno2, op1, op2):
|
||||
return [
|
||||
lbl2 := self.Label(),
|
||||
('LOAD_NAME', 0, 10),
|
||||
(op1, lbl1 := self.Label(), lno1),
|
||||
('LOAD_NAME', 1, 20),
|
||||
lbl1,
|
||||
(op2, lbl2, lno2),
|
||||
]
|
||||
|
||||
|
||||
for op1 in ('JUMP', 'JUMP_NO_INTERRUPT'):
|
||||
for op2 in ('JUMP', 'JUMP_NO_INTERRUPT'):
|
||||
# different lines
|
||||
lno1, lno2 = (4, 5)
|
||||
with self.subTest(lno = (lno1, lno2), ops = (op1, op2)):
|
||||
insts = get_insts(lno1, lno2, op1, op2)
|
||||
expected_insts = [
|
||||
('LOAD_NAME', 0, 10),
|
||||
('NOP', 0, 4),
|
||||
(op2, 0, 5),
|
||||
]
|
||||
self.cfg_optimization_test(insts, expected_insts, consts=list(range(5)))
|
||||
|
||||
# Threading
|
||||
for lno1, lno2 in [(-1, -1), (-1, 5), (6, -1), (7, 7)]:
|
||||
with self.subTest(lno = (lno1, lno2), ops = (op1, op2)):
|
||||
insts = get_insts(lno1, lno2, op1, op2)
|
||||
lno = lno1 if lno1 != -1 else lno2
|
||||
if lno == -1:
|
||||
lno = 10 # Propagated from the line before
|
||||
|
||||
op = 'JUMP' if 'JUMP' in (op1, op2) else 'JUMP_NO_INTERRUPT'
|
||||
expected_insts = [
|
||||
('LOAD_NAME', 0, 10),
|
||||
(op, 0, lno),
|
||||
]
|
||||
self.cfg_optimization_test(insts, expected_insts, consts=list(range(5)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Compiler changed so that synthetic jumps which are not at loop end no longer check the eval breaker.
|
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
|
@ -481,13 +481,16 @@ no_redundant_jumps(cfg_builder *g) {
|
|||
if (IS_UNCONDITIONAL_JUMP_OPCODE(last->i_opcode)) {
|
||||
basicblock *next = next_nonempty_block(b->b_next);
|
||||
basicblock *jump_target = next_nonempty_block(last->i_target);
|
||||
assert(jump_target != next);
|
||||
if (jump_target == next) {
|
||||
assert(next);
|
||||
if (last->i_loc.lineno == next->b_instr[0].i_loc.lineno) {
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1097,6 +1100,7 @@ remove_redundant_jumps(cfg_builder *g) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1135,11 +1139,15 @@ jump_thread(cfg_instr *inst, cfg_instr *target, int opcode)
|
|||
assert(is_jump(target));
|
||||
// bpo-45773: If inst->i_target == target->i_target, then nothing actually
|
||||
// changes (and we fall into an infinite loop):
|
||||
if ((inst->i_loc.lineno == target->i_loc.lineno || target->i_loc.lineno == -1) &&
|
||||
if ((inst->i_loc.lineno == target->i_loc.lineno ||
|
||||
inst->i_loc.lineno == -1 || target->i_loc.lineno == -1) &&
|
||||
inst->i_target != target->i_target)
|
||||
{
|
||||
inst->i_target = target->i_target;
|
||||
inst->i_opcode = opcode;
|
||||
if (inst->i_loc.lineno == -1) {
|
||||
inst->i_loc = target->i_loc;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1602,9 +1610,14 @@ 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);
|
||||
continue;
|
||||
case JUMP_NO_INTERRUPT:
|
||||
i -= jump_thread(inst, target, opcode);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case FOR_ITER:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue