Skip to content

Commit

Permalink
chore: Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Oct 24, 2024
1 parent 259f61b commit b58f85f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 9 additions & 1 deletion assembly/src/assembler/mast_forest_merger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ fn mast_forest_merge_assembler() {
export.foo
push.19
end
export.qux
swap drop
end
"#;

let lib_b = r#"
use.lib::mod
export.qux_duplicate
swap drop
end
export.bar
push.2
if.true
Expand All @@ -55,7 +63,7 @@ fn mast_forest_merge_assembler() {
for root in forest.procedure_roots() {
let original_digest = forest.nodes()[root.as_usize()].digest();
let new_root = root_maps.map_root(forest_idx, root).unwrap();
let new_digest = forest.nodes()[new_root.as_usize()].digest();
let new_digest = merged.nodes()[new_root.as_usize()].digest();
assert_eq!(original_digest, new_digest);
}
}
Expand Down
5 changes: 2 additions & 3 deletions core/src/mast/merger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ impl MastForestRootMap {
///
/// This type is meant to encapsulates some guarantees:
///
/// - Indexing into the vector for any ID is safe if that ID is valid for the corresponding forest,
/// which is enforced in the `from_u32_safe` functions (as long as they are used with the correct
/// forest). Despite that, we still cannot index unconditionally in case a node with invalid
/// - Indexing into the vector for any ID is safe if that ID is valid for the corresponding forest.
/// Despite that, we still cannot index unconditionally in case a node with invalid
/// [`DecoratorId`]s is passed to `merge`.
/// - The entry itself can be either None or Some. However:
/// - For `DecoratorId`s we iterate and insert all decorators into this map before retrieving any
Expand Down
4 changes: 2 additions & 2 deletions core/src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ impl MastNodeId {
}
}

#[cfg(test)]
pub fn new_unsafe(value: u32) -> Self {
/// Returns a new [`MastNodeId`] from the given `value` without checking its validity.
pub(crate) fn new_unsafe(value: u32) -> Self {
Self(value)
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/mast/multi_forest_node_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ impl<'forest> MultiMastForestNodeIter<'forest> {

for (forest_idx, forest) in mast_forests.iter().enumerate() {
for (node_idx, node) in forest.nodes().iter().enumerate() {
let node_id = MastNodeId::from_u32_safe(node_idx as u32, mast_forests[forest_idx])
.expect("the passed id should be a valid node in the forest");
// SAFETY: The passed id comes from the iterator over the nodes, so we never exceed
// the forest's number of nodes.
let node_id = MastNodeId::new_unsafe(node_idx as u32);
if !node.is_external() {
non_external_nodes.insert(node.digest(), (forest_idx, node_id));
}
Expand Down Expand Up @@ -335,6 +336,9 @@ pub(crate) enum MultiMastForestIteratorItem {
},
}

// TESTS
// ================================================================================================

#[cfg(test)]
mod tests {
use miden_crypto::hash::rpo::RpoDigest;
Expand Down

0 comments on commit b58f85f

Please sign in to comment.