MCPcopy Index your code
hub / github.com/python/mypy / split_blocks_at_uninits

Function split_blocks_at_uninits

mypyc/transform/uninit.py:39–134  ·  view source on GitHub ↗
(
    blocks: list[BasicBlock], pre_must_defined: AnalysisDict[Value], strict_traceback_checks: bool
)

Source from the content-addressed store, hash-verified

37
38
39def split_blocks_at_uninits(
40 blocks: list[BasicBlock], pre_must_defined: AnalysisDict[Value], strict_traceback_checks: bool
41) -> list[BasicBlock]:
42 new_blocks: list[BasicBlock] = []
43
44 init_registers = []
45 init_registers_set = set()
46 bitmap_registers: list[Register] = [] # Init status bitmaps
47 bitmap_backed: list[Register] = [] # These use bitmaps to track init status
48
49 # First split blocks on ops that may raise.
50 for block in blocks:
51 ops = block.ops
52 block.ops = []
53 cur_block = block
54 new_blocks.append(cur_block)
55
56 for i, op in enumerate(ops):
57 defined = pre_must_defined[block, i]
58 for src in op.unique_sources():
59 # If a register operand is not guaranteed to be
60 # initialized is an operand to something other than a
61 # check that it is defined, insert a check.
62
63 # Note that for register operand in a LoadAddress op,
64 # we should be able to use it without initialization
65 # as we may need to use its address to update itself
66 if (
67 isinstance(src, Register)
68 and src not in defined
69 and not (isinstance(op, Branch) and op.op == Branch.IS_ERROR)
70 and not isinstance(op, LoadAddress)
71 ):
72 if src not in init_registers_set:
73 init_registers.append(src)
74 init_registers_set.add(src)
75
76 # XXX: if src.name is empty, it should be a
77 # temp... and it should be OK??
78 if not src.name:
79 continue
80
81 new_block, error_block = BasicBlock(), BasicBlock()
82 new_block.error_handler = error_block.error_handler = cur_block.error_handler
83 new_blocks += [error_block, new_block]
84
85 if not src.type.error_overlap:
86 cur_block.ops.append(
87 Branch(
88 src,
89 true_label=error_block,
90 false_label=new_block,
91 op=Branch.IS_ERROR,
92 line=op.line,
93 )
94 )
95 else:
96 # We need to use bitmap for this one.

Callers 1

insert_uninit_checksFunction · 0.85

Calls 15

BasicBlockClass · 0.90
BranchClass · 0.90
RaiseStandardErrorClass · 0.90
UnreachableClass · 0.90
LoadErrorValueClass · 0.90
AssignClass · 0.90
IntegerClass · 0.90
setClass · 0.85
enumerateFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…