Expand description
A frontend to rustc internals, to massage its representations and queries into a more uniform shape.
Re-exports§
pub use sinto::SInto;pub use mir_kinds::IsMirKind;pub use crate::sinto_reexport;pub use crate::sinto_todo;pub use rustc_trait_elaboration as elaboration;pub use crate::frontend::*;pub use crate::frontend::state::*;
Modules§
- adt
- constant_
utils 🔒 - def_id
- This module contains the type definition for
DefIdand the typesDefIddepends on. - full_
def - item_
ref - mir
- Copies of the relevant
MIRtypes. MIR represents a rust (function) body as a CFG. It’s a semantically rich representation that contains no high-level control-flow operations like loops or patterns; instead the control flow is entirely described by gotos and switches on integer values. - mir_
kinds - Enumerates the kinds of Mir bodies. TODO: use const generics instead of an open list of types.
- new
- This module contains type definitions that have no equivalent in Rustc.
- options
- predicates
- prelude 🔒
- rustc
- rustc_
utils 🔒 - sinto 🔒
- state
- synthetic_
items - traits 🔒
- ty
- Frontend representations of Rust types and related type operations.
- types 🔒
- uneval
- Translate constants to the frontend: type-system constants, and the values read by
rustc_const_uneval. - vars
Structs§
- Adt
- ADts (
Struct,EnumandUnionmap to this). - AdtTy
- Alias
- This type merges the information from
[
ty::AliasTyKind] and [ty::AliasTy]. - ArrayTy
- Assoc
Const - Associated constant:
trait MyTrait { const ASSOC: usize; } - AssocFn
- Associated function:
impl MyStruct { fn associated() {} }ortrait Foo { fn associated() {} } - Assoc
Item - Reflects [
ty::AssocItem] - AssocTy
- Associated type:
trait MyTrait { type Assoc; } - Binder
- Reflects [
ty::Binder] - BoundTy
- Reflects [
ty::BoundTy] - Bound
TyRef - Canonical
- Reflects [
rustc_middle::infer::canonical::Canonical] - Canonical
User Type Annotation - Reflects [
ty::CanonicalUserTypeAnnotation] - Clause
- Reflects [
ty::Clause] and adds a hash-consed predicate identifier. - Closure
- A closure, coroutine, or coroutine-closure.
- Closure
Ty - Reflects [
ty::ClosureArgs] - Coerce
Predicate - Reflects [
ty::CoercePredicate] - Const
- Const
Operand - The contents of
Operand::Const. - Constant
Expr - Rustc has different representations for constants: one for MIR
([
rustc_middle::mir::Const]), one for the type system ([rustc_middle::ty::ConstKind]). For simplicity the frontend maps those two constructs to the sameConstantExprtype. - Constant
Field Expr - Coroutine
Ty - Ctor
- The constructor function of a tuple/unit struct or tuple/unit enum variant.
- DefId
- Reflects
rustc_hir::def_id::DefId, augmented to also give ids to promoted constants (which have their own ad-hoc numbering scheme in rustc for now). - DefId
Contents - Disambiguated
DefPath Item - Reflects [
rustc_hir::definitions::DisambiguatedDefPathData] - Discriminant
Value - Reflects [
ty::util::Discr] - DynBinder
- A representation of
exists<T: Trait1 + Trait2>(value): we create a fresh type id and the appropriate trait clauses. The contained value may refer to the fresh ty and the in-scope trait clauses. This is used to represent types related todyn Trait. - DynTrait
Ty - Elaboration
Ctx - Existential
Projection - Reflects [
ty::ExistentialProjection] - Existential
Trait Ref - Reflects [
ty::ExistentialTraitRef] - Field
Def - Reflects [
ty::FieldDef] - Fn
- FnDefTy
- FnPointer
- FnPtr
Shape - Represents the “shape” of a function pointer, i.e. the most general signature we can obtain
from it without breaking the higher-kinded variables. E.g.
for<'a> fn(&'a u32) -> Adt<'a, u32>is considered to be an instantiation of the shapefor<'a> fn(&'a A) -> Adt<'a, B>withA=B=u32. - FnPtrTy
- Foreign
Mod - An
externblock. - Foreign
Ty - FullDef
- Gathers a lot of definition information about a
rustc_hir::def_id::DefId. - Generic
Param Def - Reflects [
ty::GenericParamDef] - Generic
Param DefIds - This is a pretty criminal hack: I want to generate
ty::Genericsfor my fake items. This requiresDefIds for the generic parameters. rustc has an affordance for creating newDefIds (tcx.create_def()) but I could not figure out a way to use it that didn’t end up ICEing during metadata encoding. So instead I’m reusing theDefIds of generic parameters fromcorefunctions. - Generic
Predicate - Generic
Predicates - Reflects [
ty::GenericPredicates] - Impl
Assoc Item - An associated item in a trait impl. This can be an item provided by the trait impl, or an item that reuses the trait decl default value.
- Impl
Assoc Item Value - The item is provided by the trait impl.
- Inherent
Impl - Item
Predicate - Item
Predicates - ItemRef
- Reference to an item, with generics. Basically any mention of an item (function, type, etc) uses this.
- Item
RefContents - Contents of
ItemRef. - Late
Binder - A binder that wraps something that may mention the late-bound variables of an item. This does
not count for de Bruijn indices: the late bound vars will instead be referred to using
LateParam, using thedef_idof this binder. Thatdef_idis always that of the item, except in cases where the item doesn’t have a rustc DefId, in which case we use a dummy one. - Mod
- Outlives
Predicate - Reflects [
ty::OutlivesPredicate] as a named struct instead of a tuple struct. This is because the script converting JSONSchema types to OCaml doesn’t support tuple structs, and this is the only tuple struct in the whole AST. - Param
Env - The combination of type generics and related predicates.
- PatTy
- PathBuf
- An owned, mutable path (akin to
String). - Placeholder
- Reflects [
ty::Placeholder] - Predicate
- Reflects [
ty::Predicate] and adds a hash-consed predicate identifier. - Projection
Predicate - Expresses a constraints over an associated type.
- RawPtr
Ty - Rc
- A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
- RefTy
- Repr
Flags - The representation flags without the ones irrelevant outside of rustc.
- Repr
Options - Reflects [
rustc_abi::ReprOptions]. - SliceTy
- Static
- StrTy
- Subtype
Predicate - Reflects [
ty::SubtypePredicate] - Synthetic
Item Data - Trait
- Trait
Alias - Trait alias:
trait IntIterator = Iterator<Item = i32>; - Trait
Impl - Trait
Item Binder - The binding context to use when translating a trait impl associated item.
- Trait
Predicate - Reflects [
ty::TraitClause] - Trait
Proof - A
TraitProofdescribes the full data of a trait implementation. Because of generics, this may need to combine several concrete trait implementation items. For example,((1u8, 2u8), "hello").clone()combines the generic implementation ofClonefor(A, B)with the concrete implementations foru8and&str, represented as a tree. - Trait
Proof Contents - TupleTy
- Ty
- Reflects [
rustc_middle::ty::Ty] - TyAlias
- Type alias:
type Foo = Bar; - TyFnSig
- Reflects [
ty::FnSig] - TyGenerics
- Reflects [
rustc_trait_elaboration::GenericParams]. - Type
AndMut - Reflects [
ty::TypeAndMut] - User
Args - Reflects [
ty::UserArgs] - User
Self Ty - Reflects [
ty::UserSelfTy] - Variant
Def - Reflects [
ty::VariantDef] - Virtual
Impl Assoc Item - Align
- Alignment of a type in bytes (always a power of two).
- Bound
Var - Byte
Symbol - Like
Symbol, but for byte strings.ByteSymbolis used less widely, so it has fewer operations defined thanSymbol. - Debruijn
Index - 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:
- Early
Param Region - Field
Idx - The source-order index of a field in a variant.
- Index
Vec - An owned contiguous collection of
Ts, indexed byIrather than byusize. - Macro
Kinds - A set of macro kinds, for macros that can have more than one kind
- Param
Const - ParamTy
- Promoted
Id - RAlloc
Id - RDefId
- A
DefIdidentifies a particular definition, by combining a crate index and a def index. - Span
- A compressed span.
- Spanned
- Symbol
- An interned UTF-8 string.
- Variant
Idx - The source-order index of a variant in a type.
Enums§
- AdtKind
- Reflects [
ty::AdtKind] - Alias
Kind - Reflects [
rustc_middle::ty::AliasTyKind]. - Assoc
Item Container - Assoc
Item Resolution - Assoc
TyKind - Bound
Region Kind - Reflects [
ty::BoundRegionKind] - Bound
TyKind - Reflects [
ty::BoundTyKind] - Bound
Variable Kind - Reflects [
ty::BoundVariableKind] - Builtin
Trait Data - Clause
Kind - Reflects [
ty::ClauseKind] - Closure
Kind - Reflects [
ty::ClosureKind] - Const
Kind - The kind of a constant item.
- Const
Operand Kind - Const
Source - A constant that we can ask rustc to evaluate.
- Constant
Byte - A byte of an evaluated constant, in the MiniRust sense.
- Constant
Byte Provenance - What a pointer byte in an evaluated constant points to.
- Constant
Expr Kind - The subset of expressions that corresponds to constants.
- Constant
Int - Constant
Literal - Constant
Projection Elem - Projects a place inside the pointee of a constant pointer.
- Constant
PtrBase - The place a constant pointer starts from.
- DefId
Base - DefKind
- Reflects
rustc_hir::def::DefKind - DefPath
Item - Reflects [
rustc_hir::definitions::DefPathData] - Derived
Item Kind - Destruct
Data - Discriminant
Definition - Reflects [
ty::VariantDiscr] - Existential
Predicate - A predicate without
Self, for use indyn Trait. - FnPtr
Target - The function a function pointer points to.
- Full
DefKind - Imbues
rustc_hir::def::DefKindwith a lot of extra information. - Generic
Arg - Reflects both [
ty::GenericArg] and [ty::GenericArgKind] - Generic
Param DefKind - Reflects [
ty::GenericParamDefKind] - Generic
Predicate Id - Uniquely identifies a predicate.
- Global
Ref - A global allocation.
- Host
Effect Clause - Item
Predicate Id - Uniquely identifies a predicate.
- Normalizes
To - Pattern
- Predicate
Direction - Predicate
Kind - Reflects [
ty::PredicateKind] - Read
Mode - How to read back an evaluated constant.
- Synthetic
Item - We create some extra
DefIds to represent things that rustc doesn’t have aDefIdfor. This makes the pipeline much easier to have “real” def_ids for them, as we can then solve traits for them etc, and works well with monomorphization. - Term
- Reflects [
ty::Term] - Trait
Proof Implied Predicate - Trait
Proof Kind - The source of a particular trait implementation. Most often this is either
Concretefor a concreteimpl Trait for Type {}item, orLocalBoundfor a context-boundwhere T: Trait. - TyKind
- Reflects [
ty::TyKind] - Unsizing
Metadata - The metadata to attach to the newly-unsized ptr.
- User
Type - Reflects [
ty::UserType]: this is currently disabled, and everything is printed as debug in theUserType::Todovariant. - Variant
Kind - Describe the kind of a variant
- Visibility
- Reflects [
ty::Visibility] - Assoc
Const Data - Assoc
Kind - Assoc
Type Data - Bound
VarIndex Kind - Okay, we do something fun for
Boundtypes/regions/consts: Specifically, we distinguish between canonically bound things andfor<>bound things. And, really, it comes down to caching during canonicalization and instantiation. - Ctor
Kind - What kind of constructor something is.
- CtorOf
- Encodes if a
DefKind::Ctoris the constructor of an enum variant or a struct. - Extern
Abi - ABI we expect to see within
extern "{abi}" - FloatTy
- Impl
Trait InTrait Data - Useful source information about where a desugared associated type for an RPITIT originated from.
- InferTy
- A placeholder for a type that hasn’t been inferred yet.
- Inline
Attr - IntTy
- Mutability
- RDef
Kind - What kind of definition something is; e.g.,
modvsstruct.enum DefPathDatamay need to be updated if a new variant is added here. - Safety
- Solver
Trait Lang Item - UintTy
- Variance
Constants§
- SYNTHETIC_
CRATE_ NAME - The crate name under which synthetic items are exported under.
Traits§
- Binder
Variances - Lets types declare how to compute the variance of bound parameters.
- ItemId
- The identifier of an item; generalizes over rustc’s
DefIdto allow for virtual items. - Subst
Binder - ToPoly
Trait Ref
Functions§
- alias_
ty_ kind_ def_ id - assoc_
items_ of - The associated items of the trait or inherent impl that owns
s, in definition order. - assoc_
tys_ for_ trait - Generates a list of
<trait_ref>::Tytype aliases for each non-gat associated type of the given trait and its parents, in a specific order. - bits_
and_ type_ to_ float_ constant_ literal - Converts a bit-representation of a float of type
tyto a constant literal - can_
have_ generics - Whether the item can have generic parameters.
- closure_
sig - Retrieve a closure’s signature.
- compute_
unsizing_ metadata - const_
reader - The reader for constants evaluated in the current context.
- drop_
glue_ shim - dyn_
self_ ty - Generates a
dyn Trait<Args.., Ty = <Self as Trait>::Ty..>type for the given trait ref. - erase_
and_ norm - erase_
free_ regions - Erase free regions from the given value. Largely copied from
tcx.erase_and_anonymize_regions, but also erases bound regions that are bound outsidevalue, so we can call this function inside aBinder. - fn_
sig_ bound_ region_ variances - Computes the variance of each region bound by
sig. - gen_
vtable_ sig - The vtable signature of the method, along with the state of its container.
- get_
def_ kind - Gets the kind of the definition. Can’t use
def_kinddirectly because this crashes on the crate root. - get_
foreign_ mod_ children - Gets the children of an
externblock. Empty if the block is not defined in the current crate. - get_
implied_ predicates - get_
method_ sig - The signature of a method impl may be a subtype of the one expected from the trait decl, as in the example below. For correctness, we must be able to map from the method generics declared in the trait to the actual method generics. Because this would require type inference, we instead simply return the declared signature. This will cause issues if it is possible to use such a more-specific implementation with its more-specific type, but we have a few other issues with lifetime-generic function pointers anyway so this is unlikely to cause problems.
- get_
mod_ children - Gets the children of a module.
- get_
param_ env - get_
self_ predicate - get_
trait_ decl_ dyn_ self_ ty - Generates a
dyn Trait<Args.., Ty = <Self as Trait>::Ty..>type for this trait. - get_
variant_ kind - identity_
args_ with_ inferred - Closures and inline consts have special type params that are used as inference variables. After
analysis, they can be computed from the rest of the args (modulo some erased regions). This
computes the identity args for this
def_idwith the inference ars properly inferred. - inst_
binder - Instantiate this binder with the provided args. Use
Noneif the args are known to be the identity args. - late_
bound_ for_ def - lifetime_
param_ name - local_
names - match_
region_ args - Takes two values that differ only in their regions, where
templatehas placeholder regions used each once in the places that they differ. Returns a mapping from those placeholders to the corresponding regions inactual. - normalize
- Normalize a value.
- read_
const - Evaluate
srcand read it back as aConstantExpr. - resolve_
for_ dyn - scalar_
int_ to_ constant_ literal - self_
clause_ for_ item - Retrieve the
Self: Traitclause for a trait associated item. - self_
predicate - The special “self” predicate on a trait.
- self_
trait_ ref - solve_
copy - Solve the
T: Copypredicate. - solve_
destruct - Solve the
T: Destructpredicate. - solve_
item_ implied_ traits - Solve the trait obligations for implementing a trait (or for trait associated type bounds) in the current context.
- solve_
item_ traits_ inner - Apply the given generics to the provided clauses and resolve the trait references in the current context.
- solve_
sized - Solve the
T: Sizedpredicate. - solve_
trait - This is the entrypoint of the solving.
- substitute
- Instantiate this value with the provided args. Use
Noneif the args are known to be the identity args. - super_
clause_ to_ clause_ and_ trait_ proof - Given a clause
clausein the context of some impl blockimpl_did, susbts correctlySelffromclauseand (1) derive aClauseand (2) resolve aTraitProof. - translate_
full_ def - Construct the
FullDeffor this item. IfargsisSome, the returnedFullDefwill be instantiated with the provided generics. - translate_
full_ def_ kind - Construct the
FullDefKindfor this item. - translate_
item_ ref - Translate a reference to an item, resolving the appropriate trait clauses as needed.
- translate_
mir_ const - Translate a MIR constant.
- translate_
user_ annotation - Convert a type annotation into data we can use, by fetching the types that rustc inferred and gathering the predicates that still need to be checked at borrowck time.
- type_
alias_ trait_ clauses - Collects the trait clauses needed to make a type alias well-formed, as Rust itself does not require type aliases to declare the clauses they use.
- type_
param_ name - unerase_
lifetimes - Replace each erased region in this value with a fresh placeholder region.
- unsizing_
metadata - The metadata of a pointer to a value of type
fromunsized to typeto. - vtable_
sig_ with_ dyn_ self - The signature of
method_declas stored in a vtable, i.e. with itsSelftype replaced by the givendyn Trait<..>type.
Type Aliases§
- Canonical
User Type - Reflects [
ty::CanonicalUserType] - HashMap
- Type alias for a hash map that uses the Fx hashing algorithm.
- Ident
- Reflects [
rustc_span::symbol::Ident] - Placeholder
Const - Reflects [
ty::PlaceholderConst] - Placeholder
Ty - Reflects [
ty::PlaceholderType] - Poly
FnSig - Reflects [
ty::PolyFnSig] - Predicate
Searcher - Region
Outlives Predicate - Reflects [
ty::RegionOutlivesPredicate] - Trait
Ref - Reflects [
ty::TraitRef] Contains the def_id and arguments passed to the trait. The first type argument is theSelftype. The trait proofs are the required predicate for this trait; currently they are always empty because we consider all trait predicates as implied.self.in_traitis alwaysNonebecause a trait can’t be associated to another one. - Type
Outlives Predicate - Reflects [
ty::TypeOutlivesPredicate] - Unit
Binder - User
Annotation - The data of a user annotation, bound in an existentially-quantified binder.
- User
Annotation Data - The data of a user annotation: for each used projection we get the type of the corresponding place, and we record outlives predicates that must hold. The first vec matches the input list of projections, the second is free-form.
- User
Annotation Proj - Denotes a subplace of a user annotation, e.g. in
let Foo { x, .. }: Self = ...;the annotation will have a projection forx. - Placeholder
Region - Region