[−][src]Struct chalk_ir::DebruijnIndex
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
impl DebruijnIndex
[src]
pub const INNERMOST: DebruijnIndex
[src]
Innermost index.
pub const ONE: DebruijnIndex
[src]
One level higher than the innermost index.
pub fn new(depth: u32) -> Self
[src]
Creates a new de Bruijn index with a given depth.
pub fn depth(self) -> u32
[src]
Depth of the De Bruijn index, counting from 0 starting with the innermost binder.
pub fn within(self, outer_binder: DebruijnIndex) -> bool
[src]
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
#[must_use]pub fn shifted_in(self) -> DebruijnIndex
[src]
Returns the resulting index when this value is moved into through one binder.
pub fn shift_in(&mut self)
[src]
Update this index in place by shifting it "in" through
amount
number of binders.
#[must_use]pub fn shifted_in_from(self, outer_binder: DebruijnIndex) -> DebruijnIndex
[src]
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).
#[must_use]pub fn shifted_out(self) -> Option<DebruijnIndex>
[src]
Returns the resulting index when this value is moved out from
amount
number of new binders.
pub fn shift_out(&mut self)
[src]
Update in place by shifting out from amount
binders.
pub fn shifted_out_to(
self,
outer_binder: DebruijnIndex
) -> Option<DebruijnIndex>
[src]
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
impl Clone for DebruijnIndex
[src]
fn clone(&self) -> DebruijnIndex
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for DebruijnIndex
[src]
impl Debug for DebruijnIndex
[src]
impl Eq for DebruijnIndex
[src]
impl<I: Interner, TI: TargetInterner<I>> Fold<I, TI> for DebruijnIndex
[src]
type Result = Self
The type of value that will be produced once folding is done. Typically this is Self
, unless Self
contains borrowed values, in which case owned values are produced (for example, one can fold over a &T
value where T: Fold
, in which case you get back a T
, not a &T
). Read more
fn fold_with<'i>(
&self,
_folder: &mut dyn Folder<'i, I, TI>,
_outer_binder: DebruijnIndex
) -> Fallible<Self::Result> where
I: 'i,
TI: 'i,
[src]
&self,
_folder: &mut dyn Folder<'i, I, TI>,
_outer_binder: DebruijnIndex
) -> Fallible<Self::Result> where
I: 'i,
TI: 'i,
impl Hash for DebruijnIndex
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for DebruijnIndex
[src]
fn cmp(&self, other: &DebruijnIndex) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<DebruijnIndex> for DebruijnIndex
[src]
fn eq(&self, other: &DebruijnIndex) -> bool
[src]
fn ne(&self, other: &DebruijnIndex) -> bool
[src]
impl PartialOrd<DebruijnIndex> for DebruijnIndex
[src]
fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>
[src]
fn lt(&self, other: &DebruijnIndex) -> bool
[src]
fn le(&self, other: &DebruijnIndex) -> bool
[src]
fn gt(&self, other: &DebruijnIndex) -> bool
[src]
fn ge(&self, other: &DebruijnIndex) -> bool
[src]
impl StructuralEq for DebruijnIndex
[src]
impl StructuralPartialEq for DebruijnIndex
[src]
impl<I: Interner> Visit<I> for DebruijnIndex
[src]
fn visit_with<'i, R: VisitResult>(
&self,
_visitor: &mut dyn Visitor<'i, I, Result = R>,
_outer_binder: DebruijnIndex
) -> R where
I: 'i,
[src]
&self,
_visitor: &mut dyn Visitor<'i, I, Result = R>,
_outer_binder: DebruijnIndex
) -> R where
I: 'i,
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Cast for T
[src]
fn cast<U>(self, interner: &U::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
[src]
Self: CastTo<U>,
U: HasInterner,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, I> Shift<I> for T where
I: Interner,
T: Fold<I, I>,
[src]
I: Interner,
T: Fold<I, I>,
fn shifted_in(&Self, &I) -> <T as Fold<I, I>>::Result
[src]
fn shifted_in_from(&Self, &I, DebruijnIndex) -> <T as Fold<I, I>>::Result
[src]
fn shifted_out_to(
&Self,
&I,
DebruijnIndex
) -> Result<<T as Fold<I, I>>::Result, NoSolution>
[src]
&Self,
&I,
DebruijnIndex
) -> Result<<T as Fold<I, I>>::Result, NoSolution>
fn shifted_out(&Self, &I) -> Result<<T as Fold<I, I>>::Result, NoSolution>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, I> VisitExt<I> for T where
I: Interner,
T: Visit<I>,
[src]
I: Interner,
T: Visit<I>,