MCPcopy Create free account
hub / github.com/python/mypy / check_func_ir

Function check_func_ir

mypyc/analysis/ircheck.py:98–126  ·  view source on GitHub ↗

Applies validations to a given function ir and returns a list of errors found.

(fn: FuncIR)

Source from the content-addressed store, hash-verified

96
97
98def check_func_ir(fn: FuncIR) -> list[FnError]:
99 """Applies validations to a given function ir and returns a list of errors found."""
100 errors = []
101
102 op_set = set()
103
104 for block in fn.blocks:
105 if not block.terminated:
106 errors.append(
107 FnError(source=block.ops[-1] if block.ops else block, desc="Block not terminated")
108 )
109 for op in block.ops[:-1]:
110 if isinstance(op, ControlOp):
111 errors.append(FnError(source=op, desc="Block has operations after control op"))
112
113 if op in op_set:
114 errors.append(FnError(source=op, desc="Func has a duplicate op"))
115 op_set.add(op)
116
117 errors.extend(check_op_sources_valid(fn))
118 if errors:
119 return errors
120
121 op_checker = OpChecker(fn)
122 for block in fn.blocks:
123 for op in block.ops:
124 op.accept(op_checker)
125
126 return op_checker.errors
127
128
129class IrCheckException(Exception):

Callers 3

assert_has_errorFunction · 0.90
assert_no_errorsFunction · 0.90
assert_func_ir_validFunction · 0.85

Calls 9

setClass · 0.85
FnErrorClass · 0.85
isinstanceFunction · 0.85
check_op_sources_validFunction · 0.85
OpCheckerClass · 0.85
appendMethod · 0.80
extendMethod · 0.80
addMethod · 0.45
acceptMethod · 0.45

Tested by 2

assert_has_errorFunction · 0.72
assert_no_errorsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…