pub struct SsaFormingVisitor<'a> {
pub state: &'a mut CompilerState,
pub rename_table: RenameTable,
pub program: Symbol,
pub rename_defs: bool,
}
Fields§
§state: &'a mut CompilerState
§rename_table: RenameTable
The RenameTable
for the current basic block in the AST
program: Symbol
The main program name.
rename_defs: bool
Whether to rename places in definitions.
Implementations§
Source§impl SsaFormingVisitor<'_>
impl SsaFormingVisitor<'_>
Sourcepub fn consume_expression_and_define(
&mut self,
input: Expression,
) -> (Expression, Vec<Statement>)
pub fn consume_expression_and_define( &mut self, input: Expression, ) -> (Expression, Vec<Statement>)
Consume this expression and assign it to a variable (unless it’s already an Identifier).
Source§impl SsaFormingVisitor<'_>
impl SsaFormingVisitor<'_>
Sourcepub(crate) fn push(&mut self)
pub(crate) fn push(&mut self)
Pushes a new scope, setting the current scope as the new scope’s parent.
Sourcepub(crate) fn pop(&mut self) -> RenameTable
pub(crate) fn pop(&mut self) -> RenameTable
If the RenameTable has a parent, then self.rename_table
is set to the parent, otherwise it is set to a default RenameTable
.
pub(crate) fn rename_identifier(&mut self, identifier: Identifier) -> Identifier
pub(crate) fn simple_definition( &mut self, identifier: Identifier, rhs: Expression, ) -> Statement
Sourcepub(crate) fn unique_simple_definition(
&mut self,
expr: Expression,
) -> (Identifier, Statement)
pub(crate) fn unique_simple_definition( &mut self, expr: Expression, ) -> (Identifier, Statement)
Constructs a simple assign statement for expr
with a unique name.
For example, expr
is transformed into $var$0 = expr;
.
The lhs is guaranteed to be unique with respect to the Assigner
.
Trait Implementations§
Source§impl ExpressionConsumer for SsaFormingVisitor<'_>
impl ExpressionConsumer for SsaFormingVisitor<'_>
Source§fn consume_array(&mut self, input: ArrayExpression) -> Self::Output
fn consume_array(&mut self, input: ArrayExpression) -> Self::Output
Consumes an array expression, accumulating any statements that are generated.
Source§fn consume_binary(&mut self, input: BinaryExpression) -> Self::Output
fn consume_binary(&mut self, input: BinaryExpression) -> Self::Output
Consumes a binary expression, accumulating any statements that are generated.
Source§fn consume_call(&mut self, input: CallExpression) -> Self::Output
fn consume_call(&mut self, input: CallExpression) -> Self::Output
Consumes a call expression without visiting the function name, accumulating any statements that are generated.
Source§fn consume_cast(&mut self, input: CastExpression) -> Self::Output
fn consume_cast(&mut self, input: CastExpression) -> Self::Output
Consumes a cast expression, accumulating any statements that are generated.
Source§fn consume_struct_init(&mut self, input: StructExpression) -> Self::Output
fn consume_struct_init(&mut self, input: StructExpression) -> Self::Output
Consumes a struct initialization expression with renamed variables, accumulating any statements that are generated.
Source§fn consume_identifier(&mut self, identifier: Identifier) -> Self::Output
fn consume_identifier(&mut self, identifier: Identifier) -> Self::Output
Retrieve the new name for this Identifier
.
Note that this shouldn’t be used for Identifier
s on the lhs of definitions or
assignments.
Source§fn consume_literal(&mut self, input: Literal) -> Self::Output
fn consume_literal(&mut self, input: Literal) -> Self::Output
Consumes and returns the literal without making any modifications.
Source§fn consume_locator(&mut self, input: LocatorExpression) -> Self::Output
fn consume_locator(&mut self, input: LocatorExpression) -> Self::Output
Consumes and returns the locator expression without making any modifications
Source§fn consume_ternary(&mut self, input: TernaryExpression) -> Self::Output
fn consume_ternary(&mut self, input: TernaryExpression) -> Self::Output
Consumes a ternary expression, accumulating any statements that are generated.
Source§fn consume_tuple(&mut self, input: TupleExpression) -> Self::Output
fn consume_tuple(&mut self, input: TupleExpression) -> Self::Output
Consumes a tuple expression, accumulating any statements that are generated
Source§fn consume_unary(&mut self, input: UnaryExpression) -> Self::Output
fn consume_unary(&mut self, input: UnaryExpression) -> Self::Output
Consumes a unary expression, accumulating any statements that are generated.
type Output = (Expression, Vec<Statement>)
fn consume_array_access(&mut self, input: ArrayAccess) -> Self::Output
fn consume_member_access(&mut self, input: MemberAccess) -> Self::Output
fn consume_tuple_access(&mut self, input: TupleAccess) -> Self::Output
fn consume_repeat(&mut self, input: RepeatExpression) -> Self::Output
fn consume_unit(&mut self, input: UnitExpression) -> Self::Output
fn consume_associated_constant( &mut self, input: AssociatedConstantExpression, ) -> Self::Output
fn consume_associated_function( &mut self, input: AssociatedFunctionExpression, ) -> Self::Output
fn consume_expression(&mut self, input: Expression) -> Self::Output
fn consume_err(&mut self, _input: ErrExpression) -> Self::Output
Source§impl FunctionConsumer for SsaFormingVisitor<'_>
impl FunctionConsumer for SsaFormingVisitor<'_>
Source§impl ProgramConsumer for SsaFormingVisitor<'_>
impl ProgramConsumer for SsaFormingVisitor<'_>
Source§impl ProgramScopeConsumer for SsaFormingVisitor<'_>
impl ProgramScopeConsumer for SsaFormingVisitor<'_>
type Output = ProgramScope
fn consume_program_scope(&mut self, input: ProgramScope) -> Self::Output
Source§impl StatementConsumer for SsaFormingVisitor<'_>
impl StatementConsumer for SsaFormingVisitor<'_>
Source§fn consume_assert(&mut self, input: AssertStatement) -> Self::Output
fn consume_assert(&mut self, input: AssertStatement) -> Self::Output
Consumes the expressions in an AssertStatement
, returning the list of simplified statements.
Source§fn consume_assign(&mut self, assign: AssignStatement) -> Self::Output
fn consume_assign(&mut self, assign: AssignStatement) -> Self::Output
Consume all AssignStatement
s, renaming as necessary.
Source§fn consume_block(&mut self, block: Block) -> Self::Output
fn consume_block(&mut self, block: Block) -> Self::Output
Consumes a Block
, flattening its constituent ConditionalStatement
s.
Source§fn consume_conditional(
&mut self,
conditional: ConditionalStatement,
) -> Self::Output
fn consume_conditional( &mut self, conditional: ConditionalStatement, ) -> Self::Output
Consumes a ConditionalStatement
, producing phi functions (assign statements) for variables written in the then-block and otherwise-block.
For more information on phi functions, see https://en.wikipedia.org/wiki/Static_single_assignment_form.
Furthermore a new AssignStatement
is introduced for non-trivial expressions in the condition of ConditionalStatement
s.
For example,
if x > 0 { x = x + 1 }
becomeslet $cond$0 = x > 0; if $cond$0 { x = x + 1; }
if true { x = x + 1 }
remains the same.if b { x = x + 1 }
remains the same.
Source§fn consume_definition(
&mut self,
definition: DefinitionStatement,
) -> Self::Output
fn consume_definition( &mut self, definition: DefinitionStatement, ) -> Self::Output
Consumes the DefinitionStatement
into an AssignStatement
, renaming the left-hand-side as appropriate.
Source§fn consume_expression_statement(
&mut self,
input: ExpressionStatement,
) -> Self::Output
fn consume_expression_statement( &mut self, input: ExpressionStatement, ) -> Self::Output
Consumes the expressions associated with ExpressionStatement
, returning the simplified ExpressionStatement
.
Source§fn consume_return(&mut self, input: ReturnStatement) -> Self::Output
fn consume_return(&mut self, input: ReturnStatement) -> Self::Output
Reconstructs the expression associated with the return statement, returning a simplified ReturnStatement
.
Note that type checking guarantees that there is at most one ReturnStatement
in a block.
type Output = Vec<Statement>
fn consume_const(&mut self, _: ConstDeclaration) -> Self::Output
fn consume_iteration(&mut self, _input: IterationStatement) -> Self::Output
fn consume_statement(&mut self, input: Statement) -> Self::Output
Source§impl StructConsumer for SsaFormingVisitor<'_>
impl StructConsumer for SsaFormingVisitor<'_>
Auto Trait Implementations§
impl<'a> Freeze for SsaFormingVisitor<'a>
impl<'a> !RefUnwindSafe for SsaFormingVisitor<'a>
impl<'a> !Send for SsaFormingVisitor<'a>
impl<'a> !Sync for SsaFormingVisitor<'a>
impl<'a> Unpin for SsaFormingVisitor<'a>
impl<'a> !UnwindSafe for SsaFormingVisitor<'a>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more