@@ -161,6 +161,7 @@ def __init__(self,
161
161
self .previous_modules = get_module_to_path_map (manager )
162
162
self .deps = get_all_dependencies (manager , graph , self .options )
163
163
self .previous_targets_with_errors = manager .errors .targets ()
164
+ self .graph = graph
164
165
# Module, if any, that had blocking errors in the last run as (id, path) tuple.
165
166
# TODO: Handle blocking errors in the initial build
166
167
self .blocking_error = None # type: Optional[Tuple[str, str]]
@@ -170,8 +171,7 @@ def __init__(self,
170
171
# for the cache. This is kind of a hack and it might be better to have
171
172
# this directly reflected in load_graph's interface.
172
173
self .options .cache_dir = os .devnull
173
- mark_all_meta_as_memory_only (graph , manager )
174
- manager .saved_cache = preserve_full_cache (graph , manager )
174
+ manager .saved_cache = {}
175
175
self .type_maps = extract_type_maps (graph )
176
176
# Active triggers during the last update
177
177
self .triggered = [] # type: List[str]
@@ -261,7 +261,7 @@ def update_single(self, module: str, path: str) -> Tuple[List[str],
261
261
old_snapshots [module ] = snapshot
262
262
263
263
manager .errors .reset ()
264
- result = update_single_isolated (module , path , manager , previous_modules )
264
+ result = update_single_isolated (module , path , manager , previous_modules , self . graph )
265
265
if isinstance (result , BlockedUpdate ):
266
266
# Blocking error -- just give up
267
267
module , path , remaining , errors = result
@@ -294,23 +294,13 @@ def update_single(self, module: str, path: str) -> Tuple[List[str],
294
294
if state .tree is None and id in manager .saved_cache :
295
295
meta , tree , type_map = manager .saved_cache [id ]
296
296
state .tree = tree
297
- mark_all_meta_as_memory_only (graph , manager )
298
- manager .saved_cache = preserve_full_cache (graph , manager )
299
297
self .previous_modules = get_module_to_path_map (manager )
300
298
self .type_maps = extract_type_maps (graph )
301
299
302
- return manager . errors . new_messages (), remaining , ( module , path ), False
303
-
300
+ # XXX: I want us to not need this
301
+ self . graph = graph
304
302
305
- def mark_all_meta_as_memory_only (graph : Dict [str , State ],
306
- manager : BuildManager ) -> None :
307
- for id , state in graph .items ():
308
- if id in manager .saved_cache :
309
- # Don't look at disk.
310
- old = manager .saved_cache [id ]
311
- manager .saved_cache [id ] = (old [0 ]._replace (memory_only = True ),
312
- old [1 ],
313
- old [2 ])
303
+ return manager .errors .new_messages (), remaining , (module , path ), False
314
304
315
305
316
306
def get_all_dependencies (manager : BuildManager , graph : Dict [str , State ],
@@ -350,7 +340,8 @@ def get_all_dependencies(manager: BuildManager, graph: Dict[str, State],
350
340
def update_single_isolated (module : str ,
351
341
path : str ,
352
342
manager : BuildManager ,
353
- previous_modules : Dict [str , str ]) -> UpdateResult :
343
+ previous_modules : Dict [str , str ],
344
+ graph : Graph ) -> UpdateResult :
354
345
"""Build a new version of one changed module only.
355
346
356
347
Don't propagate changes to elsewhere in the program. Raise CompleError on
@@ -371,11 +362,11 @@ def update_single_isolated(module: str,
371
362
372
363
old_modules = dict (manager .modules )
373
364
sources = get_sources (previous_modules , [(module , path )])
374
- invalidate_stale_cache_entries (manager .saved_cache , [(module , path )])
365
+ invalidate_stale_cache_entries (manager .saved_cache , graph , [(module , path )])
375
366
376
367
manager .missing_modules .clear ()
377
368
try :
378
- graph = load_graph (sources , manager )
369
+ load_graph (sources , manager , graph )
379
370
except CompileError as err :
380
371
# Parse error somewhere in the program -- a blocker
381
372
assert err .module_with_blocker
@@ -437,6 +428,7 @@ def update_single_isolated(module: str,
437
428
replace_modules_with_new_variants (manager , graph , old_modules , new_modules )
438
429
439
430
# Perform type checking.
431
+ state .type_checker ().reset ()
440
432
state .type_check_first_pass ()
441
433
state .type_check_second_pass ()
442
434
state .compute_fine_grained_deps ()
@@ -488,8 +480,9 @@ def delete_module(module_id: str,
488
480
manager .log_fine_grained ('delete module %r' % module_id )
489
481
# TODO: Deletion of a package
490
482
# TODO: Remove deps for the module (this only affects memory use, not correctness)
491
- assert module_id not in graph
492
483
new_graph = graph .copy ()
484
+ if module_id in new_graph :
485
+ del new_graph [module_id ]
493
486
if module_id in manager .modules :
494
487
del manager .modules [module_id ]
495
488
if module_id in manager .saved_cache :
@@ -529,9 +522,11 @@ def get_sources(modules: Dict[str, str],
529
522
sources = [BuildSource (path , id , None )
530
523
for id , path in items
531
524
if os .path .isfile (path )]
525
+ sources = []
532
526
for id , path in changed_modules :
533
- if os .path .isfile (path ) and id not in modules :
527
+ if os .path .isfile (path ): # and id not in modules:
534
528
sources .append (BuildSource (path , id , None ))
529
+ # print(changed_modules, sources)
535
530
return sources
536
531
537
532
@@ -549,75 +544,14 @@ def get_all_changed_modules(root_module: str,
549
544
return changed_modules
550
545
551
546
552
- def preserve_full_cache (graph : Graph , manager : BuildManager ) -> SavedCache :
553
- """Preserve every module with an AST in the graph, including modules with errors."""
554
- saved_cache = {}
555
- for id , state in graph .items ():
556
- assert state .id == id
557
- if state .tree is not None :
558
- meta = state .meta
559
- if meta is None :
560
- # No metadata, likely because of an error. We still want to retain the AST.
561
- # There is no corresponding JSON so create partial "memory-only" metadata.
562
- assert state .path
563
- dep_prios = state .dependency_priorities ()
564
- dep_lines = state .dependency_lines ()
565
- meta = memory_only_cache_meta (
566
- id ,
567
- state .path ,
568
- state .dependencies ,
569
- state .suppressed ,
570
- list (state .child_modules ),
571
- dep_prios ,
572
- dep_lines ,
573
- state .source_hash ,
574
- state .ignore_all ,
575
- manager )
576
- else :
577
- meta = meta ._replace (memory_only = True )
578
- saved_cache [id ] = (meta , state .tree , state .type_map ())
579
- return saved_cache
580
-
581
-
582
- def memory_only_cache_meta (id : str ,
583
- path : str ,
584
- dependencies : List [str ],
585
- suppressed : List [str ],
586
- child_modules : List [str ],
587
- dep_prios : List [int ],
588
- dep_lines : List [int ],
589
- source_hash : str ,
590
- ignore_all : bool ,
591
- manager : BuildManager ) -> CacheMeta :
592
- """Create cache metadata for module that doesn't have a JSON cache files.
593
-
594
- JSON cache files aren't written for modules with errors, but we want to still
595
- cache them in fine-grained incremental mode.
596
- """
597
- options = manager .options .clone_for_module (id )
598
- # Note that we omit attributes related to the JSON files.
599
- meta = {'id' : id ,
600
- 'path' : path ,
601
- 'memory_only' : True , # Important bit: don't expect JSON files to exist
602
- 'hash' : source_hash ,
603
- 'dependencies' : dependencies ,
604
- 'suppressed' : suppressed ,
605
- 'child_modules' : child_modules ,
606
- 'options' : options .select_options_affecting_cache (),
607
- 'dep_prios' : dep_prios ,
608
- 'dep_lines' : dep_lines ,
609
- 'interface_hash' : '' ,
610
- 'version_id' : manager .version_id ,
611
- 'ignore_all' : ignore_all ,
612
- }
613
- return cache_meta_from_dict (meta , '' )
614
-
615
-
616
547
def invalidate_stale_cache_entries (cache : SavedCache ,
548
+ graph : Graph ,
617
549
changed_modules : List [Tuple [str , str ]]) -> None :
618
550
for name , _ in changed_modules :
619
551
if name in cache :
620
552
del cache [name ]
553
+ if name in graph :
554
+ del graph [name ]
621
555
622
556
623
557
def verify_dependencies (state : State , manager : BuildManager ) -> None :
@@ -809,8 +743,8 @@ def reprocess_nodes(manager: BuildManager,
809
743
810
744
Return fired triggers.
811
745
"""
812
- if module_id not in manager . saved_cache or module_id not in graph :
813
- manager .log_fine_grained ('%s not in saved cache or graph (blocking errors or deleted?)' %
746
+ if module_id not in graph :
747
+ manager .log_fine_grained ('%s not in graph (blocking errors or deleted?)' %
814
748
module_id )
815
749
return set ()
816
750
@@ -863,10 +797,8 @@ def key(node: DeferredNode) -> int:
863
797
merge_asts (file_node , old_symbols [name ], file_node , new_symbols [name ])
864
798
865
799
# Type check.
866
- meta , file_node , type_map = manager .saved_cache [module_id ]
867
- graph [module_id ].tree = file_node
868
- graph [module_id ].type_checker ().type_map = type_map
869
800
checker = graph [module_id ].type_checker ()
801
+ checker .reset ()
870
802
# We seem to need additional passes in fine-grained incremental mode.
871
803
checker .pass_num = 0
872
804
checker .last_pass = 3
0 commit comments