8000 GH-93621: reorder code in with/async-with exception exit path to reduce the size of the exception table by iritkatriel · Pull Request #93622 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

GH-93621: reorder code in with/async-with exception exit path to reduce the size of the exception table #93622

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 6 commits into from
Jun 10, 2022
Merged
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
add direct dis tests for with and async-with
  • Loading branch information
iritkatriel committed Jun 9, 2022
commit dc96fbec8cc6f18f0d0dec720cbbca83afb700f9
135 changes: 133 additions & 2 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,131 @@ def _fstring(a, b, c, d):
RETURN_VALUE
""" % (_fstring.__code__.co_firstlineno, _fstring.__code__.co_firstlineno + 1)

def _with(c):
with c:
x = 1
y = 2

dis_with = """\
%3d RESUME 0

%3d LOAD_FAST 0 (c)
BEFORE_WITH
POP_TOP

%3d LOAD_CONST 1 (1)
STORE_FAST 1 (x)

%3d LOAD_CONST 0 (None)
LOAD_CONST 0 (None)
LOAD_CONST 0 (None)
CALL 2
POP_TOP

%3d LOAD_CONST 2 (2)
STORE_FAST 2 (y)
LOAD_CONST 0 (None)
RETURN_VALUE

%3d >> PUSH_EXC_INFO
WITH_EXCEPT_START
POP_JUMP_FORWARD_IF_TRUE 1 (to 46)
RERAISE 2
>> POP_TOP
POP_EXCEPT
POP_TOP
POP_TOP

%3d LOAD_CONST 2 (2)
STORE_FAST 2 (y)
LOAD_CONST 0 (None)
RETURN_VALUE
>> COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
""" % (_with.__code__.co_firstlineno,
_with.__code__.co_firstlineno + 1,
_with.__code__.co_firstlineno + 2,
_with.__code__.co_firstlineno + 1,
_with.__code__.co_firstlineno + 3,
_with.__code__.co_firstlineno + 1,
_with.__code__.co_firstlineno + 3,
)

async def _asyncwith(c):
async with c:
x = 1
y = 2

dis_asyncwith = """\
%3d RETURN_GENERATOR
POP_TOP
RESUME 0

%3d LOAD_FAST 0 (c)
BEFORE_ASYNC_WITH
GET_AWAITABLE 1
LOAD_CONST 0 (None)
>> SEND 3 (to 22)
YIELD_VALUE 3
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 14)
>> POP_TOP

%3d LOAD_CONST 1 (1)
STORE_FAST 1 (x)

%3d LOAD_CONST 0 (None)
LOAD_CONST 0 (None)
LOAD_CONST 0 (None)
CALL 2
GET_AWAITABLE 2
LOAD_CONST 0 (None)
>> SEND 3 (to 56)
YIELD_VALUE 2
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 48)
>> POP_TOP

%3d LOAD_CONST 2 (2)
STORE_FAST 2 (y)
LOAD_CONST 0 (None)
RETURN_VALUE

%3d >> PUSH_EXC_INFO
WITH_EXCEPT_START
GET_AWAITABLE 2
LOAD_CONST 0 (None)
>> SEND 3 (to 82)
YIELD_VALUE 6
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 74)
>> POP_JUMP_FORWARD_IF_TRUE 1 (to 86)
RERAISE 2
>> POP_TOP
POP_EXCEPT
POP_TOP
POP_TOP

%3d LOAD_CONST 2 (2)
STORE_FAST 2 (y)
LOAD_CONST 0 (None)
RETURN_VALUE
>> COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
""" % (_asyncwith.__code__.co_firstlineno,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 2,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 3,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 3,
)


def _tryfinally(a, b):
try:
return a
Expand Down Expand Up @@ -883,6 +1008,12 @@ def test_disassemble_coroutine(self):
def test_disassemble_fstring(self):
self.do_disassembly_test(_fstring, dis_fstring)

def test_disassemble_with(self):
self.do_disassembly_test(_with, dis_with)

def test_disassemble_asyncwith(self):
self.do_disassembly_test(_asyncwith, dis_asyncwith)

def test_disassemble_try_finally(self):
self.do_disassembly_test(_tryfinally, dis_tryfinally)
self.do_disassembly_test(_tryfinallyconst, dis_tryfinallyconst)
Expand Down Expand Up @@ -1046,8 +1177,8 @@ def test_show_caches(self):
caches = list(self.get_cached_values(quickened, adaptive))
for cache in caches:
self.assertRegex(cache, pattern)
self.assertEqual(caches.count(""), 8)
self.assertEqual(len(caches), 22)
self.assertEqual(caches.count(""), 9)
self.assertEqual(len(caches), 23)


class DisWithFileTests(DisTests):
Expand Down
0