From 9be0d7ffd1c62e54cf714bcaf986425147cb0700 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 12 Apr 2025 19:39:33 +0800 Subject: [PATCH 1/5] gh-131798: Use `sym_new_type` instead of `sym_new_not_null` for _BUILD_LIST, _BUILD_SET, _BUILD_MAP Signed-off-by: Manjusaka --- .../2025-04-12-19-41-16.gh-issue-131798.JkSocg.rst | 2 ++ Python/optimizer_bytecodes.c | 12 ++++++++++++ Python/optimizer_cases.c.h | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-04-12-19-41-16.gh-issue-131798.JkSocg.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-12-19-41-16.gh-issue-131798.JkSocg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-12-19-41-16.gh-issue-131798.JkSocg.rst new file mode 100644 index 00000000000000..5a9c0cde35fffb --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-12-19-41-16.gh-issue-131798.JkSocg.rst @@ -0,0 +1,2 @@ +Use ``sym_new_type`` instead of ``sym_new_not_null`` for _BUILD_LIST, +_BUILD_SET, _BUILD_MAP diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 8e1eacfec83e95..baf8429c85371a 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -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, &PyMap_Type); + } + op(_UNPACK_SEQUENCE_TWO_TUPLE, (seq -- val1, val0)) { val0 = sym_tuple_getitem(ctx, seq, 0); val1 = sym_tuple_getitem(ctx, seq, 1); diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 6a20cef906242b..fe375e3f4be41e 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -1031,7 +1031,7 @@ case _BUILD_LIST: { JitOptSymbol *list; - list = sym_new_not_null(ctx); + list = sym_new_type(ctx, &PyList_Type); stack_pointer[-oparg] = list; stack_pointer += 1 - oparg; assert(WITHIN_STACK_BOUNDS()); @@ -1061,7 +1061,7 @@ case _BUILD_MAP: { JitOptSymbol *map; - map = sym_new_not_null(ctx); + map = sym_new_type(ctx, &PyMap_Type); stack_pointer[-oparg*2] = map; stack_pointer += 1 - oparg*2; assert(WITHIN_STACK_BOUNDS()); @@ -2092,7 +2092,7 @@ case _BUILD_SLICE: { JitOptSymbol *slice; - slice = sym_new_not_null(ctx); + slice = sym_new_type(ctx, &PySlice_Type); stack_pointer[-oparg] = slice; stack_pointer += 1 - oparg; assert(WITHIN_STACK_BOUNDS()); From c3d7c3325cea8c5066bb4ee55784b42fda98d1fb Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 12 Apr 2025 20:03:36 +0800 Subject: [PATCH 2/5] Fix review idea Signed-off-by: Manjusaka --- Python/optimizer_bytecodes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index baf8429c85371a..43fe2107bf998a 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -928,7 +928,7 @@ dummy_func(void) { } op(_BUILD_MAP, (values[oparg*2] -- map)) { - map = sym_new_type(ctx, &PyMap_Type); + map = sym_new_type(ctx, &PyDict_Type); } op(_UNPACK_SEQUENCE_TWO_TUPLE, (seq -- val1, val0)) { From a724d891f9e898d2ceae0c5aff3a30bbea5ee833 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 12 Apr 2025 20:07:13 +0800 Subject: [PATCH 3/5] Fix review idea Signed-off-by: Manjusaka --- Python/optimizer_cases.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index fe375e3f4be41e..f51b00d25fe506 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -1061,7 +1061,7 @@ case _BUILD_MAP: { JitOptSymbol *map; - map = sym_new_type(ctx, &PyMap_Type); + map = sym_new_type(ctx, &PyDict_Type); stack_pointer[-oparg*2] = map; stack_pointer += 1 - oparg*2; assert(WITHIN_STACK_BOUNDS()); From 0e12c857db6b590b1775913d2610a608c7656ef6 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 12 Apr 2025 23:34:18 +0800 Subject: [PATCH 4/5] Update the test Signed-off-by: Manjusaka --- Lib/test/test_capi/test_opt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index c0e771a0d59c4f..1a1cfa6fab48eb 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1686,7 +1686,7 @@ def f(n): 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) @@ -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) 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) From 839a749daf3700d79ea90ad29b4a2ce34ea72b8e Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Wed, 16 Apr 2025 22:02:27 +0800 Subject: [PATCH 5/5] fix review idea Signed-off-by: Manjusaka --- Lib/test/test_capi/test_opt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 1a1cfa6fab48eb..34b7c5982245c7 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1678,7 +1678,7 @@ def f(n): x = 0 for _ in range(n): d = {} - d["Spam"] = 1 # Guarded... + d["Spam"] = 1 # unguarded! x += d["Spam"] # ...unguarded! return x @@ -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! pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy