1
1
use crate :: analyse:: { ModuleAnalyzerConstructor , TargetSupport } ;
2
2
use crate :: line_numbers:: { self , LineNumbers } ;
3
+ use crate :: package_interface:: { self , ModuleInterface } ;
3
4
use crate :: type_:: PRELUDE_MODULE_NAME ;
4
5
use crate :: {
5
6
ast:: { SrcSpan , TypedModule , UntypedModule } ,
@@ -22,6 +23,7 @@ use crate::{
22
23
} ;
23
24
use askama:: Template ;
24
25
use ecow:: EcoString ;
26
+ use std:: borrow:: BorrowMut ;
25
27
use std:: collections:: HashSet ;
26
28
use std:: { collections:: HashMap , fmt:: write, time:: SystemTime } ;
27
29
use vec1:: Vec1 ;
@@ -104,7 +106,7 @@ where
104
106
stale_modules : & mut StaleTracker ,
105
107
incomplete_modules : & mut HashSet < EcoString > ,
106
108
telemetry : & dyn Telemetry ,
107
- ) -> Outcome < Vec < Module > , Error > {
109
+ ) -> Outcome < ( Vec < Module > , Vec < CacheMetadata > ) , Error > {
108
110
let span = tracing:: info_span!( "compile" , package = %self . config. name. as_str( ) ) ;
109
111
let _enter = span. enter ( ) ;
110
112
@@ -168,6 +170,8 @@ where
168
170
}
169
171
}
170
172
173
+ println ! ( "{:?}" , loaded. cached_metadata) ;
174
+
171
175
// Type check the modules that are new or have changed
172
176
tracing:: info!( count=%loaded. to_compile. len( ) , "analysing_modules" ) ;
173
177
let outcome = analyse (
@@ -182,9 +186,12 @@ where
182
186
incomplete_modules,
183
187
) ;
184
188
185
- let modules = match outcome {
189
+ let mut modules = match outcome {
186
190
Outcome :: Ok ( modules) => modules,
187
- Outcome :: PartialFailure ( _, _) | Outcome :: TotalFailure ( _) => return outcome,
191
+ Outcome :: PartialFailure ( modules, err) => {
192
+ return Outcome :: PartialFailure ( ( modules, loaded. cached_metadata ) , err)
193
+ }
194
+ Outcome :: TotalFailure ( err) => return Outcome :: TotalFailure ( err) ,
188
195
} ;
189
196
190
197
tracing:: debug!( "performing_code_generation" ) ;
@@ -197,7 +204,7 @@ where
197
204
return error. into ( ) ;
198
205
}
199
206
200
- Outcome :: Ok ( modules)
207
+ Outcome :: Ok ( ( modules, loaded . cached_metadata ) )
201
208
}
202
209
203
210
fn compile_erlang_to_beam ( & mut self , modules : & HashSet < Utf8PathBuf > ) -> Result < ( ) , Error > {
@@ -304,11 +311,13 @@ where
304
311
let name = format ! ( "{}.cache_meta" , & module_name) ;
305
312
let path = artefact_dir. join ( name) ;
306
313
let info = CacheMetadata {
314
+ name : module. name . clone ( ) ,
307
315
mtime : module. mtime ,
308
316
codegen_performed : self . perform_codegen ,
309
317
dependencies : module. dependencies . clone ( ) ,
310
318
fingerprint : SourceFingerprint :: new ( & module. code ) ,
311
319
line_numbers : module. ast . type_info . line_numbers . clone ( ) ,
320
+ interface : package_interface:: ModuleInterface :: from_module ( module) ,
312
321
} ;
313
322
self . io . write_bytes ( & path, & info. to_binary ( ) ) ?;
314
323
@@ -594,28 +603,28 @@ pub(crate) fn module_name(package_path: &Utf8Path, full_module_path: &Utf8Path)
594
603
#[ derive( Debug ) ]
595
604
pub ( crate ) enum Input {
596
605
New ( UncompiledModule ) ,
597
- Cached ( CachedModule ) ,
606
+ Cached ( ( CachedModule , CacheMetadata ) ) ,
598
607
}
599
608
600
609
impl Input {
601
610
pub fn name ( & self ) -> & EcoString {
602
611
match self {
603
612
Input :: New ( m) => & m. name ,
604
- Input :: Cached ( m) => & m. name ,
613
+ Input :: Cached ( m) => & m. 0 . name ,
605
614
}
606
615
}
607
616
608
617
pub fn source_path ( & self ) -> & Utf8Path {
609
618
match self {
610
619
Input :: New ( m) => & m. path ,
611
- Input :: Cached ( m) => & m. source_path ,
620
+ Input :: Cached ( m) => & m. 0 . source_path ,
612
621
}
613
622
}
614
623
615
624
pub fn dependencies ( & self ) -> Vec < EcoString > {
616
625
match self {
617
626
Input :: New ( m) => m. dependencies . iter ( ) . map ( |( n, _) | n. clone ( ) ) . collect ( ) ,
618
- Input :: Cached ( m) => m. dependencies . iter ( ) . map ( |( n, _) | n. clone ( ) ) . collect ( ) ,
627
+ Input :: Cached ( m) => m. 0 . dependencies . iter ( ) . map ( |( n, _) | n. clone ( ) ) . collect ( ) ,
619
628
}
620
629
}
621
630
@@ -645,13 +654,15 @@ pub(crate) struct CachedModule {
645
654
pub line_numbers : LineNumbers ,
646
655
}
647
656
648
- #[ derive( Debug , serde:: Serialize , serde:: Deserialize ) ]
649
- pub ( crate ) struct CacheMetadata {
657
+ #[ derive( Debug , serde:: Serialize , serde:: Deserialize , Clone ) ]
658
+ pub struct CacheMetadata {
659
+ pub name : EcoString ,
650
660
pub mtime : SystemTime ,
651
661
pub codegen_performed : bool ,
652
662
pub dependencies : Vec < ( EcoString , SrcSpan ) > ,
653
663
pub fingerprint : SourceFingerprint ,
654
664
pub line_numbers : LineNumbers ,
665
+ pub interface : package_interface:: ModuleInterface ,
655
666
}
656
667
657
668
impl CacheMetadata {
@@ -664,22 +675,24 @@ impl CacheMetadata {
664
675
}
665
676
}
666
677
667
- #[ derive( Debug , Default , PartialEq , Eq ) ]
678
+ #[ derive( Debug , Default ) ]
668
679
pub ( crate ) struct Loaded {
669
680
pub to_compile : Vec < UncompiledModule > ,
670
681
pub cached : Vec < type_:: ModuleInterface > ,
682
+ pub cached_metadata : Vec < CacheMetadata > ,
671
683
}
672
684
673
685
impl Loaded {
674
686
fn empty ( ) -> Self {
675
687
Self {
676
688
to_compile : vec ! [ ] ,
677
689
cached : vec ! [ ] ,
690
+ cached_metadata : vec ! [ ] ,
678
691
}
679
692
}
680
693
}
681
694
682
- #[ derive( Debug , PartialEq , Eq ) ]
695
+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
683
696
pub ( crate ) struct UncompiledModule {
684
697
pub path : Utf8PathBuf ,
685
698
pub name : EcoString ,
0 commit comments