diff --git a/CHANGELOG.md b/CHANGELOG.md index cde551574..4a7a3b093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ - Added `new_unsafe()` constructors to MAST node types which do not compute node hashes (#1453). - Consolidated `BasicBlockNode` constructors and converted assert flow to `MastForestError::EmptyBasicBlock` (#1453). +#### Fixes + +- Fixed an issue with registering non-local procedures in `MemMastForestStore` (#1462). + ## 0.10.4 (2024-08-15) - `miden-processor` crate only #### Enhancements diff --git a/core/src/mast/mod.rs b/core/src/mast/mod.rs index 1fba097c7..87a6daa35 100644 --- a/core/src/mast/mod.rs +++ b/core/src/mast/mod.rs @@ -297,11 +297,25 @@ impl MastForest { self.roots.contains(&node_id) } - /// Returns an iterator over the digest of the procedures in this MAST forest. + /// Returns an iterator over the digests of all procedures in this MAST forest. pub fn procedure_digests(&self) -> impl Iterator + '_ { self.roots.iter().map(|&root_id| self[root_id].digest()) } + /// Returns an iterator over the digests of local procedures in this MAST forest. + /// + /// A local procedure is defined as a procedure which is not a single external node. + pub fn local_procedure_digests(&self) -> impl Iterator + '_ { + self.roots.iter().filter_map(|&root_id| { + let node = &self[root_id]; + if node.is_external() { + None + } else { + Some(node.digest()) + } + }) + } + /// Returns an iterator over the IDs of the procedures in this MAST forest. pub fn procedure_roots(&self) -> &[MastNodeId] { &self.roots diff --git a/core/src/mast/node/mod.rs b/core/src/mast/node/mod.rs index bd4b49721..63293a333 100644 --- a/core/src/mast/node/mod.rs +++ b/core/src/mast/node/mod.rs @@ -106,6 +106,17 @@ impl MastNode { // ------------------------------------------------------------------------------------------------ /// Public accessors impl MastNode { + /// Returns true if this node is an external node. + pub fn is_external(&self) -> bool { + matches!(self, MastNode::External(_)) + } + + /// Returns true if this node is a Dyn node. + pub fn is_dyn(&self) -> bool { + matches!(self, MastNode::Dyn) + } + + /// Returns true if this node is a basic block. pub fn is_basic_block(&self) -> bool { matches!(self, Self::Block(_)) } diff --git a/processor/src/host/mast_forest_store.rs b/processor/src/host/mast_forest_store.rs index 27f20dd4d..f6d05b025 100644 --- a/processor/src/host/mast_forest_store.rs +++ b/processor/src/host/mast_forest_store.rs @@ -26,7 +26,8 @@ impl MemMastForestStore { pub fn insert(&mut self, mast_forest: MastForest) { let mast_forest = Arc::new(mast_forest); - for proc_digest in mast_forest.procedure_digests() { + // only register the procedures which are local to this forest + for proc_digest in mast_forest.local_procedure_digests() { self.mast_forests.insert(proc_digest, mast_forest.clone()); } }