diff --git a/CHANGELOG.md b/CHANGELOG.md index 1354e4a75e..53d198691c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Introduced `MastForestError` to enforce `MastForest` node count invariant (#1394) - Added functions to `MastForestBuilder` to allow ensuring of nodes with fewer LOC (#1404) - Make `Assembler` single-use (#1409) +- Remove `ProcedureCache` from the assembler (#1411). #### Changed diff --git a/assembly/src/assembler/mod.rs b/assembly/src/assembler/mod.rs index f965e29671..95bb6d4100 100644 --- a/assembly/src/assembler/mod.rs +++ b/assembly/src/assembler/mod.rs @@ -536,7 +536,7 @@ impl Assembler { }; let resolved = self.module_graph.resolve_target(&caller, target)?; match resolved { - ResolvedTarget::Phantom(digest) | ResolvedTarget::Cached { digest, .. } => Ok(digest), + ResolvedTarget::Phantom(digest) => Ok(digest), ResolvedTarget::Exact { gid } | ResolvedTarget::Resolved { gid, .. } => { Ok(mast_forest_builder .get_procedure(gid) diff --git a/assembly/src/assembler/module_graph/analysis/rewrite_check.rs b/assembly/src/assembler/module_graph/analysis/rewrite_check.rs index 0baddf44b2..4c097133e5 100644 --- a/assembly/src/assembler/module_graph/analysis/rewrite_check.rs +++ b/assembly/src/assembler/module_graph/analysis/rewrite_check.rs @@ -68,13 +68,6 @@ impl<'a, 'b: 'a> RewriteCheckVisitor<'a, 'b> { Ok(ResolvedTarget::Exact { .. } | ResolvedTarget::Phantom(_)) => { ControlFlow::Continue(()) } - Ok(ResolvedTarget::Cached { .. }) => { - if let InvocationTarget::MastRoot(_) = target { - ControlFlow::Continue(()) - } else { - ControlFlow::Break(Ok(true)) - } - } } } } diff --git a/assembly/src/assembler/module_graph/mod.rs b/assembly/src/assembler/module_graph/mod.rs index 5abea2a5f4..0ce18226dc 100644 --- a/assembly/src/assembler/module_graph/mod.rs +++ b/assembly/src/assembler/module_graph/mod.rs @@ -47,8 +47,6 @@ pub struct ModuleGraph { /// The set of MAST roots which have procedure definitions in this graph. There can be /// multiple procedures bound to the same root due to having identical code. roots: BTreeMap>, - /// The set of procedures in this graph which have known MAST roots - digests: BTreeMap, kernel_index: Option, kernel: Kernel, } @@ -344,20 +342,6 @@ impl ModuleGraph { self.modules.get(id.module.as_usize()).and_then(|m| m.get(id.index)) } - /// Fetches a [Procedure] by [RpoDigest]. - /// - /// NOTE: This implicitly chooses the first definition for a procedure if the same digest is - /// shared for multiple definitions. - #[allow(unused)] - pub fn get_procedure_by_digest(&self, digest: &RpoDigest) -> Option<&Procedure> { - self.roots - .get(digest) - .and_then(|indices| match self.get_procedure(indices[0])? { - Export::Procedure(ref proc) => Some(proc), - Export::Alias(_) => None, - }) - } - pub fn get_procedure_index_by_digest( &self, digest: &RpoDigest, @@ -365,12 +349,6 @@ impl ModuleGraph { self.roots.get(digest).map(|indices| indices[0]) } - /// Look up the [RpoDigest] associated with the given [GlobalProcedureIndex], if one is known - /// at this point in time. - pub fn get_mast_root(&self, id: GlobalProcedureIndex) -> Option<&RpoDigest> { - self.digests.get(&id) - } - #[allow(unused)] pub fn callees(&self, gid: GlobalProcedureIndex) -> &[GlobalProcedureIndex] { self.callgraph.out_edges(gid) @@ -435,19 +413,6 @@ impl ModuleGraph { } } - match self.digests.entry(id) { - Entry::Occupied(ref entry) => { - assert_eq!( - entry.get(), - &digest, - "attempted to register the same procedure with different digests!" - ); - } - Entry::Vacant(entry) => { - entry.insert(digest); - } - } - Ok(()) } diff --git a/assembly/src/assembler/module_graph/name_resolver.rs b/assembly/src/assembler/module_graph/name_resolver.rs index 6070a52e18..07fb614dc6 100644 --- a/assembly/src/assembler/module_graph/name_resolver.rs +++ b/assembly/src/assembler/module_graph/name_resolver.rs @@ -48,12 +48,6 @@ pub struct CallerInfo { /// Represents the output of the [NameResolver] when it resolves a procedure name. #[derive(Debug)] pub enum ResolvedTarget { - /// The callee is available in the procedure cache, so we know its exact hash. - Cached { - digest: RpoDigest, - /// If the procedure was compiled from source, this is its identifier in the [ModuleGraph] - gid: Option, - }, /// The callee was resolved to a known procedure in the [ModuleGraph] Exact { gid: GlobalProcedureIndex }, /// The callee was resolved to a concrete procedure definition, and can be referenced as @@ -73,7 +67,6 @@ impl ResolvedTarget { pub fn into_global_id(self) -> Option { match self { ResolvedTarget::Exact { gid } | ResolvedTarget::Resolved { gid, .. } => Some(gid), - ResolvedTarget::Cached { gid, .. } => gid, ResolvedTarget::Phantom(_) => None, } } @@ -140,51 +133,31 @@ impl<'a> NameResolver<'a> { module: self.graph.kernel_index.unwrap(), index: index.into_inner(), }; - match self.graph.get_mast_root(gid) { - Some(digest) => Ok(ResolvedTarget::Cached { - digest: *digest, - gid: Some(gid), - }), - None => Ok(ResolvedTarget::Exact { gid }), - } + Ok(ResolvedTarget::Exact { gid }) } Some(ResolvedProcedure::Local(index)) => { let gid = GlobalProcedureIndex { module: caller.module, index: index.into_inner(), }; - match self.graph.get_mast_root(gid) { - Some(digest) => Ok(ResolvedTarget::Cached { - digest: *digest, - gid: Some(gid), - }), - None => Ok(ResolvedTarget::Exact { gid }), - } + Ok(ResolvedTarget::Exact { gid }) } Some(ResolvedProcedure::External(ref fqn)) => { let gid = self.find(caller, fqn)?; - match self.graph.get_mast_root(gid) { - Some(digest) => Ok(ResolvedTarget::Cached { - digest: *digest, - gid: Some(gid), - }), - None => { - let path = self.module_path(gid.module); - let pending_offset = self.graph.modules.len(); - let name = if gid.module.as_usize() >= pending_offset { - self.pending[gid.module.as_usize() - pending_offset] - .resolver - .get_name(gid.index) - .clone() - } else { - self.graph[gid].name().clone() - }; - Ok(ResolvedTarget::Resolved { - gid, - target: InvocationTarget::AbsoluteProcedurePath { name, path }, - }) - } - } + let path = self.module_path(gid.module); + let pending_offset = self.graph.modules.len(); + let name = if gid.module.as_usize() >= pending_offset { + self.pending[gid.module.as_usize() - pending_offset] + .resolver + .get_name(gid.index) + .clone() + } else { + self.graph[gid].name().clone() + }; + Ok(ResolvedTarget::Resolved { + gid, + target: InvocationTarget::AbsoluteProcedurePath { name, path }, + }) } Some(ResolvedProcedure::MastRoot(ref digest)) => { match self.graph.get_procedure_index_by_digest(digest) { @@ -241,28 +214,20 @@ impl<'a> NameResolver<'a> { name: name.clone(), }; let gid = self.find(caller, &fqn)?; - match self.graph.get_mast_root(gid) { - Some(digest) => Ok(ResolvedTarget::Cached { - digest: *digest, - gid: Some(gid), - }), - None => { - let path = self.module_path(gid.module); - let pending_offset = self.graph.modules.len(); - let name = if gid.module.as_usize() >= pending_offset { - self.pending[gid.module.as_usize() - pending_offset] - .resolver - .get_name(gid.index) - .clone() - } else { - self.graph[gid].name().clone() - }; - Ok(ResolvedTarget::Resolved { - gid, - target: InvocationTarget::AbsoluteProcedurePath { name, path }, - }) - } - } + let path = self.module_path(gid.module); + let pending_offset = self.graph.modules.len(); + let name = if gid.module.as_usize() >= pending_offset { + self.pending[gid.module.as_usize() - pending_offset] + .resolver + .get_name(gid.index) + .clone() + } else { + self.graph[gid].name().clone() + }; + Ok(ResolvedTarget::Resolved { + gid, + target: InvocationTarget::AbsoluteProcedurePath { name, path }, + }) } None => Err(AssemblyError::UndefinedModule { span: target.span(), @@ -280,13 +245,7 @@ impl<'a> NameResolver<'a> { name: name.clone(), }; let gid = self.find(caller, &fqn)?; - match self.graph.get_mast_root(gid) { - Some(digest) => Ok(ResolvedTarget::Cached { - digest: *digest, - gid: Some(gid), - }), - None => Ok(ResolvedTarget::Exact { gid }), - } + Ok(ResolvedTarget::Exact { gid }) } } } diff --git a/assembly/src/assembler/module_graph/rewrites/module.rs b/assembly/src/assembler/module_graph/rewrites/module.rs index 73218ddf8b..9d39307b89 100644 --- a/assembly/src/assembler/module_graph/rewrites/module.rs +++ b/assembly/src/assembler/module_graph/rewrites/module.rs @@ -11,7 +11,7 @@ use crate::{ InvocationTarget, Invoke, InvokeKind, Module, Procedure, }, diagnostics::SourceFile, - AssemblyError, Span, Spanned, + AssemblyError, Spanned, }; /// A [ModuleRewriter] handles applying all of the module-wide rewrites to a [Module] that is being @@ -67,13 +67,6 @@ impl<'a, 'b: 'a> ModuleRewriter<'a, 'b> { }; match self.resolver.resolve_target(&caller, target) { Err(err) => return ControlFlow::Break(err), - Ok(ResolvedTarget::Cached { digest, .. }) => { - *target = InvocationTarget::MastRoot(Span::new(target.span(), digest)); - self.invoked.insert(Invoke { - kind, - target: target.clone(), - }); - } Ok(ResolvedTarget::Phantom(_)) => (), Ok(ResolvedTarget::Exact { .. }) => { self.invoked.insert(Invoke {