Visitar URL original
gh-87092: refactor assemble() to a number of separate functions, which do not need the compiler struct by iritkatriel · Pull Request #102562 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
tidy up the no-arg representation in unit test instruction sequences
  • Loading branch information
iritkatriel committed Mar 10, 2023
commit 0f198b6ee313459ef2ab679be02387c4bf523b73
4 changes: 2 additions & 2 deletions Lib/test/support/bytecode_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def normalize_insts(self, insts):
if isinstance(oparg, self.Label):
arg = oparg.value
else:
arg = oparg if opcode in self.HAS_ARG else 0
arg = oparg if opcode in self.HAS_ARG else None
opcode = dis.opname[opcode]
res.append((opcode, arg, *loc))
return res
Expand All @@ -125,7 +125,7 @@ def complete_insts_info(self, insts):
assert isinstance(item, tuple)
inst = list(reversed(item))
opcode = dis.opmap[inst.pop()]
oparg = inst.pop() if opcode in self.HAS_ARG_OR_TARGET else 0
oparg = inst.pop()
loc = inst + [-1] * (4 - len(inst))
res.append((opcode, oparg, *loc))
return res
Expand Down
12 changes: 5 additions & 7 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,7 @@ def test_conditional_jump_forward_non_const_condition(self):
('POP_JUMP_IF_TRUE', lbl := self.Label(), 12),
('LOAD_CONST', 1, 13),
lbl,
('NOP', 0, 14),
('RETURN_CONST', 2, 0),
('RETURN_CONST', 2, 14),
]
self.cfg_optimization_test(insts,
expected_insts,
Expand All @@ -1023,10 +1022,9 @@ def test_conditional_jump_forward_const_condition(self):
('RETURN_VALUE', 14),
]
expected_insts = [
('NOP', None, 11),
('NOP', None, 12),
('NOP', 0, 14),
('RETURN_CONST', 1, 0),
('NOP', 11),
('NOP', 12),
('RETURN_CONST', 1, 14),
]
self.cfg_optimization_test(insts,
expected_insts,
Expand Down Expand Up @@ -1061,7 +1059,7 @@ def test_conditional_jump_backward_const_condition(self):
]
expected_insts = [
lbl := self.Label(),
('NOP', None, 11),
('NOP', 11),
('JUMP', lbl, 12),
]
self.cfg_optimization_test(insts, expected_insts, consts=list(range(5)))
Expand Down
12 changes: 9 additions & 3 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9844,9 +9844,15 @@ instructions_to_cfg(PyObject *instructions, cfg_builder *g)
if (PyErr_Occurred()) {
goto error;
}
int oparg = PyLong_AsLong(PyTuple_GET_ITEM(item, 1));
if (PyErr_Occurred()) {
goto error;
int oparg;
if (HAS_ARG(opcode)) {
oparg = PyLong_AsLong(PyTuple_GET_ITEM(item, 1));
if (PyErr_Occurred()) {
goto error;
}
}
else {
oparg = 0;
}
location loc;
loc.lineno = PyLong_AsLong(PyTuple_GET_ITEM(item, 2));
Expand Down