Struct chalk_ir::fold::shift::DownShifter
source · struct DownShifter<I> {
target_binder: DebruijnIndex,
interner: I,
}
Expand description
A shifter that reduces debruijn indices – in other words, which lifts a value out from binders. Consider this example:
Fields§
§target_binder: DebruijnIndex
§interner: I
Implementations§
source§impl<I> DownShifter<I>
impl<I> DownShifter<I>
sourcefn adjust(
&self,
bound_var: BoundVar,
outer_binder: DebruijnIndex,
) -> Fallible<BoundVar>
fn adjust( &self, bound_var: BoundVar, outer_binder: DebruijnIndex, ) -> Fallible<BoundVar>
Given a reference to a free variable at depth depth
(appearing within binders
internal binders), attempts to
lift that free variable out from adjustment
levels of
binders (i.e., convert it to depth depth - self.adjustment
). If the free variable is bound by one of
those internal binders (i.e., depth < self.adjustment
) the
this will fail with Err
. Otherwise, returns the variable at
this new depth (but adjusted to appear within binders
).
Trait Implementations§
source§impl<I: Interner> FallibleTypeFolder<I> for DownShifter<I>
impl<I: Interner> FallibleTypeFolder<I> for DownShifter<I>
§type Error = NoSolution
type Error = NoSolution
The type this folder returns when folding fails. This is
commonly
NoSolution
.source§fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error>
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error>
Creates a
dyn
value from this folder. Unfortunately, this
must be added manually to each impl of FallibleTypeFolder; it
permits the default implements below to create a
&mut dyn FallibleTypeFolder
from Self
without knowing what
Self
is (by invoking this method). Effectively, this limits
impls of FallibleTypeFolder
to types for which we are able to
create a dyn value (i.e., not [T]
types).source§fn try_fold_free_var_ty(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex,
) -> Fallible<Ty<I>>
fn try_fold_free_var_ty( &mut self, bound_var: BoundVar, outer_binder: DebruijnIndex, ) -> Fallible<Ty<I>>
Invoked for
TyKind::BoundVar
instances that are not bound
within the type being folded over: Read moresource§fn try_fold_free_var_lifetime(
&mut self,
bound_var: BoundVar,
outer_binder: DebruijnIndex,
) -> Fallible<Lifetime<I>>
fn try_fold_free_var_lifetime( &mut self, bound_var: BoundVar, outer_binder: DebruijnIndex, ) -> Fallible<Lifetime<I>>
As
try_fold_free_var_ty
, but for lifetimes.source§fn try_fold_free_var_const(
&mut self,
ty: Ty<I>,
bound_var: BoundVar,
outer_binder: DebruijnIndex,
) -> Fallible<Const<I>>
fn try_fold_free_var_const( &mut self, ty: Ty<I>, bound_var: BoundVar, outer_binder: DebruijnIndex, ) -> Fallible<Const<I>>
As
try_fold_free_var_ty
, but for constants.source§fn try_fold_ty(
&mut self,
ty: Ty<I>,
outer_binder: DebruijnIndex,
) -> Result<Ty<I>, Self::Error>
fn try_fold_ty( &mut self, ty: Ty<I>, outer_binder: DebruijnIndex, ) -> Result<Ty<I>, Self::Error>
Top-level callback: invoked for each
Ty<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_ty
.source§fn try_fold_lifetime(
&mut self,
lifetime: Lifetime<I>,
outer_binder: DebruijnIndex,
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_lifetime( &mut self, lifetime: Lifetime<I>, outer_binder: DebruijnIndex, ) -> Result<Lifetime<I>, Self::Error>
Top-level callback: invoked for each
Lifetime<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_lifetime
.source§fn try_fold_const(
&mut self,
constant: Const<I>,
outer_binder: DebruijnIndex,
) -> Result<Const<I>, Self::Error>
fn try_fold_const( &mut self, constant: Const<I>, outer_binder: DebruijnIndex, ) -> Result<Const<I>, Self::Error>
Top-level callback: invoked for each
Const<I>
that is
encountered when folding. By default, invokes
try_super_fold_with
, which will in turn invoke the more
specialized folding methods below, like try_fold_free_var_const
.source§fn try_fold_program_clause(
&mut self,
clause: ProgramClause<I>,
outer_binder: DebruijnIndex,
) -> Result<ProgramClause<I>, Self::Error>
fn try_fold_program_clause( &mut self, clause: ProgramClause<I>, outer_binder: DebruijnIndex, ) -> Result<ProgramClause<I>, Self::Error>
Invoked for every program clause. By default, recursively folds the goals contents.
source§fn try_fold_goal(
&mut self,
goal: Goal<I>,
outer_binder: DebruijnIndex,
) -> Result<Goal<I>, Self::Error>
fn try_fold_goal( &mut self, goal: Goal<I>, outer_binder: DebruijnIndex, ) -> Result<Goal<I>, Self::Error>
Invoked for every goal. By default, recursively folds the goals contents.
source§fn forbid_free_vars(&self) -> bool
fn forbid_free_vars(&self) -> bool
If overridden to return true, then folding will panic if a
free variable is encountered. This should be done if free
type/lifetime variables are not expected.
source§fn forbid_free_placeholders(&self) -> bool
fn forbid_free_placeholders(&self) -> bool
If overridden to return true, we will panic when a free
placeholder type/lifetime/const is encountered.
source§fn try_fold_free_placeholder_ty(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex,
) -> Result<Ty<I>, Self::Error>
fn try_fold_free_placeholder_ty( &mut self, universe: PlaceholderIndex, outer_binder: DebruijnIndex, ) -> Result<Ty<I>, Self::Error>
Invoked for each occurrence of a placeholder type; these are
used when we instantiate binders universally. Returns a type
to use instead, which should be suitably shifted to account
for
binders
. Read moresource§fn try_fold_free_placeholder_lifetime(
&mut self,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex,
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_free_placeholder_lifetime( &mut self, universe: PlaceholderIndex, outer_binder: DebruijnIndex, ) -> Result<Lifetime<I>, Self::Error>
As with
try_fold_free_placeholder_ty
, but for lifetimes.source§fn try_fold_free_placeholder_const(
&mut self,
ty: Ty<I>,
universe: PlaceholderIndex,
outer_binder: DebruijnIndex,
) -> Result<Const<I>, Self::Error>
fn try_fold_free_placeholder_const( &mut self, ty: Ty<I>, universe: PlaceholderIndex, outer_binder: DebruijnIndex, ) -> Result<Const<I>, Self::Error>
As with
try_fold_free_placeholder_ty
, but for constants.source§fn forbid_inference_vars(&self) -> bool
fn forbid_inference_vars(&self) -> bool
If overridden to return true, inference variables will trigger
panics when folded. Used when inference variables are
unexpected.
source§fn try_fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex,
) -> Result<Ty<I>, Self::Error>
fn try_fold_inference_ty( &mut self, var: InferenceVar, kind: TyVariableKind, outer_binder: DebruijnIndex, ) -> Result<Ty<I>, Self::Error>
Invoked for each occurrence of a inference type; these are
used when we instantiate binders universally. Returns a type
to use instead, which should be suitably shifted to account
for
binders
. Read moresource§fn try_fold_inference_lifetime(
&mut self,
var: InferenceVar,
outer_binder: DebruijnIndex,
) -> Result<Lifetime<I>, Self::Error>
fn try_fold_inference_lifetime( &mut self, var: InferenceVar, outer_binder: DebruijnIndex, ) -> Result<Lifetime<I>, Self::Error>
As with
try_fold_inference_ty
, but for lifetimes.source§fn try_fold_inference_const(
&mut self,
ty: Ty<I>,
var: InferenceVar,
outer_binder: DebruijnIndex,
) -> Result<Const<I>, Self::Error>
fn try_fold_inference_const( &mut self, ty: Ty<I>, var: InferenceVar, outer_binder: DebruijnIndex, ) -> Result<Const<I>, Self::Error>
As with
try_fold_inference_ty
, but for constants.Auto Trait Implementations§
impl<I> Freeze for DownShifter<I>where
I: Freeze,
impl<I> RefUnwindSafe for DownShifter<I>where
I: RefUnwindSafe,
impl<I> Send for DownShifter<I>where
I: Send,
impl<I> Sync for DownShifter<I>where
I: Sync,
impl<I> Unpin for DownShifter<I>where
I: Unpin,
impl<I> UnwindSafe for DownShifter<I>where
I: UnwindSafe,
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