Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for insert 1
  • Loading branch information
Fidget-Spinner committed Jan 1, 2026
commit c62c308af87f48e67598c14be5ae373b0cff7a4b
52 changes: 52 additions & 0 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,58 @@ def test_replace_opcode_binop_one_output_insert(self):
"""
self.run_cases_test(input, input2, output)

def test_replace_opcode_unaryop_one_output_insert(self):
input = """
pure op(OP, (left -- res, l)) {
res = foo(left);
l = left;
}
"""
input2 = """
op(OP, (left -- res, l)) {
res = sym_new_non_null(ctx, foo);
l = left;
REPLACE_OPCODE_IF_EVALUATES_PURE(left, res);
}
"""
output = """
case OP: {
JitOptRef left;
JitOptRef res;
JitOptRef l;
left = stack_pointer[-1];
res = sym_new_non_null(ctx, foo);
l = left;
if (
sym_is_safe_const(ctx, left)
) {
JitOptRef left_sym = left;
_PyStackRef left = sym_get_const_as_stackref(ctx, left_sym);
_PyStackRef res_stackref;
_PyStackRef l_stackref;
/* Start of uop copied from bytecodes for constant evaluation */
res_stackref = foo(left);
l_stackref = left;
/* End of uop copied from bytecodes for constant evaluation */
(void)l_stackref;
res = sym_new_const_steal(ctx, PyStackRef_AsPyObjectSteal(res_stackref));
CHECK_STACK_BOUNDS(1);
stack_pointer[-1] = res;
stack_pointer[0] = l;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
CHECK_STACK_BOUNDS(1);
stack_pointer[-1] = res;
stack_pointer[0] = l;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
"""
self.run_cases_test(input, input2, output)

def test_replace_opocode_uop_reject_array_effects(self):
input = """
pure op(OP, (foo[2] -- res)) {
Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/optimizer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def replace_opcode_if_evaluates_pure(
0: "_POP_TOP_LOAD_CONST_INLINE_BORROW",
# (left -- res, left)
# usually for unary ops with passthrough references
2: "_POP_TWO_LOAD_CONST_INLINE_BORROW",
2: "_INSERT_1_LOAD_CONST_INLINE_BORROW",
},
2: {
# (a. b -- res), usually for binary ops
Expand Down
Loading