Skip to content

Commit a12565c

Browse files
authored
Do not update states after writing cache (#19936)
This is a little preparation for #933. We need to minimize the number of actions after writing cache, since these are things workers will need to communicate back to coordinator. Previously we updated `State.meta` after writing cache, but this looks not needed anymore, and would complicate parallel checking. Also delete couple unused attributes on `State`.
1 parent e0090d0 commit a12565c

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

mypy/build.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ def write_cache(
15461546
source_hash: str,
15471547
ignore_all: bool,
15481548
manager: BuildManager,
1549-
) -> tuple[str, tuple[dict[str, Any], str, str] | None]:
1549+
) -> tuple[str, tuple[dict[str, Any], str] | None]:
15501550
"""Write cache files for a module.
15511551
15521552
Note that this mypy's behavior is still correct when any given
@@ -1568,7 +1568,7 @@ def write_cache(
15681568
15691569
Returns:
15701570
A tuple containing the interface hash and inner tuple with cache meta JSON
1571-
that should be written and paths to cache files (inner tuple may be None,
1571+
that should be written and path to cache file (inner tuple may be None,
15721572
if the cache data could not be written).
15731573
"""
15741574
metastore = manager.metastore
@@ -1662,12 +1662,10 @@ def write_cache(
16621662
"ignore_all": ignore_all,
16631663
"plugin_data": plugin_data,
16641664
}
1665-
return interface_hash, (meta, meta_json, data_json)
1665+
return interface_hash, (meta, meta_json)
16661666

16671667

1668-
def write_cache_meta(
1669-
meta: dict[str, Any], manager: BuildManager, meta_json: str, data_json: str
1670-
) -> CacheMeta:
1668+
def write_cache_meta(meta: dict[str, Any], manager: BuildManager, meta_json: str) -> None:
16711669
# Write meta cache file
16721670
metastore = manager.metastore
16731671
meta_str = json_dumps(meta, manager.options.debug_cache)
@@ -1677,8 +1675,6 @@ def write_cache_meta(
16771675
# The next run will simply find the cache entry out of date.
16781676
manager.log(f"Error writing meta JSON file {meta_json}")
16791677

1680-
return cache_meta_from_dict(meta, data_json)
1681-
16821678

16831679
"""Dependency manager.
16841680
@@ -1864,9 +1860,6 @@ class State:
18641860
# List of (path, line number) tuples giving context for import
18651861
import_context: list[tuple[str, int]]
18661862

1867-
# The State from which this module was imported, if any
1868-
caller_state: State | None = None
1869-
18701863
# If caller_state is set, the line number in the caller where the import occurred
18711864
caller_line = 0
18721865

@@ -1917,7 +1910,6 @@ def __init__(
19171910
self.manager = manager
19181911
State.order_counter += 1
19191912
self.order = State.order_counter
1920-
self.caller_state = caller_state
19211913
self.caller_line = caller_line
19221914
if caller_state:
19231915
self.import_context = caller_state.import_context.copy()
@@ -2008,11 +2000,6 @@ def __init__(
20082000
self.parse_file(temporary=temporary)
20092001
self.compute_dependencies()
20102002

2011-
@property
2012-
def xmeta(self) -> CacheMeta:
2013-
assert self.meta, "missing meta on allegedly fresh module"
2014-
return self.meta
2015-
20162003
def add_ancestors(self) -> None:
20172004
if self.path is not None:
20182005
_, name = os.path.split(self.path)
@@ -2479,7 +2466,7 @@ def valid_references(self) -> set[str]:
24792466

24802467
return valid_refs
24812468

2482-
def write_cache(self) -> tuple[dict[str, Any], str, str] | None:
2469+
def write_cache(self) -> tuple[dict[str, Any], str] | None:
24832470
assert self.tree is not None, "Internal error: method must be called on parsed file only"
24842471
# We don't support writing cache files in fine-grained incremental mode.
24852472
if (
@@ -3477,14 +3464,13 @@ def process_stale_scc(graph: Graph, scc: list[str], manager: BuildManager) -> No
34773464
for id in stale:
34783465
meta_tuple = meta_tuples[id]
34793466
if meta_tuple is None:
3480-
graph[id].meta = None
34813467
continue
3482-
meta, meta_json, data_json = meta_tuple
3468+
meta, meta_json = meta_tuple
34833469
meta["dep_hashes"] = {
34843470
dep: graph[dep].interface_hash for dep in graph[id].dependencies if dep in graph
34853471
}
34863472
meta["error_lines"] = errors_by_id.get(id, [])
3487-
graph[id].meta = write_cache_meta(meta, manager, meta_json, data_json)
3473+
write_cache_meta(meta, manager, meta_json)
34883474

34893475

34903476
def sorted_components(

0 commit comments

Comments
 (0)