Skip to content

Commit 3f2f59a

Browse files
authored
gh-133273: Keep instruction definitions in bytecodes.c and optimizer_bytecodes.c in sync (GH-133320)
1 parent 5f3d3f2 commit 3f2f59a

File tree

4 files changed

+373
-135
lines changed

4 files changed

+373
-135
lines changed

Lib/test/test_generated_cases.py

+183
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,189 @@ 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+
2136+
def test_validate_uop_unused_input(self):
2137+
input = """
2138+
op(OP, (unused -- )) {
2139+
}
2140+
"""
2141+
input2 = """
2142+
op(OP, (foo -- )) {
2143+
}
2144+
"""
2145+
output = """
2146+
case OP: {
2147+
stack_pointer += -1;
2148+
assert(WITHIN_STACK_BOUNDS());
2149+
break;
2150+
}
2151+
"""
2152+
self.run_cases_test(input, input2, output)
2153+
2154+
input = """
2155+
op(OP, (foo -- )) {
2156+
}
2157+
"""
2158+
input2 = """
2159+
op(OP, (unused -- )) {
2160+
}
2161+
"""
2162+
output = """
2163+
case OP: {
2164+
stack_pointer += -1;
2165+
assert(WITHIN_STACK_BOUNDS());
2166+
break;
2167+
}
2168+
"""
2169+
self.run_cases_test(input, input2, output)
2170+
2171+
def test_validate_uop_unused_output(self):
2172+
input = """
2173+
op(OP, ( -- unused)) {
2174+
}
2175+
"""
2176+
input2 = """
2177+
op(OP, ( -- foo)) {
2178+
foo = NULL;
2179+
}
2180+
"""
2181+
output = """
2182+
case OP: {
2183+
JitOptSymbol *foo;
2184+
foo = NULL;
2185+
stack_pointer[0] = foo;
2186+
stack_pointer += 1;
2187+
assert(WITHIN_STACK_BOUNDS());
2188+
break;
2189+
}
2190+
"""
2191+
self.run_cases_test(input, input2, output)
2192+
2193+
input = """
2194+
op(OP, ( -- foo)) {
2195+
foo = NULL;
2196+
}
2197+
"""
2198+
input2 = """
2199+
op(OP, ( -- unused)) {
2200+
}
2201+
"""
2202+
output = """
2203+
case OP: {
2204+
stack_pointer += 1;
2205+
assert(WITHIN_STACK_BOUNDS());
2206+
break;
2207+
}
2208+
"""
2209+
self.run_cases_test(input, input2, output)
2210+
2211+
def test_validate_uop_input_size_mismatch(self):
2212+
input = """
2213+
op(OP, (arg1[2] -- )) {
2214+
}
2215+
"""
2216+
input2 = """
2217+
op(OP, (arg1[4] -- )) {
2218+
}
2219+
"""
2220+
output = """
2221+
"""
2222+
with self.assertRaisesRegex(SyntaxError,
2223+
"Inputs must have equal sizes"):
2224+
self.run_cases_test(input, input2, output)
2225+
2226+
def test_validate_uop_output_size_mismatch(self):
2227+
input = """
2228+
op(OP, ( -- out[2])) {
2229+
}
2230+
"""
2231+
input2 = """
2232+
op(OP, ( -- out[4])) {
2233+
}
2234+
"""
2235+
output = """
2236+
"""
2237+
with self.assertRaisesRegex(SyntaxError,
2238+
"Outputs must have equal sizes"):
2239+
self.run_cases_test(input, input2, output)
2240+
2241+
def test_validate_uop_unused_size_mismatch(self):
2242+
input = """
2243+
op(OP, (foo[2] -- )) {
2244+
}
2245+
"""
2246+
input2 = """
2247+
op(OP, (unused[4] -- )) {
2248+
}
2249+
"""
2250+
output = """
2251+
"""
2252+
with self.assertRaisesRegex(SyntaxError,
2253+
"Inputs must have equal sizes"):
2254+
self.run_cases_test(input, input2, output)
20722255

20732256
if __name__ == "__main__":
20742257
unittest.main()

0 commit comments

Comments
 (0)