Struct chalk_ir::DebruijnIndex
source · [−]pub struct DebruijnIndex { /* private fields */ }
Expand description
References the binder at the given depth. The index is a de
Bruijn index, so it counts back through the in-scope binders,
with 0 being the innermost binder. This is used in impls and
the like. For example, if we had a rule like for<T> { (T: Clone) :- (T: Copy) }
, then T
would be represented as a
BoundVar(0)
(as the for
is the innermost binder).
Implementations
sourceimpl DebruijnIndex
impl DebruijnIndex
sourcepub const INNERMOST: DebruijnIndex = _
pub const INNERMOST: DebruijnIndex = _
Innermost index.
sourcepub const ONE: DebruijnIndex = _
pub const ONE: DebruijnIndex = _
One level higher than the innermost index.
sourcepub fn depth(self) -> u32
pub fn depth(self) -> u32
Depth of the De Bruijn index, counting from 0 starting with the innermost binder.
sourcepub fn within(self, outer_binder: DebruijnIndex) -> bool
pub fn within(self, outer_binder: DebruijnIndex) -> bool
True if the binder identified by this index is within the
binder identified by the index outer_binder
.
Example
Imagine you have the following binders in scope
forall<a> forall<b> forall<c>
then the Debruijn index for c
would be 0
, the index for
b
would be 1, and so on. Now consider the following calls:
c.within(a) = true
b.within(a) = true
a.within(a) = false
a.within(c) = false
sourcepub fn shifted_in(self) -> DebruijnIndex
pub fn shifted_in(self) -> DebruijnIndex
Returns the resulting index when this value is moved into through one binder.
sourcepub fn shift_in(&mut self)
pub fn shift_in(&mut self)
Update this index in place by shifting it “in” through
amount
number of binders.
sourcepub fn shifted_in_from(self, outer_binder: DebruijnIndex) -> DebruijnIndex
pub fn shifted_in_from(self, outer_binder: DebruijnIndex) -> DebruijnIndex
Adds outer_binder
levels to the self
index. Intuitively, this
shifts the self
index, which was valid at the outer binder,
so that it is valid at the innermost binder.
Example: Assume that the following binders are in scope:
for<A> for<B> for<C> for<D>
^ outer binder
Assume further that the outer_binder
argument is 2,
which means that it is referring to the for<B>
binder
(since D
would be the innermost binder).
This means that self
is relative to the binder B
– so
if self
is 0 (INNERMOST
), then it refers to B
,
and if self
is 1, then it refers to A
.
We will return as follows:
0.shifted_in_from(2) = 2
– i.e.,B
, when shifted in to the binding levelD
, has index 21.shifted_in_from(2) = 3
– i.e.,A
, when shifted in to the binding levelD
, has index 32.shifted_in_from(1) = 3
– here, we changed theouter_binder
to refer toC
. Therefore2
(relative toC
) refers toA
, so the result is still 3 (sinceA
, relative to the innermost binder, has index 3).
sourcepub fn shifted_out(self) -> Option<DebruijnIndex>
pub fn shifted_out(self) -> Option<DebruijnIndex>
Returns the resulting index when this value is moved out from
amount
number of new binders.
sourcepub fn shifted_out_to(self, outer_binder: DebruijnIndex) -> Option<DebruijnIndex>
pub fn shifted_out_to(self, outer_binder: DebruijnIndex) -> Option<DebruijnIndex>
Subtracts outer_binder
levels from the self
index. Intuitively, this
shifts the self
index, which was valid at the innermost
binder, to one that is valid at the binder outer_binder
.
This will return None
if the self
index is internal to the
outer binder (i.e., if self < outer_binder
).
Example: Assume that the following binders are in scope:
for<A> for<B> for<C> for<D>
^ outer binder
Assume further that the outer_binder
argument is 2,
which means that it is referring to the for<B>
binder
(since D
would be the innermost binder).
This means that the result is relative to the binder B
– so
if self
is 0 (INNERMOST
), then it refers to B
,
and if self
is 1, then it refers to A
.
We will return as follows:
1.shifted_out_to(2) = None
– i.e., the binder forC
can’t be named from the binding levelB
3.shifted_out_to(2) = Some(1)
– i.e.,A
, when shifted out to the binding levelB
, has index 1
Trait Implementations
sourceimpl Clone for DebruijnIndex
impl Clone for DebruijnIndex
sourcefn clone(&self) -> DebruijnIndex
fn clone(&self) -> DebruijnIndex
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for DebruijnIndex
impl Debug for DebruijnIndex
sourceimpl Hash for DebruijnIndex
impl Hash for DebruijnIndex
sourceimpl Ord for DebruijnIndex
impl Ord for DebruijnIndex
sourcefn cmp(&self, other: &DebruijnIndex) -> Ordering
fn cmp(&self, other: &DebruijnIndex) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<DebruijnIndex> for DebruijnIndex
impl PartialEq<DebruijnIndex> for DebruijnIndex
sourcefn eq(&self, other: &DebruijnIndex) -> bool
fn eq(&self, other: &DebruijnIndex) -> bool
sourceimpl PartialOrd<DebruijnIndex> for DebruijnIndex
impl PartialOrd<DebruijnIndex> for DebruijnIndex
sourcefn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>
fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<I: Interner> TypeFoldable<I> for DebruijnIndex
impl<I: Interner> TypeFoldable<I> for DebruijnIndex
sourcefn try_fold_with<E>(
self,
_folder: &mut dyn FallibleTypeFolder<I, Error = E>,
_outer_binder: DebruijnIndex
) -> Result<Self, E>
fn try_fold_with<E>(
self,
_folder: &mut dyn FallibleTypeFolder<I, Error = E>,
_outer_binder: DebruijnIndex
) -> Result<Self, E>
folder
to self
; binders
is the
number of binders that are in scope when beginning the
folder. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs. Read moresourcefn fold_with(
self,
folder: &mut dyn TypeFolder<I>,
outer_binder: DebruijnIndex
) -> Self
fn fold_with(
self,
folder: &mut dyn TypeFolder<I>,
outer_binder: DebruijnIndex
) -> Self
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
. Read moresourceimpl<I: Interner> TypeVisitable<I> for DebruijnIndex
impl<I: Interner> TypeVisitable<I> for DebruijnIndex
sourcefn visit_with<B>(
&self,
_visitor: &mut dyn TypeVisitor<I, BreakTy = B>,
_outer_binder: DebruijnIndex
) -> ControlFlow<B>
fn visit_with<B>(
&self,
_visitor: &mut dyn TypeVisitor<I, BreakTy = B>,
_outer_binder: DebruijnIndex
) -> ControlFlow<B>
visitor
to self
; binders
is the
number of binders that are in scope when beginning the
visitor. Typically binders
starts as 0, but is adjusted when
we encounter Binders<T>
in the IR or other similar
constructs. Read moreimpl Copy for DebruijnIndex
impl Eq for DebruijnIndex
impl StructuralEq for DebruijnIndex
impl StructuralPartialEq for DebruijnIndex
Auto Trait Implementations
impl RefUnwindSafe for DebruijnIndex
impl Send for DebruijnIndex
impl Sync for DebruijnIndex
impl Unpin for DebruijnIndex
impl UnwindSafe for DebruijnIndex
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Cast for T
impl<T> Cast for T
sourcefn cast<U>(self, interner: U::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: U::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
U
using CastTo
.sourceimpl<T, I> Shift<I> for Twhere
T: TypeFoldable<I>,
I: Interner,
impl<T, I> Shift<I> for Twhere
T: TypeFoldable<I>,
I: Interner,
sourcefn shifted_in(self, interner: I) -> T
fn shifted_in(self, interner: I) -> T
sourcefn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T
fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T
outer_binder
so that it is
valid at the innermost binder. See DebruijnIndex::shifted_in_from
for a detailed explanation. Read moresourcefn shifted_out_to(
self,
interner: I,
target_binder: DebruijnIndex
) -> Result<T, NoSolution>
fn shifted_out_to(
self,
interner: I,
target_binder: DebruijnIndex
) -> Result<T, NoSolution>
outer_binder
. See DebruijnIndex::shifted_out_to
for a detailed explanation. Read more