@@ -241,7 +241,7 @@ pub fn generate_asts<'a>(
241241 let mut has_failure = false ;
242242 let mut stderr = "" . to_string ( ) ;
243243
244- modules
244+ let results = modules
245245 . par_iter ( )
246246 . map ( |( module_name, module) | {
247247 debug ! ( "Generating AST for module: {}" , module_name) ;
@@ -265,7 +265,7 @@ pub fn generate_asts<'a>(
265265 ) ) ,
266266 Ok ( None ) ,
267267 module. deps . to_owned ( ) ,
268- false ,
268+ None ,
269269 )
270270 }
271271
@@ -350,19 +350,12 @@ pub fn generate_asts<'a>(
350350 AHashSet :: new ( )
351351 } ;
352352
353- let has_dirty_namespace = match module. package . namespace . to_owned ( ) {
354- Some ( namespace) => deleted_modules. contains ( & namespace) ,
355- None => false ,
356- } ;
357-
358- let has_dirty_deps = !deps. is_disjoint ( deleted_modules) || has_dirty_namespace;
359-
360353 (
361354 module_name. to_owned ( ) ,
362355 ast_path,
363356 asti_path,
364357 deps,
365- has_dirty_deps ,
358+ module . package . namespace . to_owned ( ) ,
366359 )
367360 }
368361 }
@@ -372,10 +365,51 @@ pub fn generate_asts<'a>(
372365 Result < ( String , Option < String > ) , String > ,
373366 Result < Option < ( String , Option < String > ) > , String > ,
374367 AHashSet < String > ,
375- bool ,
376- ) > > ( )
368+ Option < String > ,
369+ ) > > ( ) ;
370+
371+ let mut checked_modules = AHashSet :: new ( ) ;
372+ let mut dirty_modules = deleted_modules. clone ( ) ;
373+ dirty_modules. extend (
374+ modules
375+ . iter ( )
376+ . filter_map ( |( module_name, module) | {
377+ if is_dirty ( & module) {
378+ Some ( module_name. to_string ( ) )
379+ } else {
380+ None
381+ }
382+ } )
383+ . collect :: < AHashSet < String > > ( ) ,
384+ ) ;
385+
386+ loop {
387+ let mut num_checked_modules = 0 ;
388+ for ( module_name, _ast_path, _iast_path, deps, namespace) in results. iter ( ) {
389+ if !checked_modules. contains ( module_name) {
390+ num_checked_modules += 1 ;
391+ if deps. is_subset ( & checked_modules) {
392+ checked_modules. insert ( module_name. to_string ( ) ) ;
393+
394+ let has_dirty_namespace = match namespace {
395+ Some ( namespace) => dirty_modules. contains ( namespace) ,
396+ None => false ,
397+ } ;
398+
399+ if !deps. is_disjoint ( & dirty_modules) || has_dirty_namespace {
400+ dirty_modules. insert ( module_name. to_string ( ) ) ;
401+ }
402+ }
403+ }
404+ }
405+ if num_checked_modules == 0 {
406+ break ;
407+ }
408+ }
409+
410+ results
377411 . into_iter ( )
378- . for_each ( |( module_name, ast_path, iast_path, deps, has_dirty_deps ) | {
412+ . for_each ( |( module_name, ast_path, iast_path, deps, _namespace ) | {
379413 if let Some ( module) = modules. get_mut ( & module_name) {
380414 module. deps = deps;
381415 match ast_path {
@@ -437,13 +471,16 @@ pub fn generate_asts<'a>(
437471 }
438472 } ;
439473
440- if has_dirty_deps {
474+ if dirty_modules . contains ( & module_name ) {
441475 match module. source_type {
442476 SourceType :: SourceFile ( ref mut source_file) => {
443477 source_file. implementation . dirty = true ;
444- source_file. interface . as_mut ( ) . map ( |interface| {
445- interface. dirty = true ;
446- } ) ;
478+ match source_file. interface {
479+ Some ( ref mut interface) => {
480+ interface. dirty = true ;
481+ }
482+ None => ( ) ,
483+ }
447484 }
448485 SourceType :: MlMap ( ref mut mlmap) => {
449486 mlmap. dirty = true ;
@@ -958,8 +995,8 @@ pub fn build(path: &str) -> Result<AHashMap<std::string::String, Module>, ()> {
958995 ) ;
959996 let start_compiling = Instant :: now ( ) ;
960997
961- // let mut compiled_modules = AHashSet::<String>::new();
962- let mut compiled_modules = modules
998+ let mut compiled_modules = AHashSet :: < String > :: new ( ) ;
999+ let clean_modules = modules
9631000 . iter ( )
9641001 . filter_map ( |( module_name, module) | {
9651002 if is_dirty ( module) {
@@ -970,6 +1007,9 @@ pub fn build(path: &str) -> Result<AHashMap<std::string::String, Module>, ()> {
9701007 } )
9711008 . collect :: < AHashSet < String > > ( ) ;
9721009
1010+ // always clean build
1011+ // let clean_modules = AHashSet::<String>::new();
1012+
9731013 let mut loop_count = 0 ;
9741014 let mut files_total_count = compiled_modules. len ( ) ;
9751015 let mut files_current_loop_count;
@@ -994,6 +1034,9 @@ pub fn build(path: &str) -> Result<AHashMap<std::string::String, Module>, ()> {
9941034 if module. deps . is_subset ( & compiled_modules)
9951035 && !compiled_modules. contains ( module_name)
9961036 {
1037+ if clean_modules. contains ( module_name) {
1038+ return Some ( ( module_name. to_owned ( ) , Ok ( None ) , Some ( Ok ( None ) ) ) ) ;
1039+ }
9971040 match module. source_type . to_owned ( ) {
9981041 SourceType :: MlMap ( _) => {
9991042 // the mlmap needs to be compiled before the files are compiled
0 commit comments