pub struct MastForest { /* private fields */ }
Expand description
Represents one or more procedures, represented as a collection of MastNode
s.
A MastForest
does not have an entrypoint, and hence is not executable. A crate::Program
can be built from a MastForest
to specify an entrypoint.
Implementations§
Source§impl MastForest
Constructors
impl MastForest
Constructors
Sourcepub fn new() -> MastForest
pub fn new() -> MastForest
Creates a new empty MastForest
.
Source§impl MastForest
State mutators
impl MastForest
State mutators
Sourcepub fn add_decorator(
&mut self,
decorator: Decorator,
) -> Result<DecoratorId, MastForestError>
pub fn add_decorator( &mut self, decorator: Decorator, ) -> Result<DecoratorId, MastForestError>
Adds a decorator to the forest, and returns the associated DecoratorId
.
Sourcepub fn add_node(
&mut self,
node: MastNode,
) -> Result<MastNodeId, MastForestError>
pub fn add_node( &mut self, node: MastNode, ) -> Result<MastNodeId, MastForestError>
Adds a node to the forest, and returns the associated MastNodeId
.
Adding two duplicate nodes will result in two distinct returned MastNodeId
s.
Sourcepub fn add_block(
&mut self,
operations: Vec<Operation>,
decorators: Option<Vec<(usize, DecoratorId)>>,
) -> Result<MastNodeId, MastForestError>
pub fn add_block( &mut self, operations: Vec<Operation>, decorators: Option<Vec<(usize, DecoratorId)>>, ) -> Result<MastNodeId, MastForestError>
Adds a basic block node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_join(
&mut self,
left_child: MastNodeId,
right_child: MastNodeId,
) -> Result<MastNodeId, MastForestError>
pub fn add_join( &mut self, left_child: MastNodeId, right_child: MastNodeId, ) -> Result<MastNodeId, MastForestError>
Adds a join node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_split(
&mut self,
if_branch: MastNodeId,
else_branch: MastNodeId,
) -> Result<MastNodeId, MastForestError>
pub fn add_split( &mut self, if_branch: MastNodeId, else_branch: MastNodeId, ) -> Result<MastNodeId, MastForestError>
Adds a split node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_loop(
&mut self,
body: MastNodeId,
) -> Result<MastNodeId, MastForestError>
pub fn add_loop( &mut self, body: MastNodeId, ) -> Result<MastNodeId, MastForestError>
Adds a loop node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_call(
&mut self,
callee: MastNodeId,
) -> Result<MastNodeId, MastForestError>
pub fn add_call( &mut self, callee: MastNodeId, ) -> Result<MastNodeId, MastForestError>
Adds a call node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_syscall(
&mut self,
callee: MastNodeId,
) -> Result<MastNodeId, MastForestError>
pub fn add_syscall( &mut self, callee: MastNodeId, ) -> Result<MastNodeId, MastForestError>
Adds a syscall node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_dyn(&mut self) -> Result<MastNodeId, MastForestError>
pub fn add_dyn(&mut self) -> Result<MastNodeId, MastForestError>
Adds a dyn node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_dyncall(&mut self) -> Result<MastNodeId, MastForestError>
pub fn add_dyncall(&mut self) -> Result<MastNodeId, MastForestError>
Adds a dyncall node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn add_external(
&mut self,
mast_root: RpoDigest,
) -> Result<MastNodeId, MastForestError>
pub fn add_external( &mut self, mast_root: RpoDigest, ) -> Result<MastNodeId, MastForestError>
Adds an external node to the forest, and returns the MastNodeId
associated with it.
Sourcepub fn make_root(&mut self, new_root_id: MastNodeId)
pub fn make_root(&mut self, new_root_id: MastNodeId)
Marks the given MastNodeId
as being the root of a procedure.
If the specified node is already marked as a root, this will have no effect.
§Panics
- if
new_root_id
’s internal index is larger than the number of nodes in this forest (i.e. clearly doesn’t belong to this MAST forest).
Sourcepub fn remove_nodes(
&mut self,
nodes_to_remove: &BTreeSet<MastNodeId>,
) -> BTreeMap<MastNodeId, MastNodeId>
pub fn remove_nodes( &mut self, nodes_to_remove: &BTreeSet<MastNodeId>, ) -> BTreeMap<MastNodeId, MastNodeId>
Removes all nodes in the provided set from the MAST forest. The nodes MUST be orphaned (i.e.
have no parent). Otherwise, this parent’s reference is considered “dangling” after the
removal (i.e. will point to an incorrect node after the removal), and this removal operation
would result in an invalid MastForest
.
It also returns the map from old node IDs to new node IDs. Any MastNodeId
used in
reference to the old MastForest
should be remapped using this map.
pub fn append_before_enter( &mut self, node_id: MastNodeId, decorator_ids: &[DecoratorId], )
pub fn append_after_exit( &mut self, node_id: MastNodeId, decorator_ids: &[DecoratorId], )
Sourcepub fn merge<'forest>(
forests: impl IntoIterator<Item = &'forest MastForest>,
) -> Result<(MastForest, MastForestRootMap), MastForestError>
pub fn merge<'forest>( forests: impl IntoIterator<Item = &'forest MastForest>, ) -> Result<(MastForest, MastForestRootMap), MastForestError>
Merges all forests
into a new MastForest
.
Merging two forests means combining all their constituent parts, i.e. MastNode
s,
Decorator
s and roots. During this process, any duplicate or
unreachable nodes are removed. Additionally, MastNodeId
s of nodes as well as
DecoratorId
s of decorators may change and references to them are remapped to their new
location.
For example, consider this representation of a forest’s nodes with all of these nodes being roots:
[Block(foo), Block(bar)]
If we merge another forest into it:
[Block(bar), Call(0)]
then we would expect this forest:
[Block(foo), Block(bar), Call(1)]
- The
Call
to thebar
block was remapped to its new index (now 1, previously 0). - The
Block(bar)
was deduplicated any only exists once in the merged forest.
The function also returns a vector of MastForestRootMap
s, whose length equals the number
of passed forests
. The indices in the vector correspond to the ones in forests
. The map
of a given forest contains the new locations of its roots in the merged forest. To
illustrate, the above example would return a vector of two maps:
vec![{0 -> 0, 1 -> 1}
{0 -> 1, 1 -> 2}]
- The root locations of the original forest are unchanged.
- For the second forest, the
bar
block has moved from index 0 to index 1 in the merged forest, and theCall
has moved from index 1 to 2.
If any forest being merged contains an External(qux)
node and another forest contains a
node whose digest is qux
, then the external node will be replaced with the qux
node,
which is effectively deduplication. Decorators are ignored when it comes to merging
External nodes. This means that an External node with decorators may be replaced by a node
without decorators or vice versa.
impl MastForest
Helpers
Source§impl MastForest
Public accessors
impl MastForest
Public accessors
Sourcepub fn get_decorator_by_id(
&self,
decorator_id: DecoratorId,
) -> Option<&Decorator>
pub fn get_decorator_by_id( &self, decorator_id: DecoratorId, ) -> Option<&Decorator>
Returns the Decorator
associated with the provided DecoratorId
if valid, or else
None
.
This is the fallible version of indexing (e.g. mast_forest[decorator_id]
).
Sourcepub fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
pub fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode>
Returns the MastNode
associated with the provided MastNodeId
if valid, or else
None
.
This is the fallible version of indexing (e.g. mast_forest[node_id]
).
Sourcepub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId>
pub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId>
Returns the MastNodeId
of the procedure associated with a given digest, if any.
Sourcepub fn is_procedure_root(&self, node_id: MastNodeId) -> bool
pub fn is_procedure_root(&self, node_id: MastNodeId) -> bool
Returns true if a node with the specified ID is a root of a procedure in this MAST forest.
Sourcepub fn procedure_digests(&self) -> impl Iterator<Item = RpoDigest>
pub fn procedure_digests(&self) -> impl Iterator<Item = RpoDigest>
Returns an iterator over the digests of all procedures in this MAST forest.
Sourcepub fn local_procedure_digests(&self) -> impl Iterator<Item = RpoDigest>
pub fn local_procedure_digests(&self) -> impl Iterator<Item = RpoDigest>
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.
Sourcepub fn procedure_roots(&self) -> &[MastNodeId]
pub fn procedure_roots(&self) -> &[MastNodeId]
Returns an iterator over the IDs of the procedures in this MAST forest.
Sourcepub fn num_procedures(&self) -> u32
pub fn num_procedures(&self) -> u32
Returns the number of procedures in this MAST forest.
pub fn decorators(&self) -> &[Decorator]
pub fn advice_map(&self) -> &AdviceMap
pub fn advice_map_mut(&mut self) -> &mut AdviceMap
Sourcepub fn register_error(&mut self, msg: Arc<str>) -> BaseElement
pub fn register_error(&mut self, msg: Arc<str>) -> BaseElement
Registers an error message in the MAST Forest and returns the corresponding error code as a Felt.
Sourcepub fn resolve_error_message(&self, code: BaseElement) -> Option<Arc<str>>
pub fn resolve_error_message(&self, code: BaseElement) -> Option<Arc<str>>
Given an error code as a Felt, resolves it to its corresponding error message.
Trait Implementations§
Source§impl Clone for MastForest
impl Clone for MastForest
Source§fn clone(&self) -> MastForest
fn clone(&self) -> MastForest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MastForest
impl Debug for MastForest
Source§impl Default for MastForest
impl Default for MastForest
Source§fn default() -> MastForest
fn default() -> MastForest
Source§impl Deserializable for MastForest
impl Deserializable for MastForest
Source§fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>where
R: ByteReader,
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl Index<DecoratorId> for MastForest
impl Index<DecoratorId> for MastForest
Source§fn index(
&self,
decorator_id: DecoratorId,
) -> &<MastForest as Index<DecoratorId>>::Output
fn index( &self, decorator_id: DecoratorId, ) -> &<MastForest as Index<DecoratorId>>::Output
container[index]
) operation. Read moreSource§impl Index<MastNodeId> for MastForest
impl Index<MastNodeId> for MastForest
Source§fn index(
&self,
node_id: MastNodeId,
) -> &<MastForest as Index<MastNodeId>>::Output
fn index( &self, node_id: MastNodeId, ) -> &<MastForest as Index<MastNodeId>>::Output
container[index]
) operation. Read moreSource§impl IndexMut<DecoratorId> for MastForest
impl IndexMut<DecoratorId> for MastForest
Source§fn index_mut(
&mut self,
decorator_id: DecoratorId,
) -> &mut <MastForest as Index<DecoratorId>>::Output
fn index_mut( &mut self, decorator_id: DecoratorId, ) -> &mut <MastForest as Index<DecoratorId>>::Output
container[index]
) operation. Read moreSource§impl IndexMut<MastNodeId> for MastForest
impl IndexMut<MastNodeId> for MastForest
Source§fn index_mut(
&mut self,
node_id: MastNodeId,
) -> &mut <MastForest as Index<MastNodeId>>::Output
fn index_mut( &mut self, node_id: MastNodeId, ) -> &mut <MastForest as Index<MastNodeId>>::Output
container[index]
) operation. Read moreSource§impl PartialEq for MastForest
impl PartialEq for MastForest
Source§impl Serializable for MastForest
impl Serializable for MastForest
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self
into bytes and writes these bytes into the target
.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Eq for MastForest
impl StructuralPartialEq for MastForest
Auto Trait Implementations§
impl Freeze for MastForest
impl RefUnwindSafe for MastForest
impl Send for MastForest
impl Sync for MastForest
impl Unpin for MastForest
impl UnwindSafe for MastForest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more