Cfg

Struct Cfg 

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

A cfg of CFG nodes acting as a context for a single compilation unit.

Implementations§

Source§

impl Cfg

Source

pub fn new() -> Self

Construct an empty control flow graph.

Source

pub fn insert(&mut self, node: CfgNode) -> Index

Insert a constructed CfgNode into the CFG, and get back its newly minted index.

Source

pub fn insert_error_at(&mut self, node: Index, kind: CompileError)

Insert an Error node as a shim.

Source

pub fn create_error(&mut self, kind: CompileError, span: Span) -> Index

Create a dummy Error node, as a stand-in for a node which should have been generated but for some reason cannot be.

Source

pub fn singleton(&mut self, expr: Ir) -> Index

Create a new node containing only this expression with no next-node link.

Source

pub fn spanned(&mut self, expr: Ir, span: Span) -> Index

Create a new node w/ an assigned span containing only this expression with no next-node link.

Source

pub fn resolve_scopes(&mut self, node: Option<Index>)

The purpose of the scope resolution pass is to transform “implicit” continuations into “explicit” continuations. For example, consider the session type choose { ... }; send (). In this type, the first parsing of the block will result in a Choose node with its continuation/“next” pointer set to point to a Send(()) node. However, in order to ensure that the arms of the choose construct don’t have to worry about the continuation that comes “after” in a higher/parent scope, we have the resolve_scopes pass to “lower” this continuation which implicitly follows every arm of the Choose, into becoming the continuation of every relevant arm of the Choose. This does have some special cases, for example we don’t want to change or set a next continuation for a Break node or Continue node.

Source

pub fn report_dead_code(&mut self, node: Option<Index>)

Attach errors to all dead code and code that leads to dead code, based on an internal call to the flow analysis and reachability analysis on the graph.

Source

pub fn generate_target( &mut self, node: Option<Index>, ) -> Result<Spanned<Target>, Error>

Traverse a Cfg rooted at the specified index to produce either a valid Target corresponding to it, or a syn::Error corresponding to one or more compiler errors.

Important: This function must be called after the scope resolution pass, or else the resultant code may omit sections of the input control flow graph due to implicit continuations which have not yet been resolved.

Source

pub fn iter(&self) -> impl Iterator<Item = (Index, &CfgNode)> + '_

Iterate over all nodes in the CFG. The order is not defined.

Trait Implementations§

Source§

impl Debug for Cfg

Source§

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

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

impl Default for Cfg

Source§

fn default() -> Self

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

impl Index<Index> for Cfg

Source§

type Output = CfgNode

The returned type after indexing.
Source§

fn index(&self, index: Index) -> &Self::Output

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

impl IndexMut<Index> for Cfg

Source§

fn index_mut(&mut self, index: Index) -> &mut Self::Output

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

Auto Trait Implementations§

§

impl Freeze for Cfg

§

impl RefUnwindSafe for Cfg

§

impl !Send for Cfg

§

impl !Sync for Cfg

§

impl Unpin for Cfg

§

impl UnwindSafe for Cfg

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