@@ -4,9 +4,10 @@ use crate::{
44 buildinfo:: RawBuildInfo ,
55 compilers:: { Compiler , CompilerSettings , Language } ,
66 output:: Builds ,
7+ preprocessor:: interface_repr_hash,
78 resolver:: GraphEdges ,
8- ArtifactFile , ArtifactOutput , Artifacts , ArtifactsMap , Graph , OutputContext , ParsedSource ,
9- Project , ProjectPaths , ProjectPathsConfig , SourceCompilationKind ,
9+ ArtifactFile , ArtifactOutput , Artifacts , ArtifactsMap , Graph , OutputContext , Project ,
10+ ProjectPaths , ProjectPathsConfig , SourceCompilationKind ,
1011} ;
1112use foundry_compilers_artifacts:: {
1213 sources:: { Source , Sources } ,
@@ -681,11 +682,8 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
681682 . map ( |import| strip_prefix ( import, self . project . root ( ) ) . into ( ) )
682683 . collect ( ) ;
683684
684- let interface_repr_hash = if self . cache . preprocessed && self . is_source_file ( & file) {
685- self . edges . get_parsed_source ( & file) . and_then ( ParsedSource :: interface_repr_hash)
686- } else {
687- None
688- } ;
685+ let interface_repr_hash = ( self . cache . preprocessed && self . is_source_file ( & file) )
686+ . then ( || self . interface_repr_hash ( source, & file) . to_string ( ) ) ;
689687
690688 let entry = CacheEntry {
691689 last_modification_date : CacheEntry :: read_last_modification_date ( & file)
@@ -703,6 +701,27 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
703701 self . cache . files . insert ( file, entry) ;
704702 }
705703
704+ /// Gets or calculates the content hash for the given source file.
705+ fn content_hash ( & mut self , source : & Source , file : & Path ) -> & str {
706+ self . content_hashes . entry ( file. to_path_buf ( ) ) . or_insert_with ( || source. content_hash ( ) )
707+ }
708+
709+ /// Gets or calculates the interface representation hash for the given source file.
710+ fn interface_repr_hash ( & mut self , source : & Source , file : & Path ) -> & str {
711+ self . interface_repr_hashes
712+ . entry ( file. to_path_buf ( ) )
713+ . or_insert_with ( || {
714+ if let Some ( r) = interface_repr_hash ( & source. content , file) {
715+ return r;
716+ }
717+ self . content_hashes
718+ . entry ( file. to_path_buf ( ) )
719+ . or_insert_with ( || source. content_hash ( ) )
720+ . clone ( )
721+ } )
722+ . as_str ( )
723+ }
724+
706725 /// Returns the set of [Source]s that need to be compiled to produce artifacts for requested
707726 /// input.
708727 ///
@@ -956,17 +975,11 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
956975 /// Adds the file's hashes to the set if not set yet
957976 fn fill_hashes ( & mut self , sources : & Sources ) {
958977 for ( file, source) in sources {
959- let content_hash =
960- self . content_hashes . entry ( file. clone ( ) ) . or_insert_with ( || source. content_hash ( ) ) ;
978+ let _ = self . content_hash ( source, file) ;
961979
962980 // Fill interface representation hashes for source files
963981 if self . cache . preprocessed && self . project . paths . is_source_file ( file) {
964- self . interface_repr_hashes . entry ( file. clone ( ) ) . or_insert_with ( || {
965- self . edges
966- . get_parsed_source ( file)
967- . and_then ( ParsedSource :: interface_repr_hash)
968- . unwrap_or_else ( || content_hash. clone ( ) )
969- } ) ;
982+ let _ = self . interface_repr_hash ( source, file) ;
970983 }
971984 }
972985 }
0 commit comments