Skip to content

Commit 8a9fc9d

Browse files
committed
Enforce matching stackref names between bytecodes and optimizer_bytecodes
1 parent f237953 commit 8a9fc9d

File tree

5 files changed

+243
-142
lines changed

5 files changed

+243
-142
lines changed

Lib/test/test_generated_cases.py

+64
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,70 @@ def test_missing_override_failure(self):
20692069
with self.assertRaisesRegex(AssertionError, "All abstract uops"):
20702070
self.run_cases_test(input, input2, output)
20712071

2072+
def test_validate_uop_input_length_mismatch(self):
2073+
input = """
2074+
op(OP, (arg1 -- out)) {
2075+
SPAM();
2076+
}
2077+
"""
2078+
input2 = """
2079+
op(OP, (arg1, arg2 -- out)) {
2080+
}
2081+
"""
2082+
output = """
2083+
"""
2084+
with self.assertRaisesRegex(SyntaxError,
2085+
"Must have the same number of inputs"):
2086+
self.run_cases_test(input, input2, output)
2087+
2088+
def test_validate_uop_output_length_mismatch(self):
2089+
input = """
2090+
op(OP, (arg1 -- out)) {
2091+
SPAM();
2092+
}
2093+
"""
2094+
input2 = """
2095+
op(OP, (arg1 -- out1, out2)) {
2096+
}
2097+
"""
2098+
output = """
2099+
"""
2100+
with self.assertRaisesRegex(SyntaxError,
2101+
"Must have the same number of outputs"):
2102+
self.run_cases_test(input, input2, output)
2103+
2104+
def test_validate_uop_input_name_mismatch(self):
2105+
input = """
2106+
op(OP, (foo -- out)) {
2107+
SPAM();
2108+
}
2109+
"""
2110+
input2 = """
2111+
op(OP, (bar -- out)) {
2112+
}
2113+
"""
2114+
output = """
2115+
"""
2116+
with self.assertRaisesRegex(SyntaxError,
2117+
"Inputs must have equal names"):
2118+
self.run_cases_test(input, input2, output)
2119+
2120+
def test_validate_uop_output_name_mismatch(self):
2121+
input = """
2122+
op(OP, (arg1 -- foo)) {
2123+
SPAM();
2124+
}
2125+
"""
2126+
input2 = """
2127+
op(OP, (arg1 -- bar)) {
2128+
}
2129+
"""
2130+
output = """
2131+
"""
2132+
with self.assertRaisesRegex(SyntaxError,
2133+
"Outputs must have equal names"):
2134+
self.run_cases_test(input, input2, output)
2135+
20722136

20732137
if __name__ == "__main__":
20742138
unittest.main()

Python/bytecodes.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ dummy_func(
15421542
(void)counter;
15431543
}
15441544

1545-
op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0])) {
1545+
op(_UNPACK_SEQUENCE, (seq -- values[oparg], top[0])) {
15461546
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
15471547
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg, -1, top);
15481548
Py_DECREF(seq_o);
@@ -1600,7 +1600,7 @@ dummy_func(
16001600
DECREF_INPUTS();
16011601
}
16021602

1603-
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8], top[0])) {
1603+
inst(UNPACK_EX, (seq -- values[oparg & 0xFF], unused, unused[oparg >> 8], top[0])) {
16041604
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
16051605
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg & 0xFF, oparg >> 8, top);
16061606
Py_DECREF(seq_o);
@@ -3711,7 +3711,7 @@ dummy_func(
37113711
#endif /* ENABLE_SPECIALIZATION_FT */
37123712
}
37133713

3714-
op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
3714+
op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
37153715
if (PyStackRef_TYPE(callable) == &PyMethod_Type && PyStackRef_IsNull(self_or_null)) {
37163716
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
37173717
PyObject *self = ((PyMethodObject *)callable_o)->im_self;
@@ -4107,7 +4107,7 @@ dummy_func(
41074107
_CALL_TUPLE_1 +
41084108
_CHECK_PERIODIC;
41094109

4110-
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
4110+
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
41114111
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
41124112
DEOPT_IF(!PyStackRef_IsNull(self_or_null));
41134113
DEOPT_IF(!PyType_Check(callable_o));

0 commit comments

Comments
 (0)