Expand description
The next-generation trait solver, currently still WIP.
As a user of rust, you can use -Znext-solver to enable the new trait solver.
As a developer of rustc, you shouldnβt be using the new trait
solver without asking the trait-system-refactor-initiative, but it can
be enabled with InferCtxtBuilder::with_next_trait_solver. This will
ensure that trait solving using that inference context will be routed
to the new trait solver.
For a high-level overview of how this solver works, check out the relevant section of the rustc-dev-guide.
Re-exportsΒ§
use derive_where::derive_where;πuse rustc_type_ir::lang_items::SolverTraitLangItem;πuse rustc_type_ir::transmute::Condition;πuse rustc_type_ir as ty;πuse rustc_type_ir::Const;πuse rustc_type_ir::Interner;πuse rustc_type_ir::Region;πuse rustc_type_ir::TraitClause;πuse rustc_type_ir::TypeVisitableExt;πuse rustc_type_ir::Upcast;πuse thin_vec::ThinVec;πuse thin_vec::thin_vec;πuse tracing::instrument;πuse tracing::instrument;πpub use self::eval_ctxt::EvalCtxt;pub use self::eval_ctxt::GenerateProofTree;pub use self::eval_ctxt::SolverDelegateEvalExt;pub use self::eval_ctxt::evaluate_root_goal_for_proof_tree_raw_provider;pub use self::eval_ctxt::fast_path;use crate::delegate::SolverDelegate;πuse crate::solve::assembly::Candidate;πuse rustc_type_ir::inherent::*;π
ModulesΒ§
- assembly π
- Code shared by trait and projection goals for candidate assembly.
- effect_
goals π - Dealing with host effect goals, i.e. enforcing the constness in
T: const TraitorT: [const] Trait. - eval_
ctxt π - inspect
- normalizes_
to π - project_
goals π - search_
graph π - trait_
goals π - Dealing with trait goals, i.e.
T: Trait<'a, U>.
StructsΒ§
- Accessed
Opaques - External
Constraints Data - Additional constraints returned on success.
- Goal
- A goal is a statement, i.e.
predicate, we want to prove given some assumptions, i.e.param_env. - Goal
Evaluation - The result of evaluating a goal.
- Goal
Stalled On - The conditions that must change for a goal to warrant
- Maybe
Info - Nested
Normalization Goals - NoSolution
- Query
Input - Rerun
NonErased - A bit like
NoSolution, but for functions that normally cannot fail unless they accessed opaues. (SeeTypingMode::ErasedNotCoherence). GettingOpaquesAccesseddoesnβt mean there truly is no solution. It just means that we want to bail out of the current query as fast as possible, possibly by returningNoSolutionif thatβs fastest. This is okay because when you getOpaquesAccessedweβre guaranteed that weβre going to retry this query in the original typing mode to get the correct answer. - Response
EnumsΒ§
- AdtDestructor
Kind - Indicates that a
impl Drop for Adtisconstor not. - Alias
Bound Kind - Builtin
Impl Source - Candidate
Preference Mode - Which trait candidates should be preferred over other candidates? By default, prefer where bounds over alias bounds. For marker traits, prefer alias bounds over where bounds.
- Candidate
Source - Possible ways the given goal can be proven.
- Certainty
- Compute
Goal Fast Path Outcome - For some goals we can trivially answer some questions without going through canonicalization. There are three options:
- External
Region Constraints - Fetch
Eligible Assoc Item Response - Goal
Source - Why a specific goal has to be proven.
- Goal
Stalled OnOpaques - HasChanged
- Whether evaluating this goal ended up changing the inference state.
- IsIdentity
- The variant order here matters for the
PartialOrd/Ordimpls. - Maybe
Cause - Why we failed to evaluate a goal.
- NoSolution
OrRerun NonErased - Opaque
Types Jank - Supporting not-yet-defined opaque types in HIR typeck is somewhat challenging. Ideally weβd normalize them to a new inference variable and just defer type inference which relies on the opaque until weβve constrained the hidden type.
- Param
EnvSource - Rerun
Condition - Information about how we accessed opaque types This is what the trait solver does when each states is encountered:
- Rerun
Reason - Mainly for debugging, to keep track of the source of the rerunning
in
TypingMode::ErasedNotCoherence. - Sized
Trait Kind - Which sizedness trait -
Sized,MetaSized?PointeeSizedis omitted as it is removed during lowering. - Small
Copy Set - A small set of up to 3
Copyelements, used as an optimization inRerunCondition. The entire set can beCopyed because of this requirement. - Stalled
OnCoroutines - Succeeded
InErased - TyOr
Const Infer Var - Helper for
InferCtxt::ty_or_const_infer_var_changed(see comment on that), used fortraits::fulfillβs list ofstalled_oninference variables and for merging ambiguity errors caused by the same inference variable during error reporting. - Visible
ForLeak Check - Whether the given region constraint should be considered/ignored for
leak check. In most part of the compiler, this should be
Yes, except for applying constraints from the nested goals in next-solver.Unreachableis used in places in which leak check isnβt done, e.g. borrowck.
ConstantsΒ§
- FIXPOINT_
STEP_ πLIMIT - How many fixpoint iterations we should attempt inside of the solver before bailing with overflow.
TraitsΒ§
FunctionsΒ§
- flatten_
answer_ tree - Flatten the
Conditiontree into a conjunction of predicates. - has_
no_ πinference_ or_ external_ constraints - has_
only_ πregion_ constraints
Type AliasesΒ§
- Canonical
Input Data - Canonical
Response - Query
Result - The result of evaluating a canonical query.
- Query
Result OrRerun NonErased