Compile a collection of modules into ModuleIRs. The modules to compile are specified as part of mapper's group_map. Returns the IR of the modules.
(
result: BuildResult, mapper: Mapper, compiler_options: CompilerOptions, errors: Errors
)
| 293 | |
| 294 | |
| 295 | def compile_modules_to_ir( |
| 296 | result: BuildResult, mapper: Mapper, compiler_options: CompilerOptions, errors: Errors |
| 297 | ) -> ModuleIRs: |
| 298 | """Compile a collection of modules into ModuleIRs. |
| 299 | |
| 300 | The modules to compile are specified as part of mapper's group_map. |
| 301 | |
| 302 | Returns the IR of the modules. |
| 303 | """ |
| 304 | deser_ctx = DeserMaps({}, {}) |
| 305 | modules = {} |
| 306 | |
| 307 | # Process the graph by SCC in topological order, like we do in mypy.build |
| 308 | for scc in sorted_components(result.graph): |
| 309 | scc_states = [result.graph[id] for id in sorted(scc.mod_ids)] |
| 310 | trees = [st.tree for st in scc_states if st.id in mapper.group_map and st.tree] |
| 311 | |
| 312 | if not trees: |
| 313 | continue |
| 314 | |
| 315 | fresh = all(id not in result.manager.rechecked_modules for id in scc.mod_ids) |
| 316 | if fresh: |
| 317 | load_scc_from_cache(trees, result, mapper, deser_ctx) |
| 318 | else: |
| 319 | scc_ir = compile_scc_to_ir(trees, result, mapper, compiler_options, errors) |
| 320 | modules.update(scc_ir) |
| 321 | # A later SCC loaded from cache may reference classes/functions |
| 322 | # defined in this freshly-built SCC; populate deser_ctx so the |
| 323 | # cached IR deserializer can resolve those cross-SCC references. |
| 324 | for module_ir in scc_ir.values(): |
| 325 | for cl in module_ir.classes: |
| 326 | deser_ctx.classes.setdefault(cl.fullname, cl) |
| 327 | for fn in module_ir.functions: |
| 328 | deser_ctx.functions.setdefault(fn.decl.id, fn) |
| 329 | |
| 330 | return modules |
| 331 | |
| 332 | |
| 333 | def compile_ir_to_c( |
no test coverage detected
searching dependent graphs…