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>
impl<'a> ConstantPropagation<'a>
pub fn new(diagnostics: &'a DiagnosticsHandler) -> Self
Trait Implementations§
Source§impl Pass for ConstantPropagation<'_>
impl Pass for ConstantPropagation<'_>
Source§impl VisitMut<SemanticAnalysisError> for ConstantPropagation<'_>
impl VisitMut<SemanticAnalysisError> for ConstantPropagation<'_>
Source§fn visit_mut_scalar_expr(
&mut self,
expr: &mut ScalarExpr,
) -> ControlFlow<SemanticAnalysisError>
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>
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
fn visit_mut_expr( &mut self, expr: &mut Expr, ) -> ControlFlow<SemanticAnalysisError>
fn visit_mut_statement_block( &mut self, statements: &mut Vec<Statement>, ) -> ControlFlow<SemanticAnalysisError>
fn visit_mut_module(&mut self, module: &mut Module) -> ControlFlow<T>
fn visit_mut_import(&mut self, expr: &mut Import) -> ControlFlow<T>
fn visit_mut_constant(&mut self, expr: &mut Constant) -> ControlFlow<T>
fn visit_mut_evaluator_function( &mut self, expr: &mut EvaluatorFunction, ) -> ControlFlow<T>
fn visit_mut_function(&mut self, expr: &mut Function) -> ControlFlow<T>
fn visit_mut_bus(&mut self, expr: &mut Bus) -> ControlFlow<T>
fn visit_mut_periodic_column( &mut self, expr: &mut PeriodicColumn, ) -> ControlFlow<T>
fn visit_mut_public_input(&mut self, expr: &mut PublicInput) -> ControlFlow<T>
fn visit_mut_trace_segment(&mut self, expr: &mut TraceSegment) -> ControlFlow<T>
fn visit_mut_trace_binding(&mut self, expr: &mut TraceBinding) -> ControlFlow<T>
fn visit_mut_evaluator_trace_segment( &mut self, expr: &mut TraceSegment, ) -> ControlFlow<T>
fn visit_mut_evaluator_trace_binding( &mut self, expr: &mut TraceBinding, ) -> ControlFlow<T>
fn visit_mut_let(&mut self, expr: &mut Let) -> ControlFlow<T>
fn visit_mut_boundary_constraints( &mut self, exprs: &mut Vec<Statement>, ) -> ControlFlow<T>
fn visit_mut_enforce(&mut self, expr: &mut ScalarExpr) -> ControlFlow<T>
fn visit_mut_enforce_if( &mut self, expr: &mut ScalarExpr, selector: &mut ScalarExpr, ) -> ControlFlow<T>
fn visit_mut_enforce_all( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>
fn visit_mut_bus_enforce( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>
fn visit_mut_integrity_constraints( &mut self, exprs: &mut Vec<Statement>, ) -> ControlFlow<T>
fn visit_mut_binary_expr(&mut self, expr: &mut BinaryExpr) -> ControlFlow<T>
fn visit_mut_list_comprehension( &mut self, expr: &mut ListComprehension, ) -> ControlFlow<T>
fn visit_mut_call(&mut self, expr: &mut Call) -> ControlFlow<T>
fn visit_mut_bus_operation(&mut self, expr: &mut BusOperation) -> ControlFlow<T>
fn visit_mut_range_bound(&mut self, expr: &mut RangeBound) -> ControlFlow<T>
fn visit_mut_access_type(&mut self, expr: &mut AccessType) -> ControlFlow<T>
fn visit_mut_const_symbol_access( &mut self, expr: &mut ConstSymbolAccess, ) -> ControlFlow<T>
fn visit_mut_bounded_symbol_access( &mut self, expr: &mut BoundedSymbolAccess, ) -> ControlFlow<T>
fn visit_mut_symbol_access(&mut self, expr: &mut SymbolAccess) -> ControlFlow<T>
fn visit_mut_resolvable_identifier( &mut self, expr: &mut ResolvableIdentifier, ) -> ControlFlow<T>
fn visit_mut_identifier(&mut self, expr: &mut Identifier) -> ControlFlow<T>
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> 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
Mutably borrows from an owned value. Read more
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>
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 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>
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