pub struct ConstFoldingContext<'db, 'mt> {
pub variables: &'mt mut VariableArena<'db>,
/* private fields */
}Fields§
§variables: &'mt mut VariableArena<'db>The variables arena, mostly used to get the type of variables.
Implementations§
Source§impl<'db, 'mt> ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> ConstFoldingContext<'db, 'mt>
pub fn new( db: &'db dyn Database, function_id: ConcreteFunctionWithBodyId<'db>, variables: &'mt mut VariableArena<'db>, ) -> Self
Sourcepub fn visit_block_start<'r, 'get>(
&'r mut self,
block_id: BlockId,
get_block: impl FnOnce(BlockId) -> &'get Block<'db>,
) -> boolwhere
'db: 'get,
pub fn visit_block_start<'r, 'get>(
&'r mut self,
block_id: BlockId,
get_block: impl FnOnce(BlockId) -> &'get Block<'db>,
) -> boolwhere
'db: 'get,
Determines if a block is reachable from the function start and propagates constant values when the block is reachable via a single goto statement.
Sourcepub fn visit_statement(&mut self, stmt: &mut Statement<'db>)
pub fn visit_statement(&mut self, stmt: &mut Statement<'db>)
Processes a statement and applies the constant folding optimizations.
This method performs the following operations:
- Updates the
var_infomap with constant values of variables - Replace the input statement with optimized versions when possible
- Updates
self.additional_stmtswith statements that need to be added to the block.
Note: self.visit_block_end must be called after processing all statements
in a block to actually add the additional statements.
Sourcepub fn visit_block_end(&mut self, block_id: BlockId, block: &mut Block<'db>)
pub fn visit_block_end(&mut self, block_id: BlockId, block: &mut Block<'db>)
Processes the block’s end and incorporates additional statements into the block.
This method handles the following tasks:
- Inserts the accumulated additional statements into the block.
- Converts match endings to goto when applicable.
- Updates self.reachability based on the block’s ending.
Sourcepub fn should_skip_const_folding(&self, db: &'db dyn Database) -> bool
pub fn should_skip_const_folding(&self, db: &'db dyn Database) -> bool
Returns true if const-folding should be skipped for the current function.
Trait Implementations§
Source§impl<'db> Deref for ConstFoldingContext<'db, '_>
impl<'db> Deref for ConstFoldingContext<'db, '_>
Source§type Target = ConstFoldingLibfuncInfo<'db>
type Target = ConstFoldingLibfuncInfo<'db>
The resulting type after dereferencing.
Source§fn deref(&self) -> &ConstFoldingLibfuncInfo<'db>
fn deref(&self) -> &ConstFoldingLibfuncInfo<'db>
Dereferences the value.
Auto Trait Implementations§
impl<'db, 'mt> Freeze for ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> !RefUnwindSafe for ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> !Send for ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> !Sync for ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> Unpin for ConstFoldingContext<'db, 'mt>
impl<'db, 'mt> !UnwindSafe for ConstFoldingContext<'db, 'mt>
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<'db, T> DebugDbUpcast<'db, T> for Twhere
T: ?Sized,
impl<'db, T> DebugDbUpcast<'db, T> for Twhere
T: ?Sized,
fn debug_db_upcast(&'db self) -> &'db T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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