145145
146146from mypy import errorcodes as codes
147147from mypy .config_parser import get_config_module_names , parse_mypy_comments
148- from mypy .fixup import fixup_module
148+ from mypy .fixer_state import fixer_state
149+ from mypy .fixup import NodeFixer
149150from mypy .freetree import free_tree
150151from mypy .fscache import FileSystemCache
151152from mypy .known_modules import get_known_modules , reset_known_modules_cache
@@ -814,6 +815,10 @@ def __init__(
814815 self .options = options
815816 self .version_id = version_id
816817 self .modules : dict [str , MypyFile ] = {}
818+ # Share same modules dictionary with the global fixer state.
819+ # We need to set allow_missing when doing a fine-grained cache
820+ # load because we need to gracefully handle missing modules.
821+ fixer_state .node_fixer = NodeFixer (self .modules , self .options .use_fine_grained_cache )
817822 self .import_map : dict [str , set [str ]] = {}
818823 self .missing_modules : dict [str , int ] = {}
819824 self .fg_deps_meta : dict [str , FgDepMeta ] = {}
@@ -879,7 +884,7 @@ def __init__(
879884 ]
880885 )
881886
882- self .metastore = create_metastore (options , parallel_worker )
887+ self .metastore = create_metastore (options )
883888
884889 # a mapping from source files to their corresponding shadow files
885890 # for efficient lookup
@@ -1217,7 +1222,9 @@ def wait_for_done_workers(
12171222 done_sccs = []
12181223 results = {}
12191224 for idx in ready_to_read ([w .conn for w in self .workers ], WORKER_DONE_TIMEOUT ):
1220- data = SccResponseMessage .read (receive (self .workers [idx ].conn ))
1225+ buf = receive (self .workers [idx ].conn )
1226+ assert read_tag (buf ) == SCC_RESPONSE_MESSAGE
1227+ data = SccResponseMessage .read (buf )
12211228 if not data .is_interface :
12221229 # Mark worker as free after it finished checking implementation.
12231230 self .free_workers .add (idx )
@@ -1622,13 +1629,10 @@ def exclude_from_backups(target_dir: str) -> None:
16221629 pass
16231630
16241631
1625- def create_metastore (options : Options , parallel_worker : bool = False ) -> MetadataStore :
1632+ def create_metastore (options : Options ) -> MetadataStore :
16261633 """Create the appropriate metadata store."""
16271634 if options .sqlite_cache :
1628- # We use this flag in both coordinator and workers to speed up commits,
1629- # see mypy.metastore.connect_db() for details.
1630- sync_off = options .num_workers > 0 or parallel_worker
1631- mds : MetadataStore = SqliteMetadataStore (_cache_dir_prefix (options ), sync_off = sync_off )
1635+ mds : MetadataStore = SqliteMetadataStore (_cache_dir_prefix (options ))
16321636 else :
16331637 mds = FilesystemMetadataStore (_cache_dir_prefix (options ))
16341638 return mds
@@ -2836,9 +2840,21 @@ def load_tree(self, temporary: bool = False) -> None:
28362840
28372841 def fix_cross_refs (self ) -> None :
28382842 assert self .tree is not None , "Internal error: method must be called on parsed file only"
2839- # We need to set allow_missing when doing a fine-grained cache
2840- # load because we need to gracefully handle missing modules.
2841- fixup_module (self .tree , self .manager .modules , self .options .use_fine_grained_cache )
2843+ # Do initial lightweight pass fixing TypeInfos and module cross-references.
2844+ assert fixer_state .node_fixer is not None
2845+ fixer_state .node_fixer .visit_symbol_table (self .tree .names )
2846+ type_fixer = fixer_state .node_fixer .type_fixer
2847+ # Eagerly fix shared instances, before they are used by named_type() calls.
2848+ if instance_cache .str_type is not None :
2849+ instance_cache .str_type .accept (type_fixer )
2850+ if instance_cache .function_type is not None :
2851+ instance_cache .function_type .accept (type_fixer )
2852+ if instance_cache .int_type is not None :
2853+ instance_cache .int_type .accept (type_fixer )
2854+ if instance_cache .bool_type is not None :
2855+ instance_cache .bool_type .accept (type_fixer )
2856+ if instance_cache .object_type is not None :
2857+ instance_cache .object_type .accept (type_fixer )
28422858
28432859 # Methods for processing modules from source code.
28442860
@@ -4183,7 +4199,8 @@ def process_graph(graph: Graph, manager: BuildManager) -> None:
41834199 graph_message .write (buf )
41844200 graph_data = buf .getvalue ()
41854201 for worker in manager .workers :
4186- AckMessage .read (receive (worker .conn ))
4202+ buf = receive (worker .conn )
4203+ assert read_tag (buf ) == ACK_MESSAGE
41874204 worker .conn .write_bytes (graph_data )
41884205
41894206 sccs = sorted_components (graph )
@@ -4203,10 +4220,12 @@ def process_graph(graph: Graph, manager: BuildManager) -> None:
42034220 sccs_message .write (buf )
42044221 sccs_data = buf .getvalue ()
42054222 for worker in manager .workers :
4206- AckMessage .read (receive (worker .conn ))
4223+ buf = receive (worker .conn )
4224+ assert read_tag (buf ) == ACK_MESSAGE
42074225 worker .conn .write_bytes (sccs_data )
42084226 for worker in manager .workers :
4209- AckMessage .read (receive (worker .conn ))
4227+ buf = receive (worker .conn )
4228+ assert read_tag (buf ) == ACK_MESSAGE
42104229
42114230 manager .free_workers = set (range (manager .options .num_workers ))
42124231
@@ -4785,7 +4804,6 @@ class AckMessage(IPCMessage):
47854804
47864805 @classmethod
47874806 def read (cls , buf : ReadBuffer ) -> AckMessage :
4788- assert read_tag (buf ) == ACK_MESSAGE
47894807 return AckMessage ()
47904808
47914809 def write (self , buf : WriteBuffer ) -> None :
@@ -4812,7 +4830,6 @@ def __init__(
48124830
48134831 @classmethod
48144832 def read (cls , buf : ReadBuffer ) -> SccRequestMessage :
4815- assert read_tag (buf ) == SCC_REQUEST_MESSAGE
48164833 return SccRequestMessage (
48174834 scc_id = read_int_opt (buf ),
48184835 import_errors = {
@@ -4897,7 +4914,6 @@ def __init__(
48974914
48984915 @classmethod
48994916 def read (cls , buf : ReadBuffer ) -> SccResponseMessage :
4900- assert read_tag (buf ) == SCC_RESPONSE_MESSAGE
49014917 scc_id = read_int (buf )
49024918 is_interface = read_bool (buf )
49034919 tag = read_tag (buf )
@@ -4943,7 +4959,6 @@ def __init__(self, *, sources: list[BuildSource]) -> None:
49434959
49444960 @classmethod
49454961 def read (cls , buf : ReadBuffer ) -> SourcesDataMessage :
4946- assert read_tag (buf ) == SOURCES_DATA_MESSAGE
49474962 sources = [
49484963 BuildSource (
49494964 read_str_opt (buf ),
@@ -4975,7 +4990,6 @@ def __init__(self, *, sccs: list[SCC]) -> None:
49754990
49764991 @classmethod
49774992 def read (cls , buf : ReadBuffer ) -> SccsDataMessage :
4978- assert read_tag (buf ) == SCCS_DATA_MESSAGE
49794993 sccs = [
49804994 SCC (set (read_str_list (buf )), read_int (buf ), read_int_list (buf ))
49814995 for _ in range (read_int_bare (buf ))
@@ -5003,7 +5017,6 @@ def __init__(self, *, graph: Graph, missing_modules: dict[str, int]) -> None:
50035017 @classmethod
50045018 def read (cls , buf : ReadBuffer , manager : BuildManager | None = None ) -> GraphMessage :
50055019 assert manager is not None
5006- assert read_tag (buf ) == GRAPH_MESSAGE
50075020 graph = {read_str_bare (buf ): State .read (buf , manager ) for _ in range (read_int_bare (buf ))}
50085021 missing_modules = {read_str_bare (buf ): read_int (buf ) for _ in range (read_int_bare (buf ))}
50095022 message = GraphMessage (graph = graph , missing_modules = missing_modules )
0 commit comments