Skip to content

Commit 5e37f0c

Browse files
pre-commit-ci[bot]BobTheBuidler
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 67d0b47 commit 5e37f0c

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

mypyc/analysis/dataflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,12 @@ def cleanup_cfg(blocks: list[BasicBlock]) -> None:
152152
cfg = get_cfg(blocks)
153153
orig_blocks = blocks.copy()
154154
blocks.clear()
155-
155+
156156
for i, block in enumerate(orig_blocks):
157157
# Keep the block if it's the entry block or has any predecessors
158158
# OR if it is a branch target (i.e., appears in any terminator.targets())
159159
is_branch_target = any(
160-
block is tgt
161-
for b in orig_blocks
162-
for tgt in b.terminator.targets()
160+
block is tgt for b in orig_blocks for tgt in b.terminator.targets()
163161
)
164162
if i == 0 or cfg.pred[block] or is_branch_target:
165163
blocks.append(block)

mypyc/test-data/irbuild-set.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,3 @@ L4:
791791
r9 = CPy_NoErrOccurred()
792792
L5:
793793
return 1
794-

mypyc/transform/ir_transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,18 @@ def transform_blocks(self, blocks: list[BasicBlock]) -> None:
102102
for block in block_map.values():
103103
for op in block.ops:
104104
if isinstance(op, Branch):
105-
#raise ValueError(op.targets())
105+
# raise ValueError(op.targets())
106106
branch_targets.update(op.targets())
107107

108108
# Remove blocks that became empty (only Unreachable), are not branch targets, and were not empty before
109109
empties = set()
110110
for old_block, new_block in block_map.items():
111-
if is_empty_block(new_block) and old_block not in originally_empty and old_block not in branch_targets and new_block not in branch_targets:
111+
if (
112+
is_empty_block(new_block)
113+
and old_block not in originally_empty
114+
and old_block not in branch_targets
115+
and new_block not in branch_targets
116+
):
112117
empties.add(new_block)
113118
self.builder.blocks = [block for block in self.builder.blocks if block not in empties]
114119

mypyc/transform/redundant_box_elimination.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
from typing import Dict
22

33
from mypyc.ir.func_ir import FuncIR
4-
from mypyc.ir.ops import Assign, AssignMulti, Box, Branch, Call, CallC, ComparisonOp, DecRef, IncRef, KeepAlive, Return, SetMem, Unbox, Value, Op
4+
from mypyc.ir.ops import (
5+
Assign,
6+
AssignMulti,
7+
Box,
8+
Call,
9+
CallC,
10+
ComparisonOp,
11+
DecRef,
12+
IncRef,
13+
KeepAlive,
14+
Op,
15+
Return,
16+
Unbox,
17+
Value,
18+
)
519
from mypyc.irbuild.ll_builder import LowLevelIRBuilder
620
from mypyc.options import CompilerOptions
721
from mypyc.transform.ir_transform import IRTransform
@@ -14,6 +28,7 @@ def do_box_unbox_elimination(fn: FuncIR, options: CompilerOptions) -> None:
1428
transform.transform_blocks(fn.blocks)
1529
fn.blocks = builder.blocks
1630

31+
1732
def build_use_map(fn: FuncIR) -> Dict[Value, list[Op]]:
1833
# Map each Value to a list of ops that use it
1934
use_map: Dict[Value, list[Op]] = {}
@@ -29,6 +44,7 @@ def build_use_map(fn: FuncIR) -> Dict[Value, list[Op]]:
2944

3045
_supported_ops = (Assign, AssignMulti, Call, CallC, ComparisonOp, Return)
3146

47+
3248
class BoxUnboxEliminationTransform(IRTransform):
3349
def __init__(self, builder: LowLevelIRBuilder, use_map: Dict[Value, list[Op]]):
3450
super().__init__(builder)
@@ -39,7 +55,11 @@ def visit_box(self, op: Box) -> Value | None:
3955
if len(users) == 0:
4056
return None
4157
# Check for Unbox->Box
42-
if isinstance(op.src, Unbox) and op.type == op.src.src.type and all(isinstance(user, _supported_ops) for user in users):
58+
if (
59+
isinstance(op.src, Unbox)
60+
and op.type == op.src.src.type
61+
and all(isinstance(user, _supported_ops) for user in users)
62+
):
4363
unbox = op.src
4464
for user in users:
4565
user.set_sources([unbox.src if src is op else src for src in user.sources()])
@@ -51,7 +71,11 @@ def visit_unbox(self, op: Unbox) -> Value | None:
5171
if len(users) == 0:
5272
return None
5373
# Check for Box->Unbox
54-
if isinstance(op.src, Box) and op.type == op.src.src.type and all(isinstance(user, _supported_ops) for user in users):
74+
if (
75+
isinstance(op.src, Box)
76+
and op.type == op.src.src.type
77+
and all(isinstance(user, _supported_ops) for user in users)
78+
):
5579
box = op.src
5680
for user in users:
5781
user.set_sources([box.src if src is op else src for src in user.sources()])

0 commit comments

Comments
 (0)