Skip to content

gh-92932: dis._unpack_opargs should handle EXTENDED_ARG_QUICK #92945

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 4 commits into from
Jun 3, 2022
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
2 changes: 1 addition & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,22 @@ def loop_test():
loop_test.__code__.co_firstlineno + 2,
loop_test.__code__.co_firstlineno + 1,)

def extended_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
"""% (extended_arg_quick.__code__.co_firstlineno,
extended_arg_quick.__code__.co_firstlineno + 1,)

QUICKENING_WARMUP_DELAY = 8

class DisTestBase(unittest.TestCase):
Expand Down Expand Up @@ -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_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):
def f():
l = []
Expand Down
Original file line number Diff line number Diff line change
@@ -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.