Skip to content

Commit d5b4bda

Browse files
committed
Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
1 parent 4f28f75 commit d5b4bda

File tree

6 files changed

+353
-554
lines changed

6 files changed

+353
-554
lines changed

Lib/test/test_dis.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ def _tryfinallyconst(b):
360360
16 CALL_FUNCTION 0
361361
18 POP_TOP
362362
20 RERAISE
363-
22 LOAD_CONST 0 (None)
364-
24 RETURN_VALUE
365363
""" % (_tryfinally.__code__.co_firstlineno + 1,
366364
_tryfinally.__code__.co_firstlineno + 2,
367365
_tryfinally.__code__.co_firstlineno + 4,
@@ -385,8 +383,6 @@ def _tryfinallyconst(b):
385383
16 CALL_FUNCTION 0
386384
18 POP_TOP
387385
20 RERAISE
388-
22 LOAD_CONST 0 (None)
389-
24 RETURN_VALUE
390386
""" % (_tryfinallyconst.__code__.co_firstlineno + 1,
391387
_tryfinallyconst.__code__.co_firstlineno + 2,
392388
_tryfinallyconst.__code__.co_firstlineno + 4,

Lib/test/test_peepholer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ def f(cond1, cond2):
416416
if cond1: return 4
417417
self.assertNotInBytecode(f, 'JUMP_FORWARD')
418418
# There should be one jump for the while loop.
419-
returns = [instr for instr in dis.get_instructions(f)
420-
if instr.opname == 'JUMP_ABSOLUTE']
421-
self.assertEqual(len(returns), 1)
419+
jumps = [instr for instr in dis.get_instructions(f)
420+
if 'JUMP' in instr.opname]
421+
self.assertEqual(len(jumps), 1)
422422
returns = [instr for instr in dis.get_instructions(f)
423423
if instr.opname == 'RETURN_VALUE']
424424
self.assertLessEqual(len(returns), 2)

Lib/test/test_sys_settrace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def test_jump_in_nested_finally_3(output):
948948
output.append(11)
949949
output.append(12)
950950

951-
@jump_test(5, 11, [2, 4], (ValueError, 'unreachable'))
951+
@jump_test(5, 11, [2, 4], (ValueError, 'after'))
952952
def test_no_jump_over_return_try_finally_in_finally_block(output):
953953
try:
954954
output.append(2)
@@ -1457,7 +1457,7 @@ async def test_jump_between_async_with_blocks(output):
14571457
async with asynctracecontext(output, 4):
14581458
output.append(5)
14591459

1460-
@jump_test(5, 7, [2, 4], (ValueError, "unreachable"))
1460+
@jump_test(5, 7, [2, 4], (ValueError, "after"))
14611461
def test_no_jump_over_return_out_of_finally_block(output):
14621462
try:
14631463
output.append(2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bytecode optimizations are performed directly on the control flow graph.
2+
This will result in slightly more compact code objects in some
3+
circumstances.

0 commit comments

Comments
 (0)