Skip to content

Commit

Permalink
Only register local procedures in the MAST forest store (#1462)
Browse files Browse the repository at this point in the history
* fix: only register local procedures in the MAST forest store
  • Loading branch information
bobbinth authored Aug 21, 2024
1 parent 19ed5f4 commit 8bf7503
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion core/src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = RpoDigest> + '_ {
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<Item = RpoDigest> + '_ {
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
Expand Down
11 changes: 11 additions & 0 deletions core/src/mast/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_))
}
Expand Down
3 changes: 2 additions & 1 deletion processor/src/host/mast_forest_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 8bf7503

Please sign in to comment.