Skip to content

Commit 870e8c9

Browse files
committed
Refactor away only_load_from_cache, never write to cache
1 parent 9dfe8dd commit 870e8c9

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

mypy/build.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ def __init__(self, data_dir: str,
588588
self.data_dir = data_dir
589589
self.errors = errors
590590
self.errors.set_ignore_prefix(ignore_prefix)
591-
self.only_load_from_cache = options.use_fine_grained_cache
592591
self.lib_path = tuple(lib_path)
593592
self.source_set = source_set
594593
self.reports = reports
@@ -1675,10 +1674,10 @@ def __init__(self,
16751674
for id, line in zip(self.meta.dependencies, self.meta.dep_lines)}
16761675
self.child_modules = set(self.meta.child_modules)
16771676
else:
1678-
# In fine-grained cache mode, pretend we only know about modules that
1679-
# have cache information and defer handling new modules until the
1680-
# fine-grained update.
1681-
if manager.only_load_from_cache:
1677+
# When doing a fine-grained cache load, pretend we only
1678+
# know about modules that have cache information and defer
1679+
# handling new modules until the fine-grained update.
1680+
if manager.options.use_fine_grained_cache:
16821681
manager.log("Deferring module to fine-grained update %s (%s)" % (path, id))
16831682
raise ModuleNotFound
16841683

@@ -1799,7 +1798,7 @@ def fix_cross_refs(self) -> None:
17991798
# cache load because we need to gracefully handle missing modules.
18001799
fixup_module_pass_one(self.tree, self.manager.modules,
18011800
self.manager.options.quick_and_dirty or
1802-
self.manager.only_load_from_cache)
1801+
self.manager.options.use_fine_grained_cache)
18031802

18041803
def calculate_mros(self) -> None:
18051804
assert self.tree is not None, "Internal error: method must be called on parsed file only"
@@ -2107,9 +2106,13 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
21072106
# This is a kind of unfortunate hack to work around some of fine-grained's
21082107
# fragility: if we have loaded less than 50% of the specified files from
21092108
# cache in fine-grained cache mode, load the graph again honestly.
2109+
# In this case, we just turn the cache off entirely, so we don't need
2110+
# to worry about some files being loaded and some from cache and so
2111+
# that fine-grained mode never *writes* to the cache.
21102112
if manager.options.use_fine_grained_cache and len(graph) < 0.50 * len(sources):
2111-
manager.log("Redoing load_graph because too much was missing")
2112-
manager.only_load_from_cache = False
2113+
manager.log("Redoing load_graph without cache because too much was missing")
2114+
manager.options.use_fine_grained_cache = False
2115+
manager.options.cache_dir = os.devnull
21132116
graph = load_graph(sources, manager)
21142117

21152118
t1 = time.time()
@@ -2130,8 +2133,8 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
21302133
if manager.options.dump_graph:
21312134
dump_graph(graph)
21322135
return graph
2133-
if manager.only_load_from_cache:
2134-
halfass_process_graph(graph, manager)
2136+
if manager.options.use_fine_grained_cache:
2137+
process_fine_grained_cache_graph(graph, manager)
21352138
else:
21362139
process_graph(graph, manager)
21372140
updated = preserve_cache(graph)
@@ -2453,7 +2456,7 @@ def process_graph(graph: Graph, manager: BuildManager) -> None:
24532456
manager.log("No fresh SCCs left in queue")
24542457

24552458

2456-
def halfass_process_graph(graph: Graph, manager: BuildManager) -> None:
2459+
def process_fine_grained_cache_graph(graph: Graph, manager: BuildManager) -> None:
24572460
"""Finish loading everything for use in the fine-grained incremental cache"""
24582461

24592462
# If we are running in fine-grained incremental mode with caching,

mypy/dmypy_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
280280
result = mypy.build.build(sources=sources,
281281
options=self.options,
282282
alt_lib_path=self.alt_lib_path)
283+
# build will clear use_fine_grained_cache if it needs to give up
284+
# on doing a cache load.
285+
cache_load_succeeded = self.options.use_fine_grained_cache
283286
except mypy.errors.CompileError as e:
284287
output = ''.join(s + '\n' for s in e.messages)
285288
if e.use_stdout:
@@ -297,7 +300,7 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
297300
# If we are using the fine-grained cache, build hasn't actually done
298301
# the typechecking on the updated files yet.
299302
# Run a fine-grained update starting from the cached data
300-
if self.options.use_fine_grained_cache:
303+
if cache_load_succeeded:
301304
# Pull times and hashes out of the saved_cache and stick them into
302305
# the fswatcher, so we pick up the changes.
303306
for state in self.fine_grained_manager.graph.values():

mypy/server/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def __init__(self,
174174
# for the cache. This is kind of a hack and it might be better to have
175175
# this directly reflected in load_graph's interface.
176176
self.options.cache_dir = os.devnull
177+
self.options.use_fine_grained_cache = False
177178
manager.saved_cache = {}
178-
manager.only_load_from_cache = False
179179
# Active triggers during the last update
180180
self.triggered = [] # type: List[str]
181181

0 commit comments

Comments
 (0)