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

Function build_ir

mypyc/irbuild/main.py:58–133  ·  view source on GitHub ↗

Build basic IR for a set of modules that have been type-checked by mypy. The returned IR is not complete and requires additional transformations, such as the insertion of refcount handling.

(
    modules: list[MypyFile],
    graph: Graph,
    types: dict[Expression, Type],
    mapper: Mapper,
    options: CompilerOptions,
    errors: Errors,
)

Source from the content-addressed store, hash-verified

56
57@strict_optional_dec # Turn on strict optional for any type manipulations we do
58def build_ir(
59 modules: list[MypyFile],
60 graph: Graph,
61 types: dict[Expression, Type],
62 mapper: Mapper,
63 options: CompilerOptions,
64 errors: Errors,
65) -> ModuleIRs:
66 """Build basic IR for a set of modules that have been type-checked by mypy.
67
68 The returned IR is not complete and requires additional
69 transformations, such as the insertion of refcount handling.
70 """
71
72 build_type_map(mapper, modules, graph, types, options, errors)
73 adjust_generator_classes_of_methods(mapper)
74 singledispatch_info = find_singledispatch_register_impls(modules, errors)
75
76 result: ModuleIRs = {}
77 if errors.num_errors > 0:
78 return result
79
80 # Generate IR for all modules.
81 class_irs = []
82
83 for module in modules:
84 # First pass to determine free symbols.
85 pbv = PreBuildVisitor(errors, module, singledispatch_info.decorators_to_remove, types)
86 module.accept(pbv)
87
88 # Declare generator classes for nested async functions and generators.
89 for fdef in pbv.nested_funcs:
90 if isinstance(fdef, FuncDef):
91 # Make generator class name sufficiently unique.
92 suffix = f"___{fdef.line}"
93 if fdef.is_coroutine or fdef.is_generator:
94 create_generator_class_for_func(
95 module.fullname, None, fdef, mapper, name_suffix=suffix
96 )
97
98 # Construct and configure builder objects (cyclic runtime dependency).
99 visitor = IRBuilderVisitor()
100 builder = IRBuilder(
101 module.fullname,
102 types,
103 graph,
104 errors,
105 mapper,
106 pbv,
107 visitor,
108 options,
109 singledispatch_info.singledispatch_impls,
110 )
111 visitor.builder = builder
112
113 # Second pass does the bulk of the work.
114 transform_mypy_file(builder, module)
115 module_ir = ModuleIR(

Callers 2

compile_scc_to_irFunction · 0.90

Calls 15

build_type_mapFunction · 0.90
PreBuildVisitorClass · 0.90
IRBuilderVisitorClass · 0.90
IRBuilderClass · 0.90
ModuleIRClass · 0.90
compute_vtableFunction · 0.90
isinstanceFunction · 0.85
transform_mypy_fileFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…