Thanks to visit codestin.com
Credit goes to github.com

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
initialize frame values to NULL when args are known
  • Loading branch information
Fidget-Spinner committed Jan 1, 2026
commit 844cc42db0bf37df092d7c6a6856e905d8fcccab
22 changes: 22 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2557,8 +2557,30 @@ def testfunc(n):
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_POP_TOP_NOP", uops)
self.assertIn("_PUSH_FRAME", uops)
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)

def test_store_fast_refcount_elimination_when_uninitialized(self):
def foo():
# Since y is known to be
# uninitialized (NULL) here,
# The refcount is eliminated in the STORE_FAST.
y = 2
return y
def testfunc(n):
# The STORE_FAST for the range here needs a POP_TOP
# (for now, until we do loop peeling).
for _ in range(n):
foo()

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_POP_TOP_NOP", uops)
self.assertIn("_PUSH_FRAME", uops)
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)


def test_float_op_refcount_elimination(self):
def testfunc(args):
a, b, n = args
Expand Down
6 changes: 5 additions & 1 deletion Python/optimizer_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,12 @@ _Py_uop_frame_new(
frame->locals[i] = args[i];
}

// If the args are known, then it's safe to just initialize
// every other non-set local to null symbol.
bool default_null = args != NULL;

for (int i = arg_len; i < co->co_nlocalsplus; i++) {
JitOptRef local = _Py_uop_sym_new_unknown(ctx);
JitOptRef local = default_null ? _Py_uop_sym_new_null(ctx) : _Py_uop_sym_new_unknown(ctx);
frame->locals[i] = local;
}

Expand Down