ConstantPropagation

Struct ConstantPropagation 

Source
pub struct ConstantPropagation<'a> { /* private fields */ }
Expand description

This pass performs constant propagation on a Program, replacing all uses of a constant with the constant itself, converting accesses into constant aggregates with the accessed value, replacing local variables bound to constants with the constant value, and folding constant expressions into constant values.

It is expected that the provided Program has already been run through semantic analysis, so it will panic if it encounters invalid constructions to help catch bugs in the semantic analysis pass, should they exist.

Implementations§

Source§

impl<'a> ConstantPropagation<'a>

Source

pub fn new(diagnostics: &'a DiagnosticsHandler) -> Self

Trait Implementations§

Source§

impl Pass for ConstantPropagation<'_>

Source§

type Input<'a> = Program

Source§

type Output<'a> = Program

Source§

type Error = SemanticAnalysisError

Source§

fn run<'a>( &mut self, program: Self::Input<'a>, ) -> Result<Self::Output<'a>, Self::Error>

Runs the pass on the given input Read more
Source§

fn chain<P, E>(self, pass: P) -> Chain<Self, P>
where Self: Sized, E: From<Self::Error>, P: for<'a> Pass<Input<'a> = Self::Output<'a>, Error = E>,

Chains two passes together to form a new, fused pass
Source§

impl VisitMut<SemanticAnalysisError> for ConstantPropagation<'_>

Source§

fn visit_mut_scalar_expr( &mut self, expr: &mut ScalarExpr, ) -> ControlFlow<SemanticAnalysisError>

Fold constant expressions

Source§

fn visit_mut_statement( &mut self, _: &mut Statement, ) -> ControlFlow<SemanticAnalysisError>

It should not be possible to reach this, as we handle statements at the block level

Source§

fn visit_mut_expr( &mut self, expr: &mut Expr, ) -> ControlFlow<SemanticAnalysisError>

Source§

fn visit_mut_statement_block( &mut self, statements: &mut Vec<Statement>, ) -> ControlFlow<SemanticAnalysisError>

Source§

fn visit_mut_module(&mut self, module: &mut Module) -> ControlFlow<T>

Source§

fn visit_mut_import(&mut self, expr: &mut Import) -> ControlFlow<T>

Source§

fn visit_mut_constant(&mut self, expr: &mut Constant) -> ControlFlow<T>

Source§

fn visit_mut_evaluator_function( &mut self, expr: &mut EvaluatorFunction, ) -> ControlFlow<T>

Source§

fn visit_mut_function(&mut self, expr: &mut Function) -> ControlFlow<T>

Source§

fn visit_mut_bus(&mut self, expr: &mut Bus) -> ControlFlow<T>

Source§

fn visit_mut_periodic_column( &mut self, expr: &mut PeriodicColumn, ) -> ControlFlow<T>

Source§

fn visit_mut_public_input(&mut self, expr: &mut PublicInput) -> ControlFlow<T>

Source§

fn visit_mut_trace_segment(&mut self, expr: &mut TraceSegment) -> ControlFlow<T>

Source§

fn visit_mut_trace_binding(&mut self, expr: &mut TraceBinding) -> ControlFlow<T>

Source§

fn visit_mut_evaluator_trace_segment( &mut self, expr: &mut TraceSegment, ) -> ControlFlow<T>

Source§

fn visit_mut_evaluator_trace_binding( &mut self, expr: &mut TraceBinding, ) -> ControlFlow<T>

Source§

fn visit_mut_let(&mut self, expr: &mut Let) -> ControlFlow<T>

Source§

fn visit_mut_boundary_constraints( &mut self, exprs: &mut Vec<Statement>, ) -> ControlFlow<T>

Source§

fn visit_mut_enforce(&mut self, expr: &mut ScalarExpr) -> ControlFlow<T>

Source§

fn visit_mut_enforce_if( &mut self, expr: &mut ScalarExpr, selector: &mut ScalarExpr, ) -> ControlFlow<T>

Source§

fn visit_mut_enforce_all( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>

Source§

fn visit_mut_bus_enforce( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>

Source§

fn visit_mut_integrity_constraints( &mut self, exprs: &mut Vec<Statement>, ) -> ControlFlow<T>

Source§

fn visit_mut_binary_expr(&mut self, expr: &mut BinaryExpr) -> ControlFlow<T>

Source§

fn visit_mut_list_comprehension( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>

Source§

fn visit_mut_call(&mut self, expr: &mut Call) -> ControlFlow<T>

Source§

fn visit_mut_bus_operation(&mut self, expr: &mut BusOperation) -> ControlFlow<T>

Source§

fn visit_mut_range_bound(&mut self, expr: &mut RangeBound) -> ControlFlow<T>

Source§

fn visit_mut_access_type(&mut self, expr: &mut AccessType) -> ControlFlow<T>

Source§

fn visit_mut_const_symbol_access( &mut self, expr: &mut ConstSymbolAccess, ) -> ControlFlow<T>

Source§

fn visit_mut_bounded_symbol_access( &mut self, expr: &mut BoundedSymbolAccess, ) -> ControlFlow<T>

Source§

fn visit_mut_symbol_access(&mut self, expr: &mut SymbolAccess) -> ControlFlow<T>

Source§

fn visit_mut_resolvable_identifier( &mut self, expr: &mut ResolvableIdentifier, ) -> ControlFlow<T>

Source§

fn visit_mut_identifier(&mut self, expr: &mut Identifier) -> ControlFlow<T>

Source§

fn visit_mut_typed_identifier( &mut self, expr: &mut (Identifier, Type), ) -> ControlFlow<T>

Auto Trait Implementations§

§

impl<'a> Freeze for ConstantPropagation<'a>

§

impl<'a> !RefUnwindSafe for ConstantPropagation<'a>

§

impl<'a> !Send for ConstantPropagation<'a>

§

impl<'a> !Sync for ConstantPropagation<'a>

§

impl<'a> Unpin for ConstantPropagation<'a>

§

impl<'a> !UnwindSafe for ConstantPropagation<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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