@@ -6,7 +6,7 @@ use crate::{
66 output:: Builds ,
77 resolver:: GraphEdges ,
88 ArtifactFile , ArtifactOutput , Artifacts , ArtifactsMap , Graph , OutputContext , Project ,
9- ProjectPaths , ProjectPathsConfig , SourceCompilationKind ,
9+ ProjectPaths , ProjectPathsConfig , SourceCompilationKind , SourceParser ,
1010} ;
1111use foundry_compilers_artifacts:: {
1212 sources:: { Source , Sources } ,
@@ -658,7 +658,7 @@ pub(crate) struct ArtifactsCacheInner<
658658 pub cached_builds : Builds < C :: Language > ,
659659
660660 /// Relationship between all the files.
661- pub edges : GraphEdges < C :: ParsedSource > ,
661+ pub edges : GraphEdges < C :: Parser > ,
662662
663663 /// The project.
664664 pub project : & ' a Project < C , T > ,
@@ -723,6 +723,7 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
723723 /// Gets or calculates the interface representation hash for the given source file.
724724 fn interface_repr_hash ( & mut self , source : & Source , file : & Path ) -> & str {
725725 self . interface_repr_hashes . entry ( file. to_path_buf ( ) ) . or_insert_with ( || {
726+ // TODO: use `interface_representation_ast` directly with `edges.parser()`.
726727 if let Some ( r) = interface_repr_hash ( & source. content , file) {
727728 return r;
728729 }
@@ -823,10 +824,10 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
823824
824825 // Walks over all cache entries, detects dirty files and removes them from cache.
825826 fn find_and_remove_dirty ( & mut self ) {
826- fn populate_dirty_files < D > (
827+ fn populate_dirty_files < P : SourceParser > (
827828 file : & Path ,
828829 dirty_files : & mut HashSet < PathBuf > ,
829- edges : & GraphEdges < D > ,
830+ edges : & GraphEdges < P > ,
830831 ) {
831832 for file in edges. importers ( file) {
832833 // If file is marked as dirty we either have already visited it or it was marked as
@@ -890,7 +891,7 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
890891
891892 // Build a temporary graph for walking imports. We need this because `self.edges`
892893 // only contains graph data for in-scope sources but we are operating on cache entries.
893- if let Ok ( graph) = Graph :: < C :: ParsedSource > :: resolve_sources ( & self . project . paths , sources) {
894+ if let Ok ( graph) = Graph :: < C :: Parser > :: resolve_sources ( & self . project . paths , sources) {
894895 let ( sources, edges) = graph. into_sources ( ) ;
895896
896897 // Calculate content hashes for later comparison.
@@ -1020,7 +1021,7 @@ pub(crate) enum ArtifactsCache<
10201021 C : Compiler ,
10211022> {
10221023 /// Cache nothing on disk
1023- Ephemeral ( GraphEdges < C :: ParsedSource > , & ' a Project < C , T > ) ,
1024+ Ephemeral ( GraphEdges < C :: Parser > , & ' a Project < C , T > ) ,
10241025 /// Handles the actual cached artifacts, detects artifacts that can be reused
10251026 Cached ( ArtifactsCacheInner < ' a , T , C > ) ,
10261027}
@@ -1032,7 +1033,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
10321033 #[ instrument( name = "ArtifactsCache::new" , skip( project, edges) ) ]
10331034 pub fn new (
10341035 project : & ' a Project < C , T > ,
1035- edges : GraphEdges < C :: ParsedSource > ,
1036+ edges : GraphEdges < C :: Parser > ,
10361037 preprocessed : bool ,
10371038 ) -> Result < Self > {
10381039 /// Returns the [CompilerCache] to use
@@ -1117,7 +1118,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
11171118 }
11181119
11191120 /// Returns the graph data for this project
1120- pub fn graph ( & self ) -> & GraphEdges < C :: ParsedSource > {
1121+ pub fn graph ( & self ) -> & GraphEdges < C :: Parser > {
11211122 match self {
11221123 ArtifactsCache :: Ephemeral ( graph, _) => graph,
11231124 ArtifactsCache :: Cached ( inner) => & inner. edges ,
@@ -1191,18 +1192,22 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
11911192 ///
11921193 /// Returns all the _cached_ artifacts.
11931194 #[ instrument( name = "ArtifactsCache::consume" , skip_all) ]
1195+ #[ allow( clippy:: type_complexity) ]
11941196 pub fn consume < A > (
11951197 self ,
11961198 written_artifacts : & Artifacts < A > ,
11971199 written_build_infos : & Vec < RawBuildInfo < C :: Language > > ,
11981200 write_to_disk : bool ,
1199- ) -> Result < ( Artifacts < A > , Builds < C :: Language > ) >
1201+ ) -> Result < ( Artifacts < A > , Builds < C :: Language > , GraphEdges < C :: Parser > ) >
12001202 where
12011203 T : ArtifactOutput < Artifact = A > ,
12021204 {
1203- let ArtifactsCache :: Cached ( cache) = self else {
1204- trace ! ( "no cache configured, ephemeral" ) ;
1205- return Ok ( Default :: default ( ) ) ;
1205+ let cache = match self {
1206+ ArtifactsCache :: Ephemeral ( edges, _project) => {
1207+ trace ! ( "no cache configured, ephemeral" ) ;
1208+ return Ok ( ( Default :: default ( ) , Default :: default ( ) , edges) ) ;
1209+ }
1210+ ArtifactsCache :: Cached ( cache) => cache,
12061211 } ;
12071212
12081213 let ArtifactsCacheInner {
@@ -1212,7 +1217,9 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
12121217 dirty_sources,
12131218 sources_in_scope,
12141219 project,
1215- ..
1220+ edges,
1221+ content_hashes : _,
1222+ interface_repr_hashes : _,
12161223 } = cache;
12171224
12181225 // Remove cached artifacts which are out of scope, dirty or appear in `written_artifacts`.
@@ -1264,7 +1271,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
12641271 cache. write ( project. cache_path ( ) ) ?;
12651272 }
12661273
1267- Ok ( ( cached_artifacts, cached_builds) )
1274+ Ok ( ( cached_artifacts, cached_builds, edges ) )
12681275 }
12691276
12701277 /// Marks the cached entry as seen by the compiler, if it's cached.
0 commit comments