rustc_infer::infer::canonical

Crate ir

Modules§

  • A folding traversal mechanism for complex data structures that contain type information.
  • Set of traits which are used to emulate the inherent impls that are present in rustc_middle. It is customary to glob-import rustc_type_ir::inherent::* to bring all of these traits into scope when programming in interner-agnostic settings, and to avoid importing any of these directly elsewhere (i.e. specify the full path for an implementation downstream).
  • The outlives relation T: 'a or 'a: 'b. This code frequently refers to rules defined in RFC 1214 (OutlivesFooBar), so see that RFC for reference.
  • A visiting traversal mechanism for complex data structures that contain type information.

Structs§

  • Represents the unprojected term of a projection goal.
  • Represents the projection of an associated, opaque, or lazy-type-alias type.
  • Binder is a binder for higher-ranked lifetimes or types. It is part of the compiler’s representation for things like for<'a> Fn(&'a isize) (which would be represented by the type PolyTraitRef == Binder<I, TraitRef>). Note that when we instantiate, erase, or otherwise “discharge” these bound vars, we change the type from Binder<I, T> to just T (see e.g., liberate_late_bound_regions).
  • A “canonicalized” type V is one where all free inference variables have been rewritten to “canonical vars”. These are numbered starting from 0 in order of first appearance.
  • Information about a canonical variable that is included with the canonical value. This is sufficient information for code to create a copy of the canonical value in some other inference context, with fresh inference variables replacing the canonical values.
  • A set of values corresponding to the canonical variables from some Canonical. You can give these values to canonical_value.instantiate to instantiate them into the canonical value at the right places.
  • A closure can be modeled as a struct that looks like:
  • Struct returned by split().
  • Encodes that we have to coerce from the a type to the b type.
  • A const variable ID.
  • Similar to ClosureArgs; see the above documentation for more.
  • See docs for explanation of how each argument is used.
  • 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:
  • Similar to super::Binder except that it tracks early bound generics, i.e. struct Foo<T>(T) needs T instantiated immediately. This type primarily exists to avoid forgetting to call instantiate.
  • A ProjectionPredicate for an ExistentialTraitRef.
  • An existential reference to a trait, where Self is erased. For example, the trait object Trait<'a, 'b, X, Y> is:
  • A floating-point (f32 or f64) type variable ID.
  • An integral (u32, i32, usize, etc.) type variable ID.
  • Used by the new solver to normalize an alias. This always expects the term to be an unconstrained inference variable which is used as the output.
  • A: 'region
  • This kind of predicate has no direct correspondent in the syntax, but it roughly corresponds to the syntactic forms:
  • A region variable ID.
  • Encodes that a must be a subtype of b. The a_is_expected flag indicates whether the a type is the type that we should label as “expected” when presenting user diagnostics.
  • A complete reference to a trait. These take numerous guises in syntax, but perhaps the most recognizable form is in a where-clause:
  • A type variable ID.
  • Flags that we track on types. These flags are propagated upwards through the type during type construction, so that we can quickly check whether the type has various kinds of types in it without recursing over the type itself.
  • An unevaluated (potentially generic) constant used in the type-system.
  • “Universes” are used during type- and trait-checking in the presence of for<..> binders to control what sets of names are visible. Universes are arranged into a tree: the root universe contains names that are always visible. Each child then adds a new set of names that are visible, in addition to those of its parent. We say that the child universe “extends” the parent universe with new names.
  • A helper type that you can wrap round your own type in order to automatically cache the stable hash, type flags and debruijn index on creation and not recompute it whenever the information is needed. This is only done in incremental mode. You can also opt out of caching by using StableHash::ZERO for the hash, in which case the hash gets computed each time. This is useful if you have values that you intern but never (can?) use for stable hashing.

Enums§

  • Rust actually has more than one category of type variables; notably, the type variables we create for literals (e.g., 22 or 22.) can only be instantiated with integral/float types (e.g., usize or f32). In order to faithfully reproduce a type, we need to know what set of types a given type variable can be unified with.
  • Describes the “kind” of the canonical variable. This is a “kind” in the type-theory sense of the term – i.e., a “meta” type system that analyzes type-like values.
  • A clause is something that can appear in where bounds or be inferred by implied bounds.
  • Represents the various closure traits in the language. This will determine the type of the environment (self, in the desugaring) argument that the closure expects.
  • Represents a constant in Rust.
  • Specifies how a trait object is represented.
  • An inference variable for a const, for use in const generics.
  • A placeholder for a type that hasn’t been inferred yet.
  • Polarity for a trait predicate. May either be negative or positive. Distinguished from ImplPolarity since we never compute goals with “reservation” level.
  • Representation of regions. Note that the NLL checker uses a distinct representation of regions. For this reason, it internally replaces all the regions with inference variables – the index of the variable is then used to index into internal NLL data structures. See rustc_const_eval::borrow_check module for more information.
  • Defines the kinds of types used by the type system.
  • The current typing mode of an inference context. We unfortunately have some slightly different typing rules depending on the current context. See the doc comment for each variant for how and why they are used.

Constants§

  • The shorthand encoding uses an enum’s variant index usize and is offset by this value so it never matches a real variant. This offset is also chosen so that the first byte is never < 0x80.

Traits§

  • Imagine you have a function F: FnOnce(&[T]) -> R, plus an iterator iter that produces T items. You could combine them with f(&iter.collect::<Vec<_>>()), but this requires allocating memory for the Vec.
  • Trait for decoding to a reference.
  • An Into-like trait that takes TyCtxt to perform interner-specific transformations.
  • A From-like trait that takes TyCtxt to perform interner-specific transformations.

Functions§