@@ -64,11 +64,6 @@ impl<S: CompilerSettings> CompilerCache<S> {
6464 self . files . is_empty ( )
6565 }
6666
67- /// Returns `true` if the cache contains any artifacts for the given file and version.
68- pub fn contains ( & self , file : & Path , version : & Version ) -> bool {
69- self . files . get ( file) . map_or ( true , |entry| !entry. contains_version ( version) )
70- }
71-
7267 /// Removes entry for the given file
7368 pub fn remove ( & mut self , file : & Path ) -> Option < CacheEntry > {
7469 self . files . remove ( file)
@@ -533,8 +528,10 @@ impl CacheEntry {
533528 }
534529
535530 /// Returns `true` if the artifacts set contains the given version
536- pub fn contains_version ( & self , version : & Version ) -> bool {
537- self . artifacts_versions ( ) . any ( |( v, _, _) | v == version)
531+ pub fn contains ( & self , version : & Version , profile : & str ) -> bool {
532+ self . artifacts . values ( ) . any ( |artifacts| {
533+ artifacts. get ( version) . and_then ( |artifacts| artifacts. get ( profile) ) . is_some ( )
534+ } )
538535 }
539536
540537 /// Iterator that yields all artifact files and their version
@@ -688,7 +685,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
688685 /// 2. [SourceCompilationKind::Optimized] - the file is not dirty, but is imported by a dirty
689686 /// file and thus will be processed by solc. For such files we don't need full data, so we
690687 /// are marking them as clean to optimize output selection later.
691- fn filter ( & mut self , sources : & mut Sources , version : & Version ) {
688+ fn filter ( & mut self , sources : & mut Sources , version : & Version , profile : & str ) {
692689 // sources that should be passed to compiler.
693690 let mut compile_complete = HashSet :: new ( ) ;
694691 let mut compile_optimized = HashSet :: new ( ) ;
@@ -697,7 +694,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
697694 self . sources_in_scope . insert ( file. clone ( ) , version. clone ( ) ) ;
698695
699696 // If we are missing artifact for file, compile it.
700- if self . is_missing_artifacts ( file, version) {
697+ if self . is_missing_artifacts ( file, version, profile ) {
701698 compile_complete. insert ( file. clone ( ) ) ;
702699 }
703700
@@ -731,7 +728,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
731728
732729 /// Returns whether we are missing artifacts for the given file and version.
733730 #[ instrument( level = "trace" , skip( self ) ) ]
734- fn is_missing_artifacts ( & self , file : & Path , version : & Version ) -> bool {
731+ fn is_missing_artifacts ( & self , file : & Path , version : & Version , profile : & str ) -> bool {
735732 let Some ( entry) = self . cache . entry ( file) else {
736733 trace ! ( "missing cache entry" ) ;
737734 return true ;
@@ -745,7 +742,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
745742 return false ;
746743 }
747744
748- if !entry. contains_version ( version) {
745+ if !entry. contains ( version, profile ) {
749746 trace ! ( "missing linked artifacts" ) ;
750747 return true ;
751748 }
@@ -788,6 +785,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
788785 . get ( profile. as_str ( ) )
789786 . map_or ( false , |p| p. can_use_cached ( settings) )
790787 {
788+ trace ! ( "dirty profile: {}" , profile) ;
791789 dirty_profiles. insert ( profile. clone ( ) ) ;
792790 }
793791 }
@@ -796,15 +794,20 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCacheInner<'a, T, C> {
796794 self . cache . profiles . remove ( profile) ;
797795 }
798796
799- for ( _, entry) in & mut self . cache . files {
797+ self . cache . files . retain ( |_, entry| {
798+ // keep entries which already had no artifacts
799+ if entry. artifacts . is_empty ( ) {
800+ return true ;
801+ }
800802 entry. artifacts . retain ( |_, artifacts| {
801803 artifacts. retain ( |_, artifacts| {
802804 artifacts. retain ( |profile, _| !dirty_profiles. contains ( profile) ) ;
803805 !artifacts. is_empty ( )
804806 } ) ;
805807 !artifacts. is_empty ( )
806808 } ) ;
807- }
809+ !entry. artifacts . is_empty ( )
810+ } ) ;
808811
809812 for ( profile, settings) in existing_profiles {
810813 if !self . cache . profiles . contains_key ( profile) {
@@ -1031,10 +1034,10 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCache<'a, T, C> {
10311034 }
10321035
10331036 /// Filters out those sources that don't need to be compiled
1034- pub fn filter ( & mut self , sources : & mut Sources , version : & Version ) {
1037+ pub fn filter ( & mut self , sources : & mut Sources , version : & Version , profile : & str ) {
10351038 match self {
10361039 ArtifactsCache :: Ephemeral ( ..) => { }
1037- ArtifactsCache :: Cached ( cache) => cache. filter ( sources, version) ,
1040+ ArtifactsCache :: Cached ( cache) => cache. filter ( sources, version, profile ) ,
10381041 }
10391042 }
10401043
0 commit comments