Skip to content

Commit bbd5627

Browse files
msullivanJukkaL
authored andcommitted
Don't mark a module as stale if its children change (#8134)
This was introduced in #1865 to fix an issue with new children modules being added. I think we have fixed this issue in another way also since then, since the important part of the test passes with the check removed. (I added some more stuff to the test to increase my confidence in this change). I want to remove this check because it causes a *ton* of trouble with our internal bazel integrations, where we try to generate cache artifacts for each bazel target separately. This check means that bazel targets for packages have their caches invalidated all the time, since they were generated without the children.
1 parent a2ab97b commit bbd5627

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

mypy/build.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def normpath(path: str, options: Options) -> str:
280280
('data_mtime', int), # mtime of data_json
281281
('data_json', str), # path of <id>.data.json
282282
('suppressed', List[str]), # dependencies that weren't imported
283-
('child_modules', List[str]), # all submodules of the given module
284283
('options', Optional[Dict[str, object]]), # build options
285284
# dep_prios and dep_lines are in parallel with
286285
# dependencies + suppressed.
@@ -317,7 +316,6 @@ def cache_meta_from_dict(meta: Dict[str, Any], data_json: str) -> CacheMeta:
317316
int(meta['data_mtime']) if 'data_mtime' in meta else sentinel,
318317
data_json,
319318
meta.get('suppressed', []),
320-
meta.get('child_modules', []),
321319
meta.get('options'),
322320
meta.get('dep_prios', []),
323321
meta.get('dep_lines', []),
@@ -1320,7 +1318,6 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
13201318
'data_mtime': meta.data_mtime,
13211319
'dependencies': meta.dependencies,
13221320
'suppressed': meta.suppressed,
1323-
'child_modules': meta.child_modules,
13241321
'options': (manager.options.clone_for_module(id)
13251322
.select_options_affecting_cache()),
13261323
'dep_prios': meta.dep_prios,
@@ -1364,7 +1361,7 @@ def json_dumps(obj: Any, debug_cache: bool) -> str:
13641361

13651362
def write_cache(id: str, path: str, tree: MypyFile,
13661363
dependencies: List[str], suppressed: List[str],
1367-
child_modules: List[str], dep_prios: List[int], dep_lines: List[int],
1364+
dep_prios: List[int], dep_lines: List[int],
13681365
old_interface_hash: str, source_hash: str,
13691366
ignore_all: bool, manager: BuildManager) -> Tuple[str, Optional[CacheMeta]]:
13701367
"""Write cache files for a module.
@@ -1379,7 +1376,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
13791376
tree: the fully checked module data
13801377
dependencies: module IDs on which this module depends
13811378
suppressed: module IDs which were suppressed as dependencies
1382-
child_modules: module IDs which are this package's direct submodules
13831379
dep_prios: priorities (parallel array to dependencies)
13841380
dep_lines: import line locations (parallel array to dependencies)
13851381
old_interface_hash: the hash from the previous version of the data cache file
@@ -1469,7 +1465,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
14691465
'data_mtime': data_mtime,
14701466
'dependencies': dependencies,
14711467
'suppressed': suppressed,
1472-
'child_modules': child_modules,
14731468
'options': options.select_options_affecting_cache(),
14741469
'dep_prios': dep_prios,
14751470
'dep_lines': dep_lines,
@@ -1688,9 +1683,6 @@ class State:
16881683
# Parent package, its parent, etc.
16891684
ancestors = None # type: Optional[List[str]]
16901685

1691-
# A list of all direct submodules of a given module
1692-
child_modules = None # type: Set[str]
1693-
16941686
# List of (path, line number) tuples giving context for import
16951687
import_context = None # type: List[Tuple[str, int]]
16961688

@@ -1797,7 +1789,6 @@ def __init__(self,
17971789
assert len(all_deps) == len(self.meta.dep_lines)
17981790
self.dep_line_map = {id: line
17991791
for id, line in zip(all_deps, self.meta.dep_lines)}
1800-
self.child_modules = set(self.meta.child_modules)
18011792
if temporary:
18021793
self.load_tree(temporary=True)
18031794
if not manager.use_fine_grained_cache():
@@ -1824,7 +1815,6 @@ def __init__(self,
18241815
# Parse the file (and then some) to get the dependencies.
18251816
self.parse_file()
18261817
self.compute_dependencies()
1827-
self.child_modules = set()
18281818

18291819
@property
18301820
def xmeta(self) -> CacheMeta:
@@ -1855,8 +1845,7 @@ def is_fresh(self) -> bool:
18551845
# dependency is added back we find out later in the process.
18561846
return (self.meta is not None
18571847
and self.is_interface_fresh()
1858-
and self.dependencies == self.meta.dependencies
1859-
and self.child_modules == set(self.meta.child_modules))
1848+
and self.dependencies == self.meta.dependencies)
18601849

18611850
def is_interface_fresh(self) -> bool:
18621851
return self.externally_same
@@ -2241,7 +2230,7 @@ def write_cache(self) -> None:
22412230
"Duplicates in dependencies list for {} ({})".format(self.id, self.dependencies))
22422231
new_interface_hash, self.meta = write_cache(
22432232
self.id, self.path, self.tree,
2244-
list(self.dependencies), list(self.suppressed), list(self.child_modules),
2233+
list(self.dependencies), list(self.suppressed),
22452234
dep_prios, dep_lines, self.interface_hash, self.source_hash, self.ignore_all,
22462235
self.manager)
22472236
if new_interface_hash == self.interface_hash:
@@ -2795,8 +2784,6 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
27952784
assert newst.id not in graph, newst.id
27962785
graph[newst.id] = newst
27972786
new.append(newst)
2798-
if dep in st.ancestors and dep in graph:
2799-
graph[dep].child_modules.add(st.id)
28002787
if dep in graph and dep in st.suppressed_set:
28012788
# Previously suppressed file is now visible
28022789
st.add_dependency(dep)

test-data/unit/check-incremental.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,15 @@ from parent import a
947947

948948
[file parent/a.py.2]
949949
from parent import b
950+
reveal_type(b.x)
950951

951952
[file parent/b.py.2]
953+
x = 10
952954

953-
[stale parent.a, parent.b]
954-
[rechecked parent, parent.a, parent.b]
955+
[stale parent.b]
956+
[rechecked parent.a, parent.b]
957+
[out2]
958+
tmp/parent/a.py:2: note: Revealed type is 'builtins.int'
955959

956960
[case testIncrementalReferenceExistingFileWithImportFrom]
957961
from parent import a, b

0 commit comments

Comments
 (0)