def compile_modules_to_ir( result: BuildResult, mapper: Mapper, compiler_options: CompilerOptions, errors: Errors, ) -> ModuleIRs: """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. """ deser_ctx = DeserMaps({}, {}) modules = {} # Process the graph by SCC in topological order, like we do in mypy.build for scc in sorted_components(result.graph): scc_states = [result.graph[id] for id in scc] trees = [ st.tree for st in scc_states if st.id in mapper.group_map and st.tree ] if not trees: continue fresh = all(id not in result.manager.rechecked_modules for id in scc) if fresh: load_scc_from_cache(trees, result, mapper, deser_ctx) else: scc_ir = compile_scc_to_ir(trees, result, mapper, compiler_options, errors) modules.update(scc_ir) return modules
def check_serialization_roundtrip(irs: Dict[str, ModuleIR]) -> None: """Check that we can serialize modules out and deserialize them to the same thing.""" serialized = {k: ir.serialize() for k, ir in irs.items()} ctx = DeserMaps({}, {}) irs2 = deserialize_modules(serialized, ctx) assert irs.keys() == irs2.keys() for k in irs: assert_modules_same(irs[k], irs2[k])