Skip to content

Commit 8ce5312

Browse files
committed
Don't modify the on disk cache in fine-grained mode
This is a little subtle, because interface_hash still needs to be computed, as it is a major driver of the coarse-grained build process. Since metas are no longer computed for files that get rechecked during build, to avoid spuriously reprocessing them we need to find initial file state in cache mdoe as well.
1 parent 3e1baae commit 8ce5312

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

mypy/build.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,15 +1247,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
12471247
corresponding to the metadata that was written (the latter may
12481248
be None if the cache could not be written).
12491249
"""
1250-
# Obtain file paths
1251-
path = os.path.abspath(path)
1252-
meta_json, data_json = get_cache_names(id, path, manager)
1253-
manager.log('Writing {} {} {} {}'.format(id, path, meta_json, data_json))
1254-
1255-
# Make sure directory for cache files exists
1256-
parent = os.path.dirname(data_json)
1257-
assert os.path.dirname(meta_json) == parent
1258-
12591250
# Serialize data and analyze interface
12601251
data = {'tree': tree.serialize(),
12611252
'fine_grained_deps': serialized_fine_grained_deps,
@@ -1266,6 +1257,21 @@ def write_cache(id: str, path: str, tree: MypyFile,
12661257
data_str = json.dumps(data, sort_keys=True)
12671258
interface_hash = compute_hash(data_str)
12681259

1260+
# Don't make file system modifications in fine-grained mode
1261+
# We still need to return an interface_hash, because it determines
1262+
# what gets recomputed in the initial build.
1263+
if manager.options.fine_grained_incremental:
1264+
return interface_hash, None
1265+
1266+
# Obtain file paths
1267+
path = os.path.abspath(path)
1268+
meta_json, data_json = get_cache_names(id, path, manager)
1269+
manager.log('Writing {} {} {} {}'.format(id, path, meta_json, data_json))
1270+
1271+
# Make sure directory for cache files exists
1272+
parent = os.path.dirname(data_json)
1273+
assert os.path.dirname(meta_json) == parent
1274+
12691275
# Obtain and set up metadata
12701276
try:
12711277
os.makedirs(parent, exist_ok=True)
@@ -1347,6 +1353,10 @@ def delete_cache(id: str, path: str, manager: BuildManager) -> None:
13471353
This avoids inconsistent states with cache files from different mypy runs,
13481354
see #4043 for an example.
13491355
"""
1356+
# Don't make file system modifications in fine-grained mode
1357+
if manager.options.fine_grained_incremental:
1358+
return
1359+
13501360
path = os.path.abspath(path)
13511361
meta_json, data_json = get_cache_names(id, path, manager)
13521362
manager.log('Deleting {} {} {} {}'.format(id, path, meta_json, data_json))

mypy/dmypy_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,8 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
254254
self.fscache = FileSystemCache(self.options.python_version)
255255
self.fswatcher = FileSystemWatcher(self.fscache)
256256
self.update_sources(sources)
257-
if not self.options.use_fine_grained_cache:
258-
# Stores the initial state of sources as a side effect.
259-
self.fswatcher.find_changed()
257+
# Stores the initial state of sources as a side effect.
258+
self.fswatcher.find_changed()
260259
try:
261260
# TODO: alt_lib_path
262261
result = mypy.build.build(sources=sources,
@@ -274,16 +273,17 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
274273
self.fine_grained_manager = mypy.server.update.FineGrainedBuildManager(manager, graph)
275274
self.fine_grained_initialized = True
276275
self.previous_sources = sources
277-
self.fscache.flush()
278276

279-
# If we are using the fine-grained cache, build hasn't actually done
280-
# the typechecking on the updated files yet.
277+
# If we are using the fine-grained cache, build might not have
278+
# actually done the typechecking on the updated files yet.
281279
# Run a fine-grained update starting from the cached data
282280
if self.options.use_fine_grained_cache:
283281
# Pull times and hashes out of the saved_cache and stick them into
284282
# the fswatcher, so we pick up the changes.
285283
for state in self.fine_grained_manager.graph.values():
286284
meta = state.meta
285+
# If there isn't a meta, that means the current
286+
# version got checked in the initial build.
287287
if meta is None: continue
288288
assert state.path is not None
289289
self.fswatcher.set_file_data(
@@ -294,8 +294,8 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
294294
changed = self.find_changed(sources)
295295
if changed:
296296
messages = self.fine_grained_manager.update(changed)
297-
self.fscache.flush()
298297

298+
self.fscache.flush()
299299
status = 1 if messages else 0
300300
self.previous_messages = messages[:]
301301
return {'out': ''.join(s + '\n' for s in messages), 'err': '', 'status': status}

0 commit comments

Comments
 (0)