Skip to content

Commit f3f2a69

Browse files
Add more tests
1 parent dc2d922 commit f3f2a69

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Lib/test/test_generated_cases.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,5 +2288,72 @@ def test_pure_uop_body_copied_in(self):
22882288
"""
22892289
self.run_cases_test(input, input2, output)
22902290

2291+
def test_pure_uop_body_copied_in_complex(self):
2292+
input = """
2293+
pure op(OP, (foo -- res)) {
2294+
if (foo) {
2295+
res = body(foo);
2296+
}
2297+
else {
2298+
res = 1;
2299+
}
2300+
}
2301+
"""
2302+
input2 = """
2303+
op(OP, (foo -- res)) {
2304+
res = sym_new_unknown(ctx);
2305+
}
2306+
"""
2307+
output = """
2308+
case OP: {
2309+
JitOptSymbol *res;
2310+
if (
2311+
sym_is_const(ctx, foo)
2312+
) {
2313+
JitOptSymbol *foo_sym = foo;
2314+
_PyStackRef foo = sym_get_const_as_stackref(ctx, foo_sym);
2315+
_PyStackRef res_stackref;
2316+
/* Start of pure uop copied from bytecodes for constant evaluation */
2317+
if (foo) {
2318+
res_stackref = body(foo);
2319+
}
2320+
else {
2321+
res_stackref = 1;
2322+
}
2323+
/* End of pure uop copied from bytecodes for constant evaluation */
2324+
res = sym_new_const_steal(ctx, PyStackRef_AsPyObjectBorrow(res_stackref));
2325+
stack_pointer[-1] = res;
2326+
}
2327+
else {
2328+
res = sym_new_unknown(ctx);
2329+
stack_pointer[-1] = res;
2330+
}
2331+
break;
2332+
}
2333+
"""
2334+
self.run_cases_test(input, input2, output)
2335+
2336+
def test_pure_uop_reject_array_effects(self):
2337+
input = """
2338+
pure op(OP, (foo[2] -- res)) {
2339+
if (foo) {
2340+
res = body(foo);
2341+
}
2342+
else {
2343+
res = 1;
2344+
}
2345+
}
2346+
"""
2347+
input2 = """
2348+
op(OP, (foo[2] -- res)) {
2349+
res = sym_new_unknown(ctx);
2350+
}
2351+
"""
2352+
output = """
2353+
"""
2354+
with self.assertRaisesRegex(AssertionError,
2355+
"Unsafe to convert a symbol to an array-like StackRef."):
2356+
self.run_cases_test(input, input2, output)
2357+
22912358
if __name__ == "__main__":
22922359
unittest.main()

0 commit comments

Comments
 (0)