Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce MastForestStore #1359

Merged
merged 43 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a94d52d
Introduce `ExternalNode`
plafer Jun 20, 2024
f8ad339
Replace `Assembler.node_id_by_digest` map
plafer Jun 20, 2024
06f421b
add TODOP
plafer Jun 20, 2024
bcf2a9b
Add `Host::get_mast_forest`
plafer Jun 20, 2024
980713d
Move kernel and entrypoint out of `MastForest`
plafer Jun 21, 2024
d2bbcd2
Add Host::get_mast_forest
plafer Jun 21, 2024
32e757e
Remove ProgramError
plafer Jun 21, 2024
f87217a
docs
plafer Jun 21, 2024
71f35f1
cleanup Program constructors
plafer Jun 21, 2024
a39f74f
fix docs
plafer Jun 21, 2024
f7e98af
Make `Program.kernel` an `Arc`
plafer Jun 21, 2024
b5538c5
fix executable
plafer Jun 21, 2024
2eab574
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer Jun 21, 2024
188651b
invoke_mast_root: fix external node creation logic
plafer Jun 23, 2024
b15263c
add failing test
plafer Jun 23, 2024
a94a095
don't make root in `combine_mast_node_ids` and `compile_body`
plafer Jun 23, 2024
7af0bfa
fix External docs
plafer Jun 23, 2024
a6fcf47
fmt
plafer Jun 23, 2024
c66db6f
fix `entrypoint` doc
plafer Jun 23, 2024
572fc7e
Rename `Program::new_with_kernel()`
plafer Jun 23, 2024
08ce2c7
Document `MastForestStore` and `MemMastForestStore`
plafer Jun 23, 2024
50e01e9
fix syscall
plafer Jun 23, 2024
071ab54
execute_* functions: use `MastForest`
plafer Jun 23, 2024
49de40d
`Program`: Remove `Arc` around kernel
plafer Jun 23, 2024
c28c876
remove `Arc` around `MastForest` in `Program`
plafer Jun 23, 2024
78b2b16
Return error on malformed host
plafer Jun 23, 2024
4883b44
Simplify `DefaultHost`
plafer Jun 23, 2024
155a798
`MastForest::add_node()`: add docs
plafer Jun 23, 2024
bc6d13e
fmt
plafer Jun 23, 2024
be24320
add failing `duplicate_procedure()` test
plafer Jun 23, 2024
32aedd6
Introduce `MastForestBuilder`
plafer Jun 23, 2024
088de82
Rename `mod tests` -> `testing`
plafer Jun 25, 2024
9d48fda
add `duplicate_node()` test
plafer Jun 25, 2024
6c62d9b
changelog
plafer Jun 25, 2024
039bba0
Program: use `assert!()` instead of `debug_assert!()`
plafer Jun 26, 2024
9c9e171
`MastForest::make_root()`: add assert
plafer Jun 26, 2024
8e4dc5e
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer Jun 26, 2024
c34e985
fmt
plafer Jun 26, 2024
25fe82f
fix exec invocation
plafer Jul 2, 2024
36ecdd7
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer Jul 2, 2024
3c26bd6
no else blk special case
plafer Jul 2, 2024
34c2f7f
add procedure roots comment
plafer Jul 2, 2024
97d3de8
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add failing test
plafer committed Jun 23, 2024
commit b15263c3c508c2c30f89b7d361e5267c72538dc2
4 changes: 2 additions & 2 deletions assembly/src/assembler/instruction/procedures.rs
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ impl Assembler {
// assembled, and hence be present in the `MastForest`. We currently assume that the
// `MastForest` contains all the procedures being called; "external procedures" only
// known by digest are not currently supported.
mast_forest.find_root(mast_root).ok_or_else(|| {
mast_forest.find_procedure_root(mast_root).ok_or_else(|| {
AssemblyError::UnknownExecTarget {
span,
source_file: current_source_file,
@@ -98,7 +98,7 @@ impl Assembler {
})?
}
InvokeKind::Call => {
let callee_id = mast_forest.find_root(mast_root).unwrap_or_else(|| {
let callee_id = mast_forest.find_procedure_root(mast_root).unwrap_or_else(|| {
// If the MAST root called isn't known to us, make it an external
// reference.
let external_node = MastNode::new_external(mast_root);
5 changes: 4 additions & 1 deletion assembly/src/assembler/tests.rs
Original file line number Diff line number Diff line change
@@ -208,7 +208,10 @@ fn nested_blocks() {
vec![before, r#if1, nested, exec_foo_bar_baz_node_id, syscall_foo_node_id],
&mut expected_mast_forest,
);
let expected_program = Program::new(expected_mast_forest.into(), combined_node_id);

let expected_program = Program::new(expected_mast_forest.into(), combined_node_id);
assert_eq!(expected_program.hash(), program.hash());

// also check that the program has the right number of procedures
assert_eq!(program.num_procedures(), 3);
}
12 changes: 10 additions & 2 deletions core/src/mast/mod.rs
Original file line number Diff line number Diff line change
@@ -96,14 +96,22 @@ impl MastForest {

/// Returns the [`MastNodeId`] of the procedure associated with a given digest, if any.
#[inline(always)]
pub fn find_root(&self, digest: RpoDigest) -> Option<MastNodeId> {
pub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId> {
self.roots.iter().find(|&&root_id| self[root_id].digest() == digest).copied()
}

/// Returns an iterator over the digest of the procedures in this MAST forest.
pub fn roots(&self) -> impl Iterator<Item = RpoDigest> + '_ {
pub fn procedure_roots(&self) -> impl Iterator<Item = RpoDigest> + '_ {
self.roots.iter().map(|&root_id| self[root_id].digest())
}

/// Returns the number of procedures in this MAST forest.
pub fn num_procedures(&self) -> u32 {
self.roots
.len()
.try_into()
.expect("MAST forest contains more than 2^32 procedures.")
}
}

impl Index<MastNodeId> for MastForest {
9 changes: 7 additions & 2 deletions core/src/program.rs
Original file line number Diff line number Diff line change
@@ -90,8 +90,13 @@ impl Program {

/// Returns the [`MastNodeId`] of the procedure root associated with a given digest, if any.
#[inline(always)]
pub fn find_root(&self, digest: RpoDigest) -> Option<MastNodeId> {
self.mast_forest.find_root(digest)
pub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId> {
self.mast_forest.find_procedure_root(digest)
}

/// Returns the number of procedures in this program.
pub fn num_procedures(&self) -> u32 {
self.mast_forest.num_procedures()
}
}

2 changes: 1 addition & 1 deletion processor/src/host/mast_forest_store.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ impl MemMastForestStore {
pub fn insert(&mut self, mast_forest: MastForest) {
let mast_forest = Arc::new(mast_forest);

for root in mast_forest.roots() {
for root in mast_forest.procedure_roots() {
self.mast_forests.insert(root, mast_forest.clone());
}
}
4 changes: 2 additions & 2 deletions processor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -262,7 +262,7 @@ where
root_digest: external_node.digest(),
},
)?;
let root_id = mast_forest.find_root(external_node.digest()).unwrap_or_else(|| panic!("Malformed host: MAST forest indexed by procedure root {} doesn't contain that root.", external_node.digest()));
let root_id = mast_forest.find_procedure_root(external_node.digest()).unwrap_or_else(|| panic!("Malformed host: MAST forest indexed by procedure root {} doesn't contain that root.", external_node.digest()));

let program =
Program::new_with_kernel(mast_forest, root_id, program.kernel().clone());
@@ -385,7 +385,7 @@ where

// get dynamic code from the code block table and execute it
let callee_id = program
.find_root(callee_hash.into())
.find_procedure_root(callee_hash.into())
.ok_or_else(|| ExecutionError::DynamicNodeNotFound(callee_hash.into()))?;
self.execute_mast_node(callee_id, program)?;