Skip to content

gh-131798: Use sym_new_type instead of sym_new_not_null for _BUILD_LIST, _BUILD_SLICE, and _BUILD_MAP #132434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,15 +1678,15 @@ def f(n):
x = 0
for _ in range(n):
d = {}
d["Spam"] = 1 # Guarded...
d["Spam"] = 1 # unguarded!
x += d["Spam"] # ...unguarded!
return x

res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertEqual(uops.count("_GUARD_NOS_DICT"), 1)
self.assertEqual(uops.count("_GUARD_NOS_DICT"), 0)
self.assertEqual(uops.count("_STORE_SUBSCR_DICT"), 1)
self.assertEqual(uops.count("_BINARY_OP_SUBSCR_DICT"), 1)

Expand All @@ -1695,7 +1695,7 @@ def f(n):
x = 0
for _ in range(n):
l = [0]
l[0] = 1 # Guarded...
l[0] = 1 # unguarded!
[a] = l # ...unguarded!
b = l[0] # ...unguarded!
if l: # ...unguarded!
Expand All @@ -1706,7 +1706,7 @@ def f(n):
self.assertEqual(res, 2 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertEqual(uops.count("_GUARD_NOS_LIST"), 1)
self.assertEqual(uops.count("_GUARD_NOS_LIST"), 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the comment above and change Guarded to Unguarded. The guard has now been removed.

Same for test_remove_guard_for_known_type_dict

self.assertEqual(uops.count("_STORE_SUBSCR_LIST_INT"), 1)
self.assertEqual(uops.count("_GUARD_TOS_LIST"), 0)
self.assertEqual(uops.count("_UNPACK_SEQUENCE_LIST"), 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use ``sym_new_type`` instead of ``sym_new_not_null`` for _BUILD_LIST,
_BUILD_SET, _BUILD_MAP
12 changes: 12 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,18 @@ dummy_func(void) {
tup = sym_new_tuple(ctx, oparg, values);
}

op(_BUILD_LIST, (values[oparg] -- list)) {
list = sym_new_type(ctx, &PyList_Type);
}

op(_BUILD_SLICE, (values[oparg] -- slice)) {
slice = sym_new_type(ctx, &PySlice_Type);
}

op(_BUILD_MAP, (values[oparg*2] -- map)) {
map = sym_new_type(ctx, &PyDict_Type);
}

op(_UNPACK_SEQUENCE_TWO_TUPLE, (seq -- val1, val0)) {
val0 = sym_tuple_getitem(ctx, seq, 0);
val1 = sym_tuple_getitem(ctx, seq, 1);
Expand Down
6 changes: 3 additions & 3 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading