mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-131798: Use sym_new_type
instead of sym_new_not_null
for _BUILD_LIST
, _BUILD_SLICE
, and _BUILD_MAP
(GH-132434)
--------- Signed-off-by: Manjusaka <me@manjusaka.me>
This commit is contained in:
parent
62ff86fa55
commit
b9e88ff4cb
4 changed files with 21 additions and 7 deletions
|
@ -1678,7 +1678,7 @@ class TestUopsOptimization(unittest.TestCase):
|
||||||
x = 0
|
x = 0
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
d = {}
|
d = {}
|
||||||
d["Spam"] = 1 # Guarded...
|
d["Spam"] = 1 # unguarded!
|
||||||
x += d["Spam"] # ...unguarded!
|
x += d["Spam"] # ...unguarded!
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
@ -1686,7 +1686,7 @@ class TestUopsOptimization(unittest.TestCase):
|
||||||
self.assertEqual(res, TIER2_THRESHOLD)
|
self.assertEqual(res, TIER2_THRESHOLD)
|
||||||
self.assertIsNotNone(ex)
|
self.assertIsNotNone(ex)
|
||||||
uops = get_opnames(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("_STORE_SUBSCR_DICT"), 1)
|
||||||
self.assertEqual(uops.count("_BINARY_OP_SUBSCR_DICT"), 1)
|
self.assertEqual(uops.count("_BINARY_OP_SUBSCR_DICT"), 1)
|
||||||
|
|
||||||
|
@ -1695,7 +1695,7 @@ class TestUopsOptimization(unittest.TestCase):
|
||||||
x = 0
|
x = 0
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
l = [0]
|
l = [0]
|
||||||
l[0] = 1 # Guarded...
|
l[0] = 1 # unguarded!
|
||||||
[a] = l # ...unguarded!
|
[a] = l # ...unguarded!
|
||||||
b = l[0] # ...unguarded!
|
b = l[0] # ...unguarded!
|
||||||
if l: # ...unguarded!
|
if l: # ...unguarded!
|
||||||
|
@ -1706,7 +1706,7 @@ class TestUopsOptimization(unittest.TestCase):
|
||||||
self.assertEqual(res, 2 * TIER2_THRESHOLD)
|
self.assertEqual(res, 2 * TIER2_THRESHOLD)
|
||||||
self.assertIsNotNone(ex)
|
self.assertIsNotNone(ex)
|
||||||
uops = get_opnames(ex)
|
uops = get_opnames(ex)
|
||||||
self.assertEqual(uops.count("_GUARD_NOS_LIST"), 1)
|
self.assertEqual(uops.count("_GUARD_NOS_LIST"), 0)
|
||||||
self.assertEqual(uops.count("_STORE_SUBSCR_LIST_INT"), 1)
|
self.assertEqual(uops.count("_STORE_SUBSCR_LIST_INT"), 1)
|
||||||
self.assertEqual(uops.count("_GUARD_TOS_LIST"), 0)
|
self.assertEqual(uops.count("_GUARD_TOS_LIST"), 0)
|
||||||
self.assertEqual(uops.count("_UNPACK_SEQUENCE_LIST"), 1)
|
self.assertEqual(uops.count("_UNPACK_SEQUENCE_LIST"), 1)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Use ``sym_new_type`` instead of ``sym_new_not_null`` for _BUILD_LIST,
|
||||||
|
_BUILD_SET, _BUILD_MAP
|
|
@ -919,6 +919,18 @@ dummy_func(void) {
|
||||||
tup = sym_new_tuple(ctx, oparg, values);
|
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)) {
|
op(_UNPACK_SEQUENCE_TWO_TUPLE, (seq -- val1, val0)) {
|
||||||
val0 = sym_tuple_getitem(ctx, seq, 0);
|
val0 = sym_tuple_getitem(ctx, seq, 0);
|
||||||
val1 = sym_tuple_getitem(ctx, seq, 1);
|
val1 = sym_tuple_getitem(ctx, seq, 1);
|
||||||
|
|
6
Python/optimizer_cases.c.h
generated
6
Python/optimizer_cases.c.h
generated
|
@ -1031,7 +1031,7 @@
|
||||||
|
|
||||||
case _BUILD_LIST: {
|
case _BUILD_LIST: {
|
||||||
JitOptSymbol *list;
|
JitOptSymbol *list;
|
||||||
list = sym_new_not_null(ctx);
|
list = sym_new_type(ctx, &PyList_Type);
|
||||||
stack_pointer[-oparg] = list;
|
stack_pointer[-oparg] = list;
|
||||||
stack_pointer += 1 - oparg;
|
stack_pointer += 1 - oparg;
|
||||||
assert(WITHIN_STACK_BOUNDS());
|
assert(WITHIN_STACK_BOUNDS());
|
||||||
|
@ -1061,7 +1061,7 @@
|
||||||
|
|
||||||
case _BUILD_MAP: {
|
case _BUILD_MAP: {
|
||||||
JitOptSymbol *map;
|
JitOptSymbol *map;
|
||||||
map = sym_new_not_null(ctx);
|
map = sym_new_type(ctx, &PyDict_Type);
|
||||||
stack_pointer[-oparg*2] = map;
|
stack_pointer[-oparg*2] = map;
|
||||||
stack_pointer += 1 - oparg*2;
|
stack_pointer += 1 - oparg*2;
|
||||||
assert(WITHIN_STACK_BOUNDS());
|
assert(WITHIN_STACK_BOUNDS());
|
||||||
|
@ -2092,7 +2092,7 @@
|
||||||
|
|
||||||
case _BUILD_SLICE: {
|
case _BUILD_SLICE: {
|
||||||
JitOptSymbol *slice;
|
JitOptSymbol *slice;
|
||||||
slice = sym_new_not_null(ctx);
|
slice = sym_new_type(ctx, &PySlice_Type);
|
||||||
stack_pointer[-oparg] = slice;
|
stack_pointer[-oparg] = slice;
|
||||||
stack_pointer += 1 - oparg;
|
stack_pointer += 1 - oparg;
|
||||||
assert(WITHIN_STACK_BOUNDS());
|
assert(WITHIN_STACK_BOUNDS());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue