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

Implement table-based MAST #1349

Merged
merged 109 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
13fab50
MastForest scaffolding
plafer Jun 5, 2024
ede129f
implement `CallNode` and `DynNode`
plafer Jun 5, 2024
2715666
Implement `BasicBlockNode` processing
plafer Jun 5, 2024
e36fb40
implement `External` processing
plafer Jun 5, 2024
eee816b
implement `execute_mast`
plafer Jun 5, 2024
fd77cf7
Add `MastForest::add_node()`
plafer Jun 5, 2024
e93889f
`BasicBlockNode` constructors
plafer Jun 5, 2024
408f082
JoinNode constructor
plafer Jun 5, 2024
464773a
SplitNode constructor
plafer Jun 5, 2024
7276593
LoopNode constructor
plafer Jun 5, 2024
6f607ae
`CallNode` constructors
plafer Jun 5, 2024
7fd1755
dyn and external constructors
plafer Jun 5, 2024
fde1c72
Remove comment
plafer Jun 5, 2024
f9a1d0d
`SpanBuilder` methods
plafer Jun 5, 2024
ae2bd01
`MastNodeId`: make `u32`
plafer Jun 6, 2024
2678a5a
fmt
plafer Jun 6, 2024
979e6a3
implement `Index` for `MastForex`, and mark `inline(always)`
plafer Jun 6, 2024
805be4a
Assembler: switch to use `MastForest`
plafer Jun 6, 2024
d5db165
`Assembler::assemble_test()`
plafer Jun 7, 2024
34fc0bb
Add `Display` to `MastForest`
plafer Jun 7, 2024
b408505
introduce `MastNodePrettyPrint`
plafer Jun 7, 2024
273bf76
Introduce `MastNodeDisplay`
plafer Jun 7, 2024
2babfde
fix nested_blocks test
plafer Jun 7, 2024
67106f3
BasicBlockNode: fix pretty print
plafer Jun 7, 2024
d99a915
revert `basic_block` change for now
plafer Jun 7, 2024
407f8ac
fix procedure invocation
plafer Jun 7, 2024
d93c304
Make `MastForest::get_node_id()` faillible, and use indexing everywhere
plafer Jun 7, 2024
93c11df
comment
plafer Jun 7, 2024
7411985
Rename `ExternalNode` -> `ProxyNode`
plafer Jun 7, 2024
d91bff1
update hash_memoization_control_blocks
plafer Jun 7, 2024
e7c06a3
update hash_memoization_control_blocks
plafer Jun 7, 2024
17a2b6f
update `build_bar_hash()`
plafer Jun 7, 2024
ac3691f
update decoder tests
plafer Jun 7, 2024
548009c
update processor tests
plafer Jun 7, 2024
3738d17
Merge branch 'next' into plafer-table-based-mast
plafer Jun 7, 2024
cae7bfe
processor tests
plafer Jun 10, 2024
93f79da
Remove `CodeBlock` and everything related
plafer Jun 10, 2024
424f029
Move `OpBatch`
plafer Jun 10, 2024
d79adf1
move tests
plafer Jun 10, 2024
710a142
Move `Kernel`
plafer Jun 10, 2024
26566bb
Move `ProgramInfo`
plafer Jun 10, 2024
7c26f85
rename `ensure_node()`
plafer Jun 10, 2024
76f63dc
Remove `combine_basic_blocks()`
plafer Jun 11, 2024
64a6b29
inline procedures on exec
plafer Jun 11, 2024
bce68f8
fix nested_blocks()
plafer Jun 11, 2024
63ac435
Remove `Proxy` node
plafer Jun 11, 2024
e9d2c92
Add comment in `invoke_mast_root()` about our assumptions
plafer Jun 11, 2024
354bbd3
move `MastNode` in submodule
plafer Jun 11, 2024
4f21406
rename `execute_mast_node()` and friends
plafer Jun 11, 2024
3dc679a
Introduce `Program`
plafer Jun 11, 2024
9a1146c
use `Program` everywhere
plafer Jun 11, 2024
8556210
fix `nested_control_blocks()` test
plafer Jun 11, 2024
7de110d
TestContext: use `assemble_test()`
plafer Jun 11, 2024
9bef046
program_with_nested_procedures fix
plafer Jun 11, 2024
b83bce5
fix program_with_one_procedure()
plafer Jun 11, 2024
57e1341
remove ignored test program_with_empty_procedure
plafer Jun 11, 2024
bc93877
fix program_with_one_import_and_hex_call
plafer Jun 11, 2024
494f4ec
ignore phantom mast call
plafer Jun 11, 2024
d616a81
fix comment_in_nested_control_blocks
plafer Jun 11, 2024
73c162f
fix test `module_alias()`
plafer Jun 11, 2024
22bcac7
fix `program_with_proc_locals()`
plafer Jun 11, 2024
df8709b
fix `program_with_reexported_proc_in_another/same_library`
plafer Jun 11, 2024
8546c21
Remove `procedure_cache()` test capability from `Assembler`
plafer Jun 11, 2024
f9c1d6e
Remove `Assembler::assemble_test()`
plafer Jun 11, 2024
8039cfb
assemble_with_options_in_context needs to consume self
plafer Jun 11, 2024
c8baccc
address TODOs
plafer Jun 11, 2024
7441749
`SplitNode`: move `to_pretty_print()` impl
plafer Jun 12, 2024
2773f37
Add `DynNode` digest test
plafer Jun 12, 2024
e50b961
verifier: export `ProgramInfo` and `Kernel`
plafer Jun 12, 2024
42b4b2a
execute: instrument("execute_program")
plafer Jun 12, 2024
aae29eb
`execute_mast_node`: use `get_node_id()` in case of errors
plafer Jun 12, 2024
c98029e
execute_call_node: use `get_node_by_id()`
plafer Jun 12, 2024
6dd2f0c
miden lib: restore all exports
plafer Jun 12, 2024
8e01659
fix `miden` crate
plafer Jun 12, 2024
4cdcffc
make `batch_ops` private
plafer Jun 12, 2024
fb151de
basic_block_node: fix docstring indentation
plafer Jun 12, 2024
e0d5cdf
fix mast module path
plafer Jun 12, 2024
2b0a44c
fix `Assembler::assemble_module()`
plafer Jun 12, 2024
fdad706
move `set_kernel` call
plafer Jun 12, 2024
9adc496
pretty print `basic_block` instead of `span`
plafer Jun 12, 2024
6960a56
cleanup MastNode.to_pretty_print
plafer Jun 12, 2024
d70308b
fix doc tests
plafer Jun 14, 2024
4c2af01
clippy
plafer Jun 14, 2024
ca59eb9
Update core/src/mast/mod.rs
plafer Jun 14, 2024
1f6a13e
Update core/src/mast/mod.rs
plafer Jun 14, 2024
a31ecd4
Use `as` operator for usize <-> u32
plafer Jun 14, 2024
4306ce2
inline(always) on `index()`
plafer Jun 14, 2024
6a06f32
use `Option.get()`
plafer Jun 14, 2024
2ef3a98
remove unused file
plafer Jun 14, 2024
ba75261
Use `binary_search` instead of linear search
plafer Jun 14, 2024
ab78daf
fix cli_run
plafer Jun 14, 2024
5b90c5b
fix asmop_repeat_test
plafer Jun 14, 2024
2fde2ba
docstring
plafer Jun 14, 2024
ceca4f6
fix test_falcon512_probabilistic_product_failure
plafer Jun 14, 2024
d3ff423
introduce `Assembler::assemble_program()`
plafer Jun 16, 2024
60428d4
Rename error variant to `MastNodeNotFoundInForest`
plafer Jun 16, 2024
5b70d83
test_utils: compile() returns `Program`
plafer Jun 16, 2024
bc8719d
fix `generate_blake3_program()`
plafer Jun 16, 2024
a062ba9
Use `program.get_node_by_id()` in the decoder
plafer Jun 16, 2024
fad9712
wrap at 100 and fix comment
plafer Jun 16, 2024
c34a532
rename `Procedure::code()` to `body_node` terminology
plafer Jun 16, 2024
4207e87
update changelog
plafer Jun 16, 2024
453f60f
clippy
plafer Jun 16, 2024
7ac1212
Remove disabled serialization tests
plafer Jun 18, 2024
c310a6f
Use `try_into()` for `usize -> u32` conversion
plafer Jun 18, 2024
d5c14c6
Remove `miette` dependency from `core`
plafer Jun 18, 2024
67343d1
fix README
plafer Jun 18, 2024
0d0e3e6
Remove `Program` type annotation
plafer Jun 18, 2024
39411a2
clippy
plafer Jun 18, 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
4 changes: 2 additions & 2 deletions air/src/constraints/chiplets/hasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub fn get_transition_constraint_count() -> usize {

/// Enforces constraints for the hasher chiplet.
///
/// - The `hasher_flag` determines if the hasher chiplet is currently enabled. It should be
/// computed by the caller and set to `Felt::ONE`
/// - The `hasher_flag` determines if the hasher chiplet is currently enabled. It should be computed
/// by the caller and set to `Felt::ONE`
/// - The `transition_flag` indicates whether this is the last row this chiplet's execution trace,
/// and therefore the constraints should not be enforced.
pub fn enforce_constraints<E: FieldElement<BaseField = Felt>>(
Expand Down
12 changes: 6 additions & 6 deletions air/src/constraints/stack/field_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ pub fn enforce_incr_constraints<E: FieldElement>(
/// in the stack with its bitwise not value. Therefore, the following constraints are
/// enforced:
/// - The top element should be a binary. It is enforced as a general constraint.
/// - The first element of the next frame should be a binary not of the first element of
/// the current frame. s0` + s0 = 1.
/// - The first element of the next frame should be a binary not of the first element of the current
/// frame. s0` + s0 = 1.
pub fn enforce_not_constraints<E: FieldElement>(
frame: &EvaluationFrame<E>,
result: &mut [E],
Expand All @@ -206,8 +206,8 @@ pub fn enforce_not_constraints<E: FieldElement>(

/// Enforces constraints of the AND operation. The AND operation computes the bitwise and of the
/// first two elements in the current trace. Therefore, the following constraints are enforced:
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0,
/// s1^2 - s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0, s1^2 -
/// s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The first element of the next frame should be a binary and of the first two elements in the
/// current frame. s0` - s0 * s1 = 0.
pub fn enforce_and_constraints<E: FieldElement>(
Expand All @@ -233,8 +233,8 @@ pub fn enforce_and_constraints<E: FieldElement>(

/// Enforces constraints of the OR operation. The OR operation computes the bitwise or of the
/// first two elements in the current trace. Therefore, the following constraints are enforced:
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0,
/// s1^2 - s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0, s1^2 -
/// s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The first element of the next frame should be a binary or of the first two elements in the
/// current frame. s0` - ( s0 + s1 - s0 * s1 ) = 0.
pub fn enforce_or_constraints<E: FieldElement>(
Expand Down
7 changes: 3 additions & 4 deletions air/src/constraints/stack/overflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ pub fn enforce_stack_depth_constraints<E: FieldElement>(

/// Enforces constraints on the overflow flag h0. Therefore, the following constraints
/// are enforced:
/// - If overflow table has values, then, h0 should be set to ONE, otherwise it should
/// be ZERO.
/// - If overflow table has values, then, h0 should be set to ONE, otherwise it should be ZERO.
pub fn enforce_overflow_flag_constraints<E: FieldElement>(
frame: &EvaluationFrame<E>,
result: &mut [E],
Expand All @@ -107,8 +106,8 @@ pub fn enforce_overflow_flag_constraints<E: FieldElement>(
}

/// Enforces constraints on the bookkeeping index `b1`. The following constraints are enforced:
/// - In the case of a right shift operation, the next b1 index should be updated with current
/// `clk` value.
/// - In the case of a right shift operation, the next b1 index should be updated with current `clk`
/// value.
/// - In the case of a left shift operation, the last stack item should be set to ZERO when the
/// depth of the stack is 16.
pub fn enforce_overflow_index_constraints<E: FieldElement>(
Expand Down
8 changes: 4 additions & 4 deletions air/src/constraints/stack/stack_manipulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ pub fn enforce_pad_constraints<E: FieldElement>(
/// Enforces constraints of the DUPn and MOVUPn operations. The DUPn operation copies the element
/// at depth n in the stack and pushes the copy onto the stack, whereas MOVUPn opearation moves the
/// element at depth n to the top of the stack. Therefore, the following constraints are enforced:
/// - The top element in the next frame should be equal to the element at depth n in the
/// current frame. s0` - sn = 0.
/// - The top element in the next frame should be equal to the element at depth n in the current
/// frame. s0` - sn = 0.
pub fn enforce_dup_movup_n_constraints<E: FieldElement>(
frame: &EvaluationFrame<E>,
result: &mut [E],
Expand Down Expand Up @@ -244,8 +244,8 @@ pub fn enforce_swapwx_constraints<E: FieldElement>(

/// Enforces constraints of the MOVDNn operation. The MOVDNn operation moves the top element
/// to depth n in the stack. Therefore, the following constraints are enforced:
/// - The top element in the current frame should be equal to the element at depth n in the
/// next frame. s0 - sn` = 0.
/// - The top element in the current frame should be equal to the element at depth n in the next
/// frame. s0 - sn` = 0.
pub fn enforce_movdnn_constraints<E: FieldElement>(
frame: &EvaluationFrame<E>,
result: &mut [E],
Expand Down
4 changes: 2 additions & 2 deletions air/src/constraints/stack/u32_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ pub fn enforce_u32split_constraints<E: FieldElement<BaseField = Felt>>(
/// Enforces constraints of the U32ADD operation. The U32ADD operation adds the top two
/// elements in the current trace of the stack. Therefore, the following constraints are
/// enforced:
/// - The aggregation of limbs from the helper registers is equal to the sum of the top two
/// element in the stack.
/// - The aggregation of limbs from the helper registers is equal to the sum of the top two element
/// in the stack.
pub fn enforce_u32add_constraints<E: FieldElement<BaseField = Felt>>(
frame: &EvaluationFrame<E>,
result: &mut [E],
Expand Down
4 changes: 2 additions & 2 deletions air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ impl ExecutionOptions {
///
/// In debug mode the VM does the following:
/// - Executes `debug` instructions (these are ignored in regular mode).
/// - Records additional info about program execution (e.g., keeps track of stack state at
/// every cycle of the VM) which enables stepping through the program forward and backward.
/// - Records additional info about program execution (e.g., keeps track of stack state at every
/// cycle of the VM) which enables stepping through the program forward and backward.
pub fn with_debugging(mut self) -> Self {
self.enable_debugging = true;
self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use super::{AssemblyContext, BodyWrapper, Decorator, DecoratorList, Instruction};
use alloc::{borrow::Borrow, string::ToString, vec::Vec};
use vm_core::{code_blocks::CodeBlock, AdviceInjector, AssemblyOp, Operation};
use vm_core::{
mast::{MastForest, MastNode, MastNodeId},
AdviceInjector, AssemblyOp, Operation,
};

// SPAN BUILDER
// BASIC BLOCK BUILDER
// ================================================================================================

/// A helper struct for constructing SPAN blocks while compiling procedure bodies.
Expand All @@ -13,15 +16,15 @@ use vm_core::{code_blocks::CodeBlock, AdviceInjector, AssemblyOp, Operation};
/// The same span builder can be used to construct many blocks. It is expected that when the last
/// SPAN block in a procedure's body is constructed `extract_final_span_into()` will be used.
#[derive(Default)]
pub struct SpanBuilder {
pub struct BasicBlockBuilder {
ops: Vec<Operation>,
decorators: DecoratorList,
epilogue: Vec<Operation>,
last_asmop_pos: usize,
}

/// Constructors
impl SpanBuilder {
impl BasicBlockBuilder {
/// Returns a new [SpanBuilder] instantiated with the specified optional wrapper.
///
/// If the wrapper is provided, the prologue of the wrapper is immediately appended to the
Expand All @@ -41,7 +44,7 @@ impl SpanBuilder {
}

/// Operations
impl SpanBuilder {
impl BasicBlockBuilder {
/// Adds the specified operation to the list of span operations.
pub fn push_op(&mut self, op: Operation) {
self.ops.push(op);
Expand All @@ -64,8 +67,8 @@ impl SpanBuilder {
}

/// Decorators
impl SpanBuilder {
/// Add ths specified decorator to the list of span decorators.
impl BasicBlockBuilder {
/// Add the specified decorator to the list of span decorators.
pub fn push_decorator(&mut self, decorator: Decorator) {
self.decorators.push((self.ops.len(), decorator));
}
Expand Down Expand Up @@ -114,34 +117,40 @@ impl SpanBuilder {
}

/// Span Constructors
impl SpanBuilder {
/// Creates a new SPAN block from the operations and decorators currently in this builder and
/// appends the block to the provided target.
impl BasicBlockBuilder {
/// Creates and returns a new BASIC BLOCK node from the operations and decorators currently in
/// this builder. If the builder is empty, then no node is created and `None` is returned.
///
/// This consumes all operations and decorators in the builder, but does not touch the
/// operations in the epilogue of the builder.
pub fn extract_span_into(&mut self, target: &mut Vec<CodeBlock>) {
pub fn make_basic_block(&mut self, mast_forest: &mut MastForest) -> Option<MastNodeId> {
if !self.ops.is_empty() {
let ops = self.ops.drain(..).collect();
let decorators = self.decorators.drain(..).collect();
target.push(CodeBlock::new_span_with_decorators(ops, decorators));

let basic_block_node = MastNode::new_basic_block_with_decorators(ops, decorators);
let basic_block_node_id = mast_forest.ensure_node(basic_block_node);

Some(basic_block_node_id)
} else if !self.decorators.is_empty() {
// this is a bug in the assembler. we shouldn't have decorators added without their
// associated operations
// TODO: change this to an error or allow decorators in empty span blocks
unreachable!("decorators in an empty SPAN block")
} else {
None
}
}

/// Creates a new SPAN block from the operations and decorators currently in this builder and
/// appends the block to the provided target.
/// Creates and returns a new BASIC BLOCK node from the operations and decorators currently in
/// this builder. If the builder is empty, then no node is created and `None` is returned.
///
/// The main differences from the `extract_span_int()` method above are:
/// - Operations contained in the epilogue of the span builder are appended to the list of ops
/// which go into the new SPAN block.
/// - The span builder is consumed in the process.
pub fn extract_final_span_into(mut self, target: &mut Vec<CodeBlock>) {
/// The main differences with [`Self::to_basic_block`] are:
/// - Operations contained in the epilogue of the builder are appended to the list of ops which
/// go into the new BASIC BLOCK node.
/// - The builder is consumed in the process.
pub fn into_basic_block(mut self, mast_forest: &mut MastForest) -> Option<MastNodeId> {
self.ops.append(&mut self.epilogue);
self.extract_span_into(target);
self.make_basic_block(mast_forest)
}
}
7 changes: 4 additions & 3 deletions assembly/src/assembler/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
diagnostics::SourceFile,
AssemblyError, LibraryPath, RpoDigest, SourceSpan, Span, Spanned,
};
use vm_core::code_blocks::CodeBlock;
use vm_core::mast::{MastForest, MastNodeId};

// ASSEMBLY CONTEXT
// ================================================================================================
Expand Down Expand Up @@ -168,6 +168,7 @@ impl AssemblyContext {
&mut self,
callee: &Procedure,
inlined: bool,
mast_forest: &MastForest,
) -> Result<(), AssemblyError> {
let context = self.unwrap_current_procedure_mut();

Expand All @@ -176,7 +177,7 @@ impl AssemblyContext {

// If the callee is not being inlined, add it to our callset
if !inlined {
context.insert_callee(callee.mast_root());
context.insert_callee(callee.mast_root(mast_forest));
}

Ok(())
Expand Down Expand Up @@ -264,7 +265,7 @@ impl ProcedureContext {
self.visibility.is_syscall()
}

pub fn into_procedure(self, code: CodeBlock) -> Box<Procedure> {
pub fn into_procedure(self, code: MastNodeId) -> Box<Procedure> {
bobbinth marked this conversation as resolved.
Show resolved Hide resolved
let procedure = Procedure::new(self.name, self.visibility, self.num_locals as u32, code)
.with_span(self.span)
.with_source_file(self.source_file)
Expand Down
6 changes: 3 additions & 3 deletions assembly/src/assembler/instruction/adv_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{validate_param, SpanBuilder};
use super::{validate_param, BasicBlockBuilder};
use crate::{ast::AdviceInjectorNode, AssemblyError, ADVICE_READ_LIMIT};
use vm_core::Operation;

Expand All @@ -12,7 +12,7 @@ use vm_core::Operation;
/// # Errors
/// Returns an error if the specified number of values to pushed is smaller than 1 or greater
/// than 16.
pub fn adv_push(span: &mut SpanBuilder, n: u8) -> Result<(), AssemblyError> {
pub fn adv_push(span: &mut BasicBlockBuilder, n: u8) -> Result<(), AssemblyError> {
validate_param(n, 1..=ADVICE_READ_LIMIT)?;
span.push_op_many(Operation::AdvPop, n as usize);
Ok(())
Expand All @@ -22,6 +22,6 @@ pub fn adv_push(span: &mut SpanBuilder, n: u8) -> Result<(), AssemblyError> {
// ================================================================================================

/// Appends advice injector decorator to the span.
pub fn adv_inject(span: &mut SpanBuilder, injector: &AdviceInjectorNode) {
pub fn adv_inject(span: &mut BasicBlockBuilder, injector: &AdviceInjectorNode) {
span.push_advice_injector(injector.into());
}
16 changes: 8 additions & 8 deletions assembly/src/assembler/instruction/crypto_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::SpanBuilder;
use super::BasicBlockBuilder;
use vm_core::{AdviceInjector, Operation::*};

// HASHING
Expand All @@ -23,7 +23,7 @@ use vm_core::{AdviceInjector, Operation::*};
/// 3. Drop D and B to achieve our result [C, ...]
///
/// This operation takes 20 VM cycles.
pub(super) fn hash(span: &mut SpanBuilder) {
pub(super) fn hash(span: &mut BasicBlockBuilder) {
#[rustfmt::skip]
let ops = [
// add 4 elements to the stack to be used as the capacity elements for the RPO permutation
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(super) fn hash(span: &mut SpanBuilder) {
/// 4. Drop F and D to return our result [E, ...].
///
/// This operation takes 16 VM cycles.
pub(super) fn hmerge(span: &mut SpanBuilder) {
pub(super) fn hmerge(span: &mut BasicBlockBuilder) {
#[rustfmt::skip]
let ops = [
// Add 4 elements to the stack to prepare the capacity portion for the RPO permutation
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(super) fn hmerge(span: &mut SpanBuilder) {
/// - root of the tree, 4 elements.
///
/// This operation takes 9 VM cycles.
pub(super) fn mtree_get(span: &mut SpanBuilder) {
pub(super) fn mtree_get(span: &mut BasicBlockBuilder) {
// stack: [d, i, R, ...]
// pops the value of the node we are looking for from the advice stack
read_mtree_node(span);
Expand Down Expand Up @@ -140,7 +140,7 @@ pub(super) fn mtree_get(span: &mut SpanBuilder) {
/// - new root of the tree after the update, 4 elements
///
/// This operation takes 29 VM cycles.
pub(super) fn mtree_set(span: &mut SpanBuilder) {
pub(super) fn mtree_set(span: &mut BasicBlockBuilder) {
// stack: [d, i, R_old, V_new, ...]

// stack: [V_old, R_new, ...] (29 cycles)
Expand All @@ -160,7 +160,7 @@ pub(super) fn mtree_set(span: &mut SpanBuilder) {
/// It is not checked whether the provided roots exist as Merkle trees in the advide providers.
///
/// This operation takes 16 VM cycles.
pub(super) fn mtree_merge(span: &mut SpanBuilder) {
pub(super) fn mtree_merge(span: &mut BasicBlockBuilder) {
// stack input: [R_rhs, R_lhs, ...]
// stack output: [R_merged, ...]

Expand Down Expand Up @@ -192,7 +192,7 @@ pub(super) fn mtree_merge(span: &mut SpanBuilder) {
/// - new value of the node, 4 elements (only in the case of mtree_set)
///
/// This operation takes 4 VM cycles.
fn read_mtree_node(span: &mut SpanBuilder) {
fn read_mtree_node(span: &mut BasicBlockBuilder) {
// The stack should be arranged in the following way: [d, i, R, ...] so that the decorator
// can fetch the node value from the root. In the `mtree.get` operation we have the stack in
// the following format: [d, i, R], whereas in the case of `mtree.set` we would also have the
Expand All @@ -210,7 +210,7 @@ fn read_mtree_node(span: &mut SpanBuilder) {
/// and perform the mutation on the copied tree.
///
/// This operation takes 29 VM cycles.
fn update_mtree(span: &mut SpanBuilder) {
fn update_mtree(span: &mut BasicBlockBuilder) {
// stack: [d, i, R_old, V_new, ...]
// output: [R_new, R_old, V_new, V_old, ...]

Expand Down
13 changes: 8 additions & 5 deletions assembly/src/assembler/instruction/env_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{mem_ops::local_to_absolute_addr, push_felt, AssemblyContext, SpanBuilder};
use super::{mem_ops::local_to_absolute_addr, push_felt, AssemblyContext, BasicBlockBuilder};
use crate::{AssemblyError, Felt, Spanned};
use vm_core::Operation::*;

Expand All @@ -10,7 +10,7 @@ use vm_core::Operation::*;
/// In cases when the immediate value is 0, `PUSH` operation is replaced with `PAD`. Also, in cases
/// when immediate value is 1, `PUSH` operation is replaced with `PAD INCR` because in most cases
/// this will be more efficient than doing a `PUSH`.
pub fn push_one<T>(imm: T, span: &mut SpanBuilder)
pub fn push_one<T>(imm: T, span: &mut BasicBlockBuilder)
where
T: Into<Felt>,
{
Expand All @@ -23,7 +23,7 @@ where
/// In cases when the immediate value is 0, `PUSH` operation is replaced with `PAD`. Also, in cases
/// when immediate value is 1, `PUSH` operation is replaced with `PAD INCR` because in most cases
/// this will be more efficient than doing a `PUSH`.
pub fn push_many<T>(imms: &[T], span: &mut SpanBuilder)
pub fn push_many<T>(imms: &[T], span: &mut BasicBlockBuilder)
where
T: Into<Felt> + Copy,
{
Expand All @@ -39,7 +39,7 @@ where
/// # Errors
/// Returns an error if index is greater than the number of procedure locals.
pub fn locaddr(
span: &mut SpanBuilder,
span: &mut BasicBlockBuilder,
index: u16,
context: &AssemblyContext,
) -> Result<(), AssemblyError> {
Expand All @@ -51,7 +51,10 @@ pub fn locaddr(
///
/// # Errors
/// Returns an error if the instruction is being executed outside of kernel context.
pub fn caller(span: &mut SpanBuilder, context: &AssemblyContext) -> Result<(), AssemblyError> {
pub fn caller(
span: &mut BasicBlockBuilder,
context: &AssemblyContext,
) -> Result<(), AssemblyError> {
let current_procedure = context.unwrap_current_procedure();
if !current_procedure.is_kernel() {
return Err(AssemblyError::CallerOutsideOfKernel {
Expand Down
Loading
Loading