Skip to content

Commit 3baa840

Browse files
committed
Replace kill/pop_dead_inputs with pop_input
1 parent a3f89b7 commit 3baa840

File tree

4 files changed

+22
-68
lines changed

4 files changed

+22
-68
lines changed

Lib/test/test_generated_cases.py

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,35 +1674,10 @@ def test_pystackref_frompyobject_new_next_to_cmacro(self):
16741674
"""
16751675
self.run_cases_test(input, output)
16761676

1677-
def test_pop_dead_inputs_all_live(self):
1677+
def test_pop_input(self):
16781678
input = """
16791679
inst(OP, (a, b --)) {
1680-
POP_DEAD_INPUTS();
1681-
HAM(a, b);
1682-
INPUTS_DEAD();
1683-
}
1684-
"""
1685-
output = """
1686-
TARGET(OP) {
1687-
frame->instr_ptr = next_instr;
1688-
next_instr += 1;
1689-
INSTRUCTION_STATS(OP);
1690-
_PyStackRef a;
1691-
_PyStackRef b;
1692-
b = stack_pointer[-1];
1693-
a = stack_pointer[-2];
1694-
HAM(a, b);
1695-
stack_pointer += -2;
1696-
assert(WITHIN_STACK_BOUNDS());
1697-
DISPATCH();
1698-
}
1699-
"""
1700-
self.run_cases_test(input, output)
1701-
1702-
def test_pop_dead_inputs_some_live(self):
1703-
input = """
1704-
inst(OP, (a, b, c --)) {
1705-
POP_DEAD_INPUTS();
1680+
POP_INPUT();
17061681
HAM(a);
17071682
INPUTS_DEAD();
17081683
}
@@ -1713,8 +1688,8 @@ def test_pop_dead_inputs_some_live(self):
17131688
next_instr += 1;
17141689
INSTRUCTION_STATS(OP);
17151690
_PyStackRef a;
1716-
a = stack_pointer[-3];
1717-
stack_pointer += -2;
1691+
a = stack_pointer[-2];
1692+
stack_pointer += -1;
17181693
assert(WITHIN_STACK_BOUNDS());
17191694
HAM(a);
17201695
stack_pointer += -1;
@@ -1724,29 +1699,14 @@ def test_pop_dead_inputs_some_live(self):
17241699
"""
17251700
self.run_cases_test(input, output)
17261701

1727-
def test_pop_dead_inputs_with_output(self):
1702+
def test_pop_input_with_empty_stack(self):
17281703
input = """
1729-
inst(OP, (a, b -- c)) {
1730-
POP_DEAD_INPUTS();
1731-
c = SPAM();
1732-
}
1733-
"""
1734-
output = """
1735-
TARGET(OP) {
1736-
frame->instr_ptr = next_instr;
1737-
next_instr += 1;
1738-
INSTRUCTION_STATS(OP);
1739-
_PyStackRef c;
1740-
stack_pointer += -2;
1741-
assert(WITHIN_STACK_BOUNDS());
1742-
c = SPAM();
1743-
stack_pointer[0] = c;
1744-
stack_pointer += 1;
1745-
assert(WITHIN_STACK_BOUNDS());
1746-
DISPATCH();
1704+
inst(OP, (--)) {
1705+
POP_INPUT();
17471706
}
17481707
"""
1749-
self.run_cases_test(input, output)
1708+
with self.assertRaises(SyntaxError):
1709+
self.run_cases_test(input, "")
17501710

17511711
def test_no_escaping_calls_in_branching_macros(self):
17521712

Python/bytecodes.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,9 +2221,8 @@ dummy_func(
22212221
assert(index < FT_ATOMIC_LOAD_SSIZE_RELAXED(mod_keys->dk_nentries));
22222222
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(mod_keys) + index;
22232223
PyObject *attr_o = FT_ATOMIC_LOAD_PTR_RELAXED(ep->me_value);
2224-
DEAD(mod_keys);
22252224
// Clear mod_keys from stack in case we need to deopt
2226-
POP_DEAD_INPUTS();
2225+
POP_INPUT();
22272226
DEOPT_IF(attr_o == NULL);
22282227
#ifdef Py_GIL_DISABLED
22292228
int increfed = _Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr);
@@ -2258,36 +2257,31 @@ dummy_func(
22582257
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict: PyDictObject * -- attr, null if (oparg & 1))) {
22592258
PyObject *attr_o;
22602259
if (!LOCK_OBJECT(dict)) {
2261-
DEAD(dict);
2262-
POP_DEAD_INPUTS();
2260+
POP_INPUT();
22632261
DEOPT_IF(true);
22642262
}
22652263

22662264
if (hint >= (size_t)dict->ma_keys->dk_nentries) {
22672265
UNLOCK_OBJECT(dict);
2268-
DEAD(dict);
2269-
POP_DEAD_INPUTS();
2266+
POP_INPUT();
22702267
DEOPT_IF(true);
22712268
}
22722269
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
22732270
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
22742271
UNLOCK_OBJECT(dict);
2275-
DEAD(dict);
2276-
POP_DEAD_INPUTS();
2272+
POP_INPUT();
22772273
DEOPT_IF(true);
22782274
}
22792275
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
22802276
if (ep->me_key != name) {
22812277
UNLOCK_OBJECT(dict);
2282-
DEAD(dict);
2283-
POP_DEAD_INPUTS();
2278+
POP_INPUT();
22842279
DEOPT_IF(true);
22852280
}
22862281
attr_o = ep->me_value;
22872282
if (attr_o == NULL) {
22882283
UNLOCK_OBJECT(dict);
2289-
DEAD(dict);
2290-
POP_DEAD_INPUTS();
2284+
POP_INPUT();
22912285
DEOPT_IF(true);
22922286
}
22932287
STAT_INC(LOAD_ATTR, hit);

Tools/cases_generator/generators_common.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, out: CWriter):
120120
"PyStackRef_AsPyObjectSteal": self.stackref_steal,
121121
"DISPATCH": self.dispatch,
122122
"INSTRUCTION_SIZE": self.instruction_size,
123-
"POP_DEAD_INPUTS": self.pop_dead_inputs,
123+
"POP_INPUT": self.pop_input,
124124
}
125125
self.out = out
126126

@@ -349,7 +349,7 @@ def save_stack(
349349
self.emit_save(storage)
350350
return True
351351

352-
def pop_dead_inputs(
352+
def pop_input(
353353
self,
354354
tkn: Token,
355355
tkn_iter: TokenIterator,
@@ -360,7 +360,11 @@ def pop_dead_inputs(
360360
next(tkn_iter)
361361
next(tkn_iter)
362362
next(tkn_iter)
363-
storage.pop_dead_inputs(self.out)
363+
if not storage.inputs:
364+
raise analysis_error("stack is empty", tkn)
365+
storage.inputs[-1].defined = False
366+
storage.clear_dead_inputs()
367+
storage.flush(self.out)
364368
return True
365369

366370
def emit_reload(self, storage: Storage) -> None:

Tools/cases_generator/stack.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,6 @@ def flush(self, out: CWriter, cast_type: str = "uintptr_t", extract_bits: bool =
512512
self._push_defined_outputs()
513513
self.stack.flush(out, cast_type, extract_bits)
514514

515-
def pop_dead_inputs(self, out: CWriter, cast_type: str = "uintptr_t", extract_bits: bool = True) -> None:
516-
self.clear_dead_inputs()
517-
self.stack.flush(out, cast_type, extract_bits)
518-
519515
def save(self, out: CWriter) -> None:
520516
assert self.spilled >= 0
521517
if self.spilled == 0:

0 commit comments

Comments
 (0)