Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub node_id_pool: ListPool<AnyNode>,
    pub region_id_pool: ListPool<Region>,
    pub region: Region,
    /* private fields */
}
Expand description

The context for a whole translation unit and the core struct of this crate.

Fields§

§node_id_pool: ListPool<AnyNode>§region_id_pool: ListPool<Region>§region: Region

Implementations§

Source§

impl Context

Source

pub fn visit_nodes_upwards<T, F>( &self, user: impl Into<User>, f: &mut F, ) -> Option<T>
where F: FnMut(&Self, AnyNode) -> Option<T>,

Traverse nodes from user invoking f for each node user directly or indirectly depends on.

Source§

impl Context

Source

pub fn input_as_result<N: InputOutForwarding>(&self, input: Input<N>) -> Result

Retrieve the Result that will be mapped to the given input.

Available for DoWhile (theta Θ) nodes.

Source

pub fn input_as_output(&self, input: Input<DoWhile>) -> Output<DoWhile>

Since DoWhile (theta Θ) nodes must have at least outputs and results that match the nodes inputs, its possible to retrieve an corresponding Output node from an Input.

Source

pub fn output_as_input(&self, output: Output<DoWhile>) -> Input<DoWhile>

Since DoWhile (theta Θ) nodes must have at least outputs and results that match the nodes inputs, its possible to retrieve an corresponding Input node from an Output.

Source

pub fn try_argument_as_input( &self, argument: Argument, ) -> Option<Input<AnyNode>>

Retrieve the input that maps to argument.

Returns None if this argument is not mapped to an input, such as for Translation Unit (Omega ω) or lambda function parameter arguments.

Source

pub fn input_as_argument<N>(&self, region: Region, input: Input<N>) -> Argument

Get the argument in region that maps to the given input

For Lambda nodes, this will be offset by the amount of function parameter arguments. For Switch nodes, this will be offset by 1 as the predicate is not forwarded as an argument to the regions.

PANICS: If region must be direct child of the input node.

Source

pub fn try_input_as_argument<N>( &self, region: Region, input: Input<N>, ) -> Option<Argument>

Get the argument in region that maps to the given input

Returns None if this input isn’t mapped to any argument (such as Switch node predicate)

Source

pub fn result_as_output<K: ResultOutputForwarding>( &self, result: Result, ) -> Output<K>

Source

pub fn output_as_result<K: ResultOutputForwarding>( &self, region: Region, output: Output<K>, ) -> Result

Source§

impl Context

Source

pub fn to_xml(&self) -> String

Source§

impl Context

Source

pub fn new(unit_symbol: impl Into<String>) -> Self

Initialize a new RVSDG translation unit.

Sets the current region to the region of an implicitly declared TranslationUnit (omega ω) node.

Source

pub fn in_region<T>( &mut self, region: Region, f: impl FnOnce(&mut Self) -> T, ) -> T

Perform f while Context::region is set to region.

Source

pub fn regions(&self, node: AnyNode) -> EntityIter<Region>

Returns an non-borrowing iterator over regions of node.

Use EntityIter::next with Context::region_id_pool as parameter to progress.

Source

pub fn inputs( &self, node_id: AnyNode, ) -> impl Iterator<Item = Input<AnyNode>> + 'static

Source

pub fn outputs( &self, node_id: AnyNode, ) -> impl Iterator<Item = Output<AnyNode>> + 'static

Source

pub fn arguments( &self, region: Region, ) -> impl Iterator<Item = Argument> + 'static

Source

pub fn results(&self, region: Region) -> impl Iterator<Item = Result> + 'static

Source

pub fn nodes(&self, region: Region) -> impl Iterator<Item = AnyNode>

Returns an iterator of all nodes that are direct children of region.

Source

pub fn add_node<F, K: NodeKind>(&mut self, init: F) -> Node<K>
where F: FnOnce(&mut Self, Node<K>) -> K,

Create a new empty node of any kind and manually initialize it with init

WARNING: Only use this for constructing your own custom nodes. The nodes defined in crate::nodes must be created by their corresponding add_ prefixed methods.

See:

Source

pub fn add_symbol(&mut self, node: AnyNode, sym: impl Into<String>)

Source

pub unsafe fn add_region( &mut self, container: AnyNode, arguments: u32, results: u32, ) -> Region

§Safety

This function allows you to violate the rules of the RVSDG. To create regions safely, use the safe functions such as Context::add_switch_branch

Source

pub fn only_child_region(&self, node: AnyNode) -> Region

Get the only singular region. Panics if there’s not exactly one region

Source

pub fn parent_region(&self, node: AnyNode) -> Option<Region>

Source

pub fn node_hooks_mut(&mut self, node: AnyNode, f: impl FnMut(&mut NodeHooks))

Source

pub fn add_binop_node<N: BinOpKind>(&mut self) -> ([Input<N>; 2], Output<N>)

Create a BinOpKind simple node.

BinOpKind nodes have two inputs, and one output.

Source

pub fn add_lambda_node(&mut self) -> (Output<Lambda>, Region)

Create a lambda node.

Lambda nodes have a singular region. Lambda nodes have a singular output, representing itself. Lambda nodes may have arguments manually declared in their region as long as no inputs have been added.

Source

pub fn add_switch_branch(&mut self, node: Node<Switch>) -> (Region, usize)

Create a new region in node which will correspond to the next number.

Source

pub fn add_globalv_node(&mut self) -> (Result, Output<GlobalV>)

Source

pub fn add_dowhile_node(&mut self) -> (Result, Node<DoWhile>)

Source

pub fn add_recenv_node(&mut self) -> Node<RecEnv>

Source

pub fn add_switch_node(&mut self) -> (Input<Switch>, Node<Switch>)

Create a switch (gamma) node.

Switch nodes first input is a predicate which determines which region is under evaluation. Switch node regions have the same amount of results as the node has outputs. Switch node region results are mapped to switch node outputs.

See Context::add_switch_branch

Source

pub fn add_number_node(&mut self, n: i128) -> Output<Number>

Source

pub fn add_apply_node(&mut self) -> Input<Apply>

Source

pub fn add_and_connect_apply_node<const N: usize>( &mut self, f: impl Into<Origin>, params: &[impl Into<Origin> + Clone], ) -> [Output<Apply>; N]

Source

pub fn add_placeholder_node<const N: usize, const ON: usize>( &mut self, name: &'static str, inputs: [Origin; N], ) -> [Output<Placeholder>; ON]

Source

pub fn add_input<K>(&mut self, node: Node<K>) -> Input<K>

Source

pub fn add_output<K>(&mut self, node: Node<K>) -> Output<K>

Source

pub fn add_argument(&mut self) -> Argument

Source

pub fn add_result(&mut self) -> Result

Source

pub fn connect(&mut self, origin: impl Into<Origin>, user: impl Into<User>)

Connect origin to user, and use pathfinding in case they’re of different regions to automatically form the connections needed to make origin available to user.

If both the origin and user ports attach to lambdas in the same region, then connect may move the lambdas into a node RecEnv (phi ϕ) node - re-arranging all connections to those lambdas as-needed.

Source

pub fn get_user(&self, user: impl Into<User>) -> Option<Origin>

Retrieve the Origin directly attached to the port user.

§Arguments
Source

pub fn try_connect( &mut self, origin: impl Into<Origin>, user: impl Into<User>, ) -> Connection

Same as Context::connect except returns Connection result instead of panicing.

Source

pub fn downcast<K: NodeKind>(&self, node_id: AnyNode) -> Option<Node<K>>

Returns the statically typed version of a node if it downcasts to K.

Source

pub unsafe fn connect_same_region(&mut self, origin: Origin, user: User)

Connects origin to user

§Safety

Does not check for cycles or recenv-transformations, which can lead to violation of RVSDG rules.

§Panics

If origin and user ports aren’t in the same region.

Source

pub fn for_each_edge<F>(&mut self, node: AnyNode, f: F)
where F: FnMut(Origin, User),

Calls f for each connection to inputs and outputs of node.

Source

pub fn open_rvsdg_viewer(&mut self)

Launches rvsdg-viewer to visualize the current RVSDG.

NOTE: Only works on valid RVSDG’s.

Source

pub fn dump_region_mapping(&mut self)

Prints which regions belong to which nodes.

Trait Implementations§

Source§

impl Debug for Context

Source§

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

Formats the value using the given formatter. Read more

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