Struct chalk_ir::DebruijnIndex[][src]

pub struct DebruijnIndex { /* fields omitted */ }
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[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 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).

#[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]

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[src]

fn clone(&self) -> DebruijnIndex[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for DebruijnIndex[src]

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

Formats the value using the given formatter. Read more

impl<I: Interner> Fold<I> 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>,
    _outer_binder: DebruijnIndex
) -> Fallible<Self::Result> where
    I: 'i, 
[src]

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. Read more

impl Hash for DebruijnIndex[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

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

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

impl Ord for DebruijnIndex[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<DebruijnIndex> for DebruijnIndex[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]

This method tests for !=.

impl PartialOrd<DebruijnIndex> for DebruijnIndex[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) -> bool
1.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) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<I: Interner> Visit<I> for DebruijnIndex[src]

fn visit_with<'i, B>(
    &self,
    _visitor: &mut dyn Visitor<'i, I, BreakTy = B>,
    _outer_binder: DebruijnIndex
) -> ControlFlow<B> where
    I: 'i, 
[src]

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. 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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Cast for T[src]

fn cast<U>(self, interner: &U::Interner) -> U where
    Self: CastTo<U>,
    U: HasInterner
[src]

Cast a value to type U using CastTo.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, I> Shift<I> for T where
    T: Fold<I>,
    I: Interner
[src]

pub fn shifted_in(Self, &I) -> <T as Fold<I>>::Result[src]

Shifts this term in one level of binders.

pub fn shifted_in_from(Self, &I, DebruijnIndex) -> <T as Fold<I>>::Result[src]

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. Read more

pub fn shifted_out_to(
    Self,
    &I,
    DebruijnIndex
) -> Result<<T as Fold<I>>::Result, NoSolution>
[src]

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. Read more

pub fn shifted_out(Self, &I) -> Result<<T as Fold<I>>::Result, NoSolution>[src]

Shifts this term out one level of binders.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, I> VisitExt<I> for T where
    T: Visit<I>,
    I: Interner
[src]

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

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