8000 gh-90997: bpo-46841: Disassembly of quickened code by penguin-wwy · Pull Request #32099 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90997: bpo-46841: Disassembly of quickened code #32099

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 16 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' of https://github.com/python/cpython into dis_qui…
…ckened_code
  • Loading branch information
penguin-wwy committed Apr 14, 2022
commit ca9a734fa41bc89871a7d2c3ec9c27766c585383
2 changes: 1 addition & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argval = arg*2
argrepr = "to " + repr(argval)
elif deop in hasjrel:
signed_arg = -arg if deop == JUMP_BACKWARD else arg
signed_arg = -arg if _is_backward_jump(deop) else arg
argval = offset + 2 + signed_arg*2
argrepr = "to " + repr(argval)
elif deop in haslocal or deop in hasfree:
Expand Down
78 changes: 38 additions & 40 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,16 @@ def load_test(x, y=0):
return a, b

dis_load_test_quickened_code = """\
%3d 0 RESUME_QUICK 0
%3d 0 RESUME_QUICK 0

%3d 2 LOAD_FAST__LOAD_FAST 0 (x)
4 LOAD_FAST 1 (y)
6 STORE_FAST__STORE_FAST 3 (b)
8 STORE_FAST__LOAD_FAST 2 (a)
%3d 2 LOAD_FAST__LOAD_FAST 0 (x)
4 LOAD_FAST 1 (y)
6 STORE_FAST__STORE_FAST 3 (b)
8 STORE_FAST__LOAD_FAST 2 (a)

%3d 10 LOAD_FAST__LOAD_FAST 2 (a)
12 LOAD_FAST 3 (b)
14 BUILD_TUPLE 2
%3d 10 LOAD_FAST__LOAD_FAST 2 (a)
12 LOAD_FAST 3 (b)
14 BUILD_TUPLE 2
16 RETURN_VALUE
""" % (load_test.__code__.co_firstlineno,
load_test.__code__.co_firstlineno + 1,
Expand All @@ -608,25 +608,25 @@ def loop_test():
load_test(i)

dis_loop_test_quickened_code = """\
%3d 0 RESUME_QUICK 0
%3d 0 RESUME_QUICK 0

%3d 2 BUILD_LIST 0
4 LOAD_CONST 1 ((1, 2, 3))
6 LIST_EXTEND 1
8 LOAD_CONST 2 (3)
10 BINARY_OP_ADAPTIVE 5 (*)
%3d 2 BUILD_LIST 0
4 LOAD_CONST 1 ((1, 2, 3))
6 LIST_EXTEND 1
8 LOAD_CONST 2 (3)
10 BINARY_OP_ADAPTIVE 5 (*)
14 GET_ITER
16 FOR_ITER 17 (to 52)
18 STORE_FAST 0 (i)
16 FOR_ITER 17 (to 52)
18 STORE_FAST 0 (i)

%3d 20 LOAD_GLOBAL_MODULE 1 (NULL + load_test)
32 LOAD_FAST 0 (i)
34 PRECALL_PYFUNC 1
38 CALL_PY_WITH_DEFAULTS 1
%3d 20 LOAD_GLOBAL_MODULE 1 (NULL + load_test)
32 LOAD_FAST 0 (i)
34 PRECALL_PYFUNC 1
38 CALL_PY_WITH_DEFAULTS 1
48 POP_TOP
50 JUMP_BACKWARD_QUICK 18 (to 16)
50 JUMP_BACKWARD_QUICK 18 (to 16)

%3d >> 52 LOAD_CONST 0 (None)
%3d >> 52 LOAD_CONST 0 (None)
54 RETURN_VALUE
""" % (loop_test.__code__.co_firstlineno,
loop_test.__code__.co_firstlineno + 1,
Expand Down Expand Up @@ -735,8 +735,6 @@ def test_boundaries(self):

def test_widths(self):
for opcode, opname in enumerate(dis.opname):
if opname in dis.deoptmap or opname == 'JUMP_BACKWARD_NO_INTERRUPT':
continue
with self.subTest(opname=opname):
width = dis._OPNAME_WIDTH
if opcode < dis.HAVE_ARGUMENT:
Expand Down Expand Up @@ -928,28 +926,28 @@ def test_super_instructions(self):
@cpython_only
def test_binary_specialize(self):
binary_op_quicken = """\
0 RESUME_QUICK 0
0 RESUME_QUICK 0

1 2 LOAD_NAME 0 (a)
4 LOAD_NAME 1 (b)
1 2 LOAD_NAME 0 (a)
4 LOAD_NAME 1 (b)
6 %s
10 RETURN_VALUE
"""
co_int = compile('a + b', "<int>", "eval")
self.code_quicken(lambda: exec(co_int, {}, {'a': 1, 'b': 2}))
got = self.get_disassembly(co_int, adaptive=True)
self.do_disassembly_compare(got, binary_op_quicken % "BINARY_OP_ADD_INT 0 (+)", True)
self.do_disassembly_compare(got, binary_op_quicken % "BINARY_OP_ADD_INT 0 (+)", True)

co_unicode = compile('a + b', "<unicode>", "eval")
self.code_quicken(lambda: exec(co_unicode, {}, {'a': 'a', 'b': 'b'}))
got = self.get_disassembly(co_unicode, adaptive=True)
self.do_disassembly_compare(got, binary_op_quicken % "BINARY_OP_ADD_UNICODE 0 (+)", True)
self.do_disassembly_compare(got, binary_op_quicken % "BINARY_OP_ADD_UNICODE 0 (+)", True)

binary_subsrc_quicken = """\
0 RESUME_QUICK 0
0 RESUME_QUICK 0

1 2 LOAD_NAME 0 (a)
4 LOAD_CONST 0 (0)
1 2 LOAD_NAME 0 (a)
4 LOAD_CONST 0 (0)
6 %s
16 RETURN_VALUE
"""
Expand All @@ -966,10 +964,10 @@ def test_binary_specialize(self):
@cpython_only
def test_load_attr_specialize(self):
load_attr_quicken = """\
0 RESUME_QUICK 0
0 RESUME_QUICK 0

1 2 LOAD_CONST 0 ('a')
4 LOAD_ATTR_SLOT 0 (__class__)
1 2 LOAD_CONST 0 ('a')
4 LOAD_ATTR_SLOT 0 (__class__)
14 RETURN_VALUE
"""
co = compile("'a'.__class__", "", "eval")
Expand All @@ -980,13 +978,13 @@ def test_load_attr_specialize(self):
@cpython_only
def test_call_specialize(self):
call_quicken = """\
0 RESUME_QUICK 0
0 RESUME_QUICK 0

1 2 PUSH_NULL
4 LOAD_NAME 0 (str)
6 LOAD_CONST 0 (1)
8 PRECALL_NO_KW_STR_1 1
12 CALL_ADAPTIVE 1
4 LOAD_NAME 0 (str)
6 LOAD_CONST 0 (1)
8 PRECALL_NO_KW_STR_1 1
12 CALL_ADAPTIVE 1
22 RETURN_VALUE
"""
co = compile("str(1)", "", "eval")
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0