charon_lib::ast::types::vars

Enum DeBruijnVar

source
pub enum DeBruijnVar<Id> {
    Bound(DeBruijnId, Id),
    Free(Id),
}
Expand description

Type-level variable.

Variables are bound in groups. Each item has a top-level binding group in its generic_params field, and then inner binders are possible using the RegionBinder<T> and Binder<T> types. Each variable is linked to exactly one binder. The Id then identifies the specific variable among all those bound in that group.

For instance, we have the following:

fn f<'a, 'b>(x: for<'c> fn(&'b u8, &'c u16, for<'d> fn(&'b u32, &'c u64, &'d u128)) -> u64) {}
     ^^^^^^         ^^       ^       ^          ^^       ^        ^        ^
       |       inner binder  |       |     inner binder  |        |        |
 top-level binder            |       |                   |        |        |
                       Bound(1, b)   |              Bound(2, b)   |     Bound(0, d)
                                     |                            |
                                 Bound(0, c)                 Bound(1, c)

To make consumption easier for projects that don’t do heavy substitution, a micro-pass at the end changes the variables bound at the top-level (i.e. in the GenericParams of items) to be Free. This is an optional pass, we may add a flag to deactivate it. The example above becomes:

fn f<'a, 'b>(x: for<'c> fn(&'b u8, &'c u16, for<'d> fn(&'b u32, &'c u64, &'d u128)) -> u64) {}
     ^^^^^^         ^^       ^       ^          ^^       ^        ^        ^
       |       inner binder  |       |     inner binder  |        |        |
 top-level binder            |       |                   |        |        |
                          Free(b)    |                Free(b)     |     Bound(0, d)
                                     |                            |
                                 Bound(0, c)                 Bound(1, c)

At the moment only region variables can be bound in a non-top-level binder.

Variants§

§

Bound(DeBruijnId, Id)

A variable attached to the nth binder, counting from the innermost.

§

Free(Id)

A variable attached to the outermost binder (the one on the item). As explained above, This is not used in charon internals, only as a micro-pass before exporting the crate data.

Implementations§

source§

impl<Id> DeBruijnVar<Id>
where Id: Copy,

source

pub fn new_at_zero(id: Id) -> Self

source

pub fn free(id: Id) -> Self

source

pub fn bound(index: DeBruijnId, id: Id) -> Self

source

pub fn incr(&self) -> Self

source

pub fn decr(&self) -> Self

source

pub fn bound_at_depth(&self, depth: DeBruijnId) -> Option<Id>

Returns the variable id if it is bound as the given depth.

source

pub fn move_out_from_depth(&self, depth: DeBruijnId) -> Option<Self>

Move the variable out of depth binders. Returns None if the variable is bound in one of these depth binders.

source

pub fn move_under_binders(&self, depth: DeBruijnId) -> Self

Move under depth binders.

Trait Implementations§

source§

impl<T: AstVisitable + Idx> AstVisitable for DeBruijnVar<T>

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any method if it exists, otherwise visit_inner.
source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any method if it exists, otherwise visit_inner.
source§

fn name(&self) -> &'static str

The name of the type, used for debug logging.
source§

fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))

Visit all occurrences of that type inside self, in pre-order traversal.
source§

fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))

Visit all occurrences of that type inside self, in pre-order traversal.
source§

impl<Id: Clone> Clone for DeBruijnVar<Id>

source§

fn clone(&self) -> DeBruijnVar<Id>

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

impl<Id: Debug> Debug for DeBruijnVar<Id>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de, Id> Deserialize<'de> for DeBruijnVar<Id>
where Id: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Id> Display for DeBruijnVar<Id>
where Id: Display,

source§

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

Formats the value using the given formatter. Read more
source§

impl<'s, Id, V> Drive<'s, V> for DeBruijnVar<Id>
where V: Visitor + Visit<'s, DeBruijnId> + Visit<'s, Id>,

source§

fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>

Call v.visit() on the immediate contents of self.
source§

impl<'s, Id, V> DriveMut<'s, V> for DeBruijnVar<Id>
where V: Visitor + VisitMut<'s, DeBruijnId> + VisitMut<'s, Id>,

source§

fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>

Call v.visit() on the immediate contents of self.
source§

impl<'a> Formatter<DeBruijnVar<ConstGenericVarId>> for FmtCtx<'a>

source§

impl<'a> Formatter<DeBruijnVar<RegionId>> for FmtCtx<'a>

source§

impl<'a> Formatter<DeBruijnVar<TraitClauseId>> for FmtCtx<'a>

source§

impl<'a> Formatter<DeBruijnVar<TypeVarId>> for FmtCtx<'a>

source§

impl<Id: Hash> Hash for DeBruijnVar<Id>

source§

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

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

impl<Id: Ord> Ord for DeBruijnVar<Id>

source§

fn cmp(&self, other: &DeBruijnVar<Id>) -> 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
source§

impl<Id: PartialEq> PartialEq for DeBruijnVar<Id>

source§

fn eq(&self, other: &DeBruijnVar<Id>) -> 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.
source§

impl<Id: PartialOrd> PartialOrd for DeBruijnVar<Id>

source§

fn partial_cmp(&self, other: &DeBruijnVar<Id>) -> 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
source§

impl<Id> Serialize for DeBruijnVar<Id>
where Id: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Id: Copy> Copy for DeBruijnVar<Id>

source§

impl<Id: Eq> Eq for DeBruijnVar<Id>

source§

impl<Id> StructuralPartialEq for DeBruijnVar<Id>

Auto Trait Implementations§

§

impl<Id> Freeze for DeBruijnVar<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for DeBruijnVar<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for DeBruijnVar<Id>
where Id: Send,

§

impl<Id> Sync for DeBruijnVar<Id>
where Id: Sync,

§

impl<Id> Unpin for DeBruijnVar<Id>
where Id: Unpin,

§

impl<Id> UnwindSafe for DeBruijnVar<Id>
where Id: UnwindSafe,

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

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

impl<I, T> ExtractContext<I, ()> for T

§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Indentable for T
where T: Display,

§

fn indented(self, indent: &str) -> Indented<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line of the formatted output will be prefixed with the indent. Read more
§

fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line except for the first of the formatted output will be prefixed with the indent. Read more
§

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.

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<I> RecreateContext<I> for I

§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
source§

impl<T> TyVisitable for T
where T: AstVisitable,

source§

fn substitute(&mut self, generics: &GenericArgs)

source§

fn move_under_binder(self) -> Self

Move under one binder.
source§

fn move_under_binders(self, depth: DeBruijnId) -> Self

Move under depth binders.
source§

fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>

Move the value out of depth binders. Returns None if it contains a variable bound in one of these depth binders.
source§

fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>

Visit the de Bruijn ids contained in self, as seen from the outside of self. This means that any variable bound inside self will be skipped, and all the seen indices will count from the outside of self.
§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

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