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) -> ConstantPropagation<'a>
Trait Implementations§
Source§impl Pass for ConstantPropagation<'_>
impl Pass for ConstantPropagation<'_>
type Input<'a> = Program
type Output<'a> = Program
type Error = SemanticAnalysisError
Source§fn run<'a>(
&mut self,
program: <ConstantPropagation<'_> as Pass>::Input<'a>,
) -> Result<<ConstantPropagation<'_> as Pass>::Output<'a>, <ConstantPropagation<'_> as Pass>::Error>
fn run<'a>( &mut self, program: <ConstantPropagation<'_> as Pass>::Input<'a>, ) -> Result<<ConstantPropagation<'_> as Pass>::Output<'a>, <ConstantPropagation<'_> as Pass>::Error>
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
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);