hir_ty

Struct DebruijnIndex

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§

§

impl DebruijnIndex

pub const INNERMOST: DebruijnIndex = _

Innermost index.

pub const ONE: DebruijnIndex = _

One level higher than the innermost index.

pub fn new(depth: u32) -> DebruijnIndex

Creates a new de Bruijn index with a given depth.

pub fn depth(self) -> u32

Depth of the De Bruijn index, counting from 0 starting with the innermost binder.

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

pub fn shifted_in(self) -> DebruijnIndex

Returns the resulting index when this value is moved into through one binder.

pub fn shift_in(&mut self)

Update this index in place by shifting it “in” through amount number of binders.

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 level D, has index 2
  • 1.shifted_in_from(2) = 3 – i.e., A, when shifted in to the binding level D, has index 3
  • 2.shifted_in_from(1) = 3 – here, we changed the outer_binder to refer to C. Therefore 2 (relative to C) refers to A, so the result is still 3 (since A, relative to the innermost binder, has index 3).

pub fn shifted_out(self) -> Option<DebruijnIndex>

Returns the resulting index when this value is moved out from amount number of new binders.

pub fn shift_out(&mut self)

Update in place by shifting out from amount binders.

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 for C can’t be named from the binding level B
  • 3.shifted_out_to(2) = Some(1) – i.e., A, when shifted out to the binding level B, has index 1

Trait Implementations§

§

impl Clone for DebruijnIndex

§

fn clone(&self) -> DebruijnIndex

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for DebruijnIndex

§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Hash for DebruijnIndex

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl Ord for DebruijnIndex

§

fn cmp(&self, other: &DebruijnIndex) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl PartialEq for DebruijnIndex

§

fn eq(&self, other: &DebruijnIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for DebruijnIndex

§

fn partial_cmp(&self, other: &DebruijnIndex) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<I> TypeFoldable<I> for DebruijnIndex
where I: Interner,

§

fn try_fold_with<E>( self, _folder: &mut dyn FallibleTypeFolder<I, Error = E>, _outer_binder: DebruijnIndex, ) -> Result<DebruijnIndex, E>

Apply the given folder 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.
§

fn fold_with( self, folder: &mut dyn TypeFolder<I, Error = Infallible>, outer_binder: DebruijnIndex, ) -> Self

A convenient alternative to try_fold_with for use with infallible folders. Do not override this method, to ensure coherence with try_fold_with.
§

impl<I> TypeVisitable<I> for DebruijnIndex
where I: Interner,

§

fn visit_with<B>( &self, _visitor: &mut dyn TypeVisitor<I, BreakTy = B>, _outer_binder: DebruijnIndex, ) -> ControlFlow<B>

Apply the given visitor 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.
§

impl Copy for DebruijnIndex

§

impl Eq for DebruijnIndex

§

impl StructuralPartialEq for DebruijnIndex

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Cast for T

§

fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U
where Self: CastTo<U>, U: HasInterner,

Cast a value to type U using CastTo.
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Sync + Send> for T
where T: Any + Send + Sync,

§

fn into_box(self) -> Box<dyn Any + Sync + Send>

Convert self into the appropriate boxed form.
source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T, I> Shift<I> for T
where T: TypeFoldable<I>, I: Interner,

§

fn shifted_in(self, interner: I) -> T

Shifts this term in one level of binders.
§

fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T

Shifts a term valid at outer_binder so that it is valid at the innermost binder. See DebruijnIndex::shifted_in_from for a detailed explanation.
§

fn shifted_out_to( self, interner: I, target_binder: DebruijnIndex, ) -> Result<T, NoSolution>

Shifts a term valid at the innermost binder so that it is valid at outer_binder. See DebruijnIndex::shifted_out_to for a detailed explanation.
§

fn shifted_out(self, interner: I) -> Result<T, NoSolution>

Shifts this term out one level of binders.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T, I> VisitExt<I> for T
where I: Interner, T: TypeVisitable<I>,

§

fn has_free_vars(&self, interner: I) -> bool

Check whether there are free (non-bound) variables.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<N> NodeTrait for N
where N: Copy + Ord + Hash,