From 759bd6baf745bd3796e0b2e88caf7d12d402eefc Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 19 May 2022 17:44:39 +0900 Subject: [PATCH 1/4] dis._unpack_opargs should handle EXTENDED_ARG_QUICK --- Lib/dis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/dis.py b/Lib/dis.py index 046013120b000d..5567061774b759 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -592,7 +592,7 @@ def _unpack_opargs(code): caches = _inline_cache_entries[deop] if deop >= HAVE_ARGUMENT: arg = code[i+1] | extended_arg - extended_arg = (arg << 8) if op == EXTENDED_ARG else 0 + extended_arg = (arg << 8) if EXTENDED_ARG in (op, deop) else 0 # The oparg is stored as a signed integer # If the value exceeds its upper limit, it will overflow and wrap # to a negative integer From 705abf8cf78f5797950ec1a248a5be2f64e5215d Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 19 May 2022 17:50:06 +0900 Subject: [PATCH 2/4] Add NEWS.d --- .../next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst b/Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst new file mode 100644 index 00000000000000..cb76ac5cbd60e1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst @@ -0,0 +1,3 @@ +Now :func:`~dis.dis` and :func:`~dis.get_instructions` handle operand values +for instructions prefixed by ``EXTENDED_ARG_QUICK``. +Patch by Sam Gross and Dong-hee Na. From fd13897eefe8d009547c0b0fd0b329b86aaf4ee4 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 20 May 2022 17:27:59 +0900 Subject: [PATCH 3/4] Address code review --- Lib/dis.py | 2 +- Lib/test/test_dis.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Lib/dis.py b/Lib/dis.py index 5567061774b759..5a5ee8d848d3a4 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -592,7 +592,7 @@ def _unpack_opargs(code): caches = _inline_cache_entries[deop] if deop >= HAVE_ARGUMENT: arg = code[i+1] | extended_arg - extended_arg = (arg << 8) if EXTENDED_ARG in (op, deop) else 0 + extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0 # The oparg is stored as a signed integer # If the value exceeds its upper limit, it will overflow and wrap # to a negative integer diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 244a24591b241e..5775a4708901d2 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -620,6 +620,22 @@ def loop_test(): loop_test.__code__.co_firstlineno + 2, loop_test.__code__.co_firstlineno + 1,) +def extend_arg_quick(): + *_, _ = ... + +dis_extended_arg_quick_code = """\ +%3d 0 RESUME 0 + +%3d 2 LOAD_CONST 1 (Ellipsis) + 4 EXTENDED_ARG_QUICK 1 + 6 UNPACK_EX 256 + 8 STORE_FAST 0 (_) + 10 STORE_FAST 0 (_) + 12 LOAD_CONST 0 (None) + 14 RETURN_VALUE +"""% (extend_arg_quick.__code__.co_firstlineno, + extend_arg_quick.__code__.co_firstlineno + 1,) + QUICKENING_WARMUP_DELAY = 8 class DisTestBase(unittest.TestCase): @@ -997,6 +1013,11 @@ def test_loop_quicken(self): got = self.get_disassembly(loop_test, adaptive=True) self.do_disassembly_compare(got, dis_loop_test_quickened_code) + @cpython_only + def test_extenaded_arg_quick(self): + got = self.get_disassembly(extend_arg_quick) + self.do_disassembly_compare(got, dis_extended_arg_quick_code, True) + def get_cached_values(self, quickened, adaptive): def f(): l = [] From e45f3a719b1601499e4a3a5b355fcb3c8d302797 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 3 Jun 2022 10:39:21 +0900 Subject: [PATCH 4/4] Address code review --- Lib/test/test_dis.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 5775a4708901d2..a4f7f84995bf5f 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -620,7 +620,7 @@ def loop_test(): loop_test.__code__.co_firstlineno + 2, loop_test.__code__.co_firstlineno + 1,) -def extend_arg_quick(): +def extended_arg_quick(): *_, _ = ... dis_extended_arg_quick_code = """\ @@ -633,8 +633,8 @@ def extend_arg_quick(): 10 STORE_FAST 0 (_) 12 LOAD_CONST 0 (None) 14 RETURN_VALUE -"""% (extend_arg_quick.__code__.co_firstlineno, - extend_arg_quick.__code__.co_firstlineno + 1,) +"""% (extended_arg_quick.__code__.co_firstlineno, + extended_arg_quick.__code__.co_firstlineno + 1,) QUICKENING_WARMUP_DELAY = 8 @@ -1014,8 +1014,8 @@ def test_loop_quicken(self): self.do_disassembly_compare(got, dis_loop_test_quickened_code) @cpython_only - def test_extenaded_arg_quick(self): - got = self.get_disassembly(extend_arg_quick) + def test_extended_arg_quick(self): + got = self.get_disassembly(extended_arg_quick) self.do_disassembly_compare(got, dis_extended_arg_quick_code, True) def get_cached_values(self, quickened, adaptive):