Struct rustc_type_ir::DebruijnIndex [−][src]
pub struct DebruijnIndex {
private: u32,
}Expand description
A De Bruijn index is a standard means of representing regions (and perhaps later types) in a higher-ranked setting. In particular, imagine a type like this:
for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char) ^ ^ | | | | | | | | | +------------+ 0 | | | | | +----------------------------------+ 1 | | | +----------------------------------------------+ 0
In this type, there are two binders (the outer fn and the inner fn). We need to be able to determine, for any given region, which fn type it is bound by, the inner or the outer one. There are various ways you can do this, but a De Bruijn index is one of the more convenient and has some nice properties. The basic idea is to count the number of binders, inside out. Some examples should help clarify what I mean.
Let’s start with the reference type &'b isize that is the first
argument to the inner function. This region 'b is assigned a De
Bruijn index of 0, meaning “the innermost binder” (in this case, a
fn). The region 'a that appears in the second argument type (&'a isize) would then be assigned a De Bruijn index of 1, meaning “the
second-innermost binder”. (These indices are written on the arrows
in the diagram).
What is interesting is that De Bruijn index attached to a particular
variable will vary depending on where it appears. For example,
the final type &'a char also refers to the region 'a declared on
the outermost fn. But this time, this reference is not nested within
any other binders (i.e., it is not an argument to the inner fn, but
rather the outer one). Therefore, in this case, it is assigned a
De Bruijn index of 0, because the innermost binder in that location
is the outer fn.
Fields
private: u32Implementations
impl DebruijnIndex[src]
impl DebruijnIndex[src]pub const MAX_AS_U32: u32[src]
pub const MAX: Self[src]
pub const fn from_usize(value: usize) -> Self[src]
pub const fn from_u32(value: u32) -> Self[src]
pub const unsafe fn from_u32_unchecked(value: u32) -> Self[src]
impl DebruijnIndex[src]
impl DebruijnIndex[src]#[must_use]pub fn shifted_in(self, amount: u32) -> DebruijnIndex[src]
#[must_use]pub fn shifted_in(self, amount: u32) -> DebruijnIndex[src]Returns the resulting index when this value is moved into
amount number of new binders. So, e.g., if you had
for<’a> fn(&’a x)
and you wanted to change it to
for<’a> fn(for<’b> fn(&’a x))
you would need to shift the index for 'a into a new binder.
pub fn shift_in(&mut self, amount: u32)[src]
pub fn shift_in(&mut self, amount: u32)[src]Update this index in place by shifting it “in” through
amount number of binders.
#[must_use]pub fn shifted_out(self, amount: u32) -> DebruijnIndex[src]
#[must_use]pub fn shifted_out(self, amount: u32) -> DebruijnIndex[src]Returns the resulting index when this value is moved out from
amount number of new binders.
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self[src]
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self[src]Adjusts any De Bruijn indices so as to make to_binder the
innermost binder. That is, if we have something bound at to_binder,
it will now be bound at INNERMOST. This is an appropriate thing to do
when moving a region out from inside binders:
for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
// Binder: D3 D2 D1 ^^Here, the region 'a would have the De Bruijn index D3,
because it is the bound 3 binders out. However, if we wanted
to refer to that region 'a in the second argument (the _),
those two binders would not be in scope. In that case, we
might invoke shift_out_to_binder(D3). This would adjust the
De Bruijn index of 'a to D1 (the innermost binder).
If we invoke shift_out_to_binder and the region is in fact
bound by one of the binders we are shifting out of, that is an
error (and should fail an assertion failure).
Trait Implementations
impl Add<usize> for DebruijnIndex[src]
impl Add<usize> for DebruijnIndex[src]impl Clone for DebruijnIndex[src]
impl Clone for DebruijnIndex[src]impl Debug for DebruijnIndex[src]
impl Debug for DebruijnIndex[src]impl<D: Decoder> Decodable<D> for DebruijnIndex[src]
impl<D: Decoder> Decodable<D> for DebruijnIndex[src]impl<E: Encoder> Encodable<E> for DebruijnIndex[src]
impl<E: Encoder> Encodable<E> for DebruijnIndex[src]impl Hash for DebruijnIndex[src]
impl Hash for DebruijnIndex[src]impl<CTX> HashStable<CTX> for DebruijnIndex[src]
impl<CTX> HashStable<CTX> for DebruijnIndex[src]fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)[src]
impl Idx for DebruijnIndex[src]
impl Idx for DebruijnIndex[src]impl Ord for DebruijnIndex[src]
impl Ord for DebruijnIndex[src]impl PartialEq<DebruijnIndex> for DebruijnIndex[src]
impl PartialEq<DebruijnIndex> for DebruijnIndex[src]fn eq(&self, other: &DebruijnIndex) -> bool[src]
fn eq(&self, other: &DebruijnIndex) -> bool[src]This method tests for self and other values to be equal, and is used
by ==. Read more
fn ne(&self, other: &DebruijnIndex) -> bool[src]
fn ne(&self, other: &DebruijnIndex) -> bool[src]This method tests for !=.
impl PartialOrd<DebruijnIndex> for DebruijnIndex[src]
impl PartialOrd<DebruijnIndex> for DebruijnIndex[src]fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>[src]This method returns an ordering between self and other values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Step for DebruijnIndex[src]
impl Step for DebruijnIndex[src]fn steps_between(start: &Self, end: &Self) -> Option<usize>[src]
fn steps_between(start: &Self, end: &Self) -> Option<usize>[src]🔬 This is a nightly-only experimental API. (step_trait)
recently redesigned
Returns the number of successor steps required to get from start to end. Read more
fn forward_checked(start: Self, u: usize) -> Option<Self>[src]
fn forward_checked(start: Self, u: usize) -> Option<Self>[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the successor
of self count times. Read more
fn backward_checked(start: Self, u: usize) -> Option<Self>[src]
fn backward_checked(start: Self, u: usize) -> Option<Self>[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the predecessor
of self count times. Read more
fn forward(start: Self, count: usize) -> Self[src]
fn forward(start: Self, count: usize) -> Self[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the successor
of self count times. Read more
unsafe fn forward_unchecked(start: Self, count: usize) -> Self[src]
unsafe fn forward_unchecked(start: Self, count: usize) -> Self[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the successor
of self count times. Read more
fn backward(start: Self, count: usize) -> Self[src]
fn backward(start: Self, count: usize) -> Self[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the predecessor
of self count times. Read more
unsafe fn backward_unchecked(start: Self, count: usize) -> Self[src]
unsafe fn backward_unchecked(start: Self, count: usize) -> Self[src]🔬 This is a nightly-only experimental API. (step_trait_ext)
recently added
Returns the value that would be obtained by taking the predecessor
of self count times. Read more
impl Copy for DebruijnIndex[src]
impl Eq for DebruijnIndex[src]
impl StructuralEq for DebruijnIndex[src]
impl StructuralPartialEq for DebruijnIndex[src]
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> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more