Struct MastForest

Source
pub struct MastForest { /* private fields */ }
Expand description

Represents one or more procedures, represented as a collection of MastNodes.

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

Source

pub fn new() -> MastForest

Creates a new empty MastForest.

Source§

impl MastForest

State mutators

Source

pub fn add_decorator( &mut self, decorator: Decorator, ) -> Result<DecoratorId, MastForestError>

Adds a decorator to the forest, and returns the associated DecoratorId.

Source

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 MastNodeIds.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn add_dyn(&mut self) -> Result<MastNodeId, MastForestError>

Adds a dyn node to the forest, and returns the MastNodeId associated with it.

Source

pub fn add_dyncall(&mut self) -> Result<MastNodeId, MastForestError>

Adds a dyncall node to the forest, and returns the MastNodeId associated with it.

Source

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.

Source

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).
Source

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.

Source

pub fn append_before_enter( &mut self, node_id: MastNodeId, decorator_ids: &[DecoratorId], )

Source

pub fn append_after_exit( &mut self, node_id: MastNodeId, decorator_ids: &[DecoratorId], )

Source

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. MastNodes, Decorators and roots. During this process, any duplicate or unreachable nodes are removed. Additionally, MastNodeIds of nodes as well as DecoratorIds 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 the bar 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 MastForestRootMaps, 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 the Call 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.

Source§

impl MastForest

This impl block contains no items.

Helpers

Source§

impl MastForest

Public accessors

Source

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]).

Source

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]).

Source

pub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId>

Returns the MastNodeId of the procedure associated with a given digest, if any.

Source

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.

Source

pub fn procedure_digests(&self) -> impl Iterator<Item = RpoDigest>

Returns an iterator over the digests of all procedures in this MAST forest.

Source

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.

Source

pub fn procedure_roots(&self) -> &[MastNodeId]

Returns an iterator over the IDs of the procedures in this MAST forest.

Source

pub fn num_procedures(&self) -> u32

Returns the number of procedures in this MAST forest.

Source

pub fn num_nodes(&self) -> u32

Returns the number of nodes in this MAST forest.

Source

pub fn nodes(&self) -> &[MastNode]

Returns the underlying nodes in this MAST forest.

Source

pub fn decorators(&self) -> &[Decorator]

Source

pub fn advice_map(&self) -> &AdviceMap

Source

pub fn advice_map_mut(&mut self) -> &mut AdviceMap

Source

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.

Source

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

Source§

fn clone(&self) -> MastForest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MastForest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for MastForest

Source§

fn default() -> MastForest

Returns the “default value” for a type. Read more
Source§

impl Deserializable for MastForest

Source§

fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
Source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
Source§

impl Index<DecoratorId> for MastForest

Source§

type Output = Decorator

The returned type after indexing.
Source§

fn index( &self, decorator_id: DecoratorId, ) -> &<MastForest as Index<DecoratorId>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<MastNodeId> for MastForest

Source§

type Output = MastNode

The returned type after indexing.
Source§

fn index( &self, node_id: MastNodeId, ) -> &<MastForest as Index<MastNodeId>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<DecoratorId> for MastForest

Source§

fn index_mut( &mut self, decorator_id: DecoratorId, ) -> &mut <MastForest as Index<DecoratorId>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<MastNodeId> for MastForest

Source§

fn index_mut( &mut self, node_id: MastNodeId, ) -> &mut <MastForest as Index<MastNodeId>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for MastForest

Source§

fn eq(&self, other: &MastForest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serializable for MastForest

Source§

fn write_into<W>(&self, target: &mut W)
where W: ByteWriter,

Serializes self into bytes and writes these bytes into the target.
Source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
Source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

impl Eq for MastForest

Source§

impl StructuralPartialEq for MastForest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more