Skip to content

Commit 7ab3ec6

Browse files
committed
Make POP_INPUT take the name of the TOS
1 parent 10d693d commit 7ab3ec6

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Lib/test/test_generated_cases.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ def test_pystackref_frompyobject_new_next_to_cmacro(self):
16771677
def test_pop_input(self):
16781678
input = """
16791679
inst(OP, (a, b --)) {
1680-
POP_INPUT();
1680+
POP_INPUT(b);
16811681
HAM(a);
16821682
INPUTS_DEAD();
16831683
}
@@ -1688,6 +1688,8 @@ def test_pop_input(self):
16881688
next_instr += 1;
16891689
INSTRUCTION_STATS(OP);
16901690
_PyStackRef a;
1691+
_PyStackRef b;
1692+
b = stack_pointer[-1];
16911693
a = stack_pointer[-2];
16921694
stack_pointer += -1;
16931695
assert(WITHIN_STACK_BOUNDS());
@@ -1702,7 +1704,16 @@ def test_pop_input(self):
17021704
def test_pop_input_with_empty_stack(self):
17031705
input = """
17041706
inst(OP, (--)) {
1705-
POP_INPUT();
1707+
POP_INPUT(foo);
1708+
}
1709+
"""
1710+
with self.assertRaises(SyntaxError):
1711+
self.run_cases_test(input, "")
1712+
1713+
def test_pop_input_with_non_tos(self):
1714+
input = """
1715+
inst(OP, (a, b --)) {
1716+
POP_INPUT(a);
17061717
}
17071718
"""
17081719
with self.assertRaises(SyntaxError):

Python/bytecodes.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ dummy_func(
22222222
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(mod_keys) + index;
22232223
PyObject *attr_o = FT_ATOMIC_LOAD_PTR_RELAXED(ep->me_value);
22242224
// Clear mod_keys from stack in case we need to deopt
2225-
POP_INPUT();
2225+
POP_INPUT(mod_keys);
22262226
DEOPT_IF(attr_o == NULL);
22272227
#ifdef Py_GIL_DISABLED
22282228
int increfed = _Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr);
@@ -2257,31 +2257,31 @@ dummy_func(
22572257
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict: PyDictObject * -- attr, null if (oparg & 1))) {
22582258
PyObject *attr_o;
22592259
if (!LOCK_OBJECT(dict)) {
2260-
POP_INPUT();
2260+
POP_INPUT(dict);
22612261
DEOPT_IF(true);
22622262
}
22632263

22642264
if (hint >= (size_t)dict->ma_keys->dk_nentries) {
22652265
UNLOCK_OBJECT(dict);
2266-
POP_INPUT();
2266+
POP_INPUT(dict);
22672267
DEOPT_IF(true);
22682268
}
22692269
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
22702270
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
22712271
UNLOCK_OBJECT(dict);
2272-
POP_INPUT();
2272+
POP_INPUT(dict);
22732273
DEOPT_IF(true);
22742274
}
22752275
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
22762276
if (ep->me_key != name) {
22772277
UNLOCK_OBJECT(dict);
2278-
POP_INPUT();
2278+
POP_INPUT(dict);
22792279
DEOPT_IF(true);
22802280
}
22812281
attr_o = ep->me_value;
22822282
if (attr_o == NULL) {
22832283
UNLOCK_OBJECT(dict);
2284-
POP_INPUT();
2284+
POP_INPUT(dict);
22852285
DEOPT_IF(true);
22862286
}
22872287
STAT_INC(LOAD_ATTR, hit);

Tools/cases_generator/generators_common.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,16 @@ def pop_input(
358358
inst: Instruction | None,
359359
) -> bool:
360360
next(tkn_iter)
361+
name_tkn = next(tkn_iter)
362+
name = name_tkn.text
361363
next(tkn_iter)
362364
next(tkn_iter)
363365
if not storage.inputs:
364366
raise analysis_error("stack is empty", tkn)
365-
storage.inputs[-1].defined = False
367+
tos = storage.inputs[-1]
368+
if tos.name != name:
369+
raise analysis_error(f"'{name} is not top of stack", name_tkn)
370+
tos.defined = False
366371
storage.clear_dead_inputs()
367372
storage.flush(self.out)
368373
return True

0 commit comments

Comments
 (0)