Skip to main content

Module solve

Module solve 

Source
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 Trait or T: [const] Trait.
eval_ctxt πŸ”’
inspect
normalizes_to πŸ”’
project_goals πŸ”’
search_graph πŸ”’
trait_goals πŸ”’
Dealing with trait goals, i.e. T: Trait<'a, U>.

StructsΒ§

AccessedOpaques
ExternalConstraintsData
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.
GoalEvaluation
The result of evaluating a goal.
GoalStalledOn
The conditions that must change for a goal to warrant
MaybeInfo
NestedNormalizationGoals
NoSolution
QueryInput
RerunNonErased
A bit like NoSolution, but for functions that normally cannot fail unless they accessed opaues. (See TypingMode::ErasedNotCoherence). Getting OpaquesAccessed doesn’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 returning NoSolution if that’s fastest. This is okay because when you get OpaquesAccessed we’re guaranteed that we’re going to retry this query in the original typing mode to get the correct answer.
Response

EnumsΒ§

AdtDestructorKind
Indicates that a impl Drop for Adt is const or not.
AliasBoundKind
BuiltinImplSource
CandidatePreferenceMode
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.
CandidateSource
Possible ways the given goal can be proven.
Certainty
ComputeGoalFastPathOutcome
For some goals we can trivially answer some questions without going through canonicalization. There are three options:
ExternalRegionConstraints
FetchEligibleAssocItemResponse
GoalSource
Why a specific goal has to be proven.
GoalStalledOnOpaques
HasChanged
Whether evaluating this goal ended up changing the inference state.
IsIdentity
The variant order here matters for the PartialOrd/Ord impls.
MaybeCause
Why we failed to evaluate a goal.
NoSolutionOrRerunNonErased
OpaqueTypesJank
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.
ParamEnvSource
RerunCondition
Information about how we accessed opaque types This is what the trait solver does when each states is encountered:
RerunReason
Mainly for debugging, to keep track of the source of the rerunning in TypingMode::ErasedNotCoherence.
SizedTraitKind
Which sizedness trait - Sized, MetaSized? PointeeSized is omitted as it is removed during lowering.
SmallCopySet
A small set of up to 3 Copy elements, used as an optimization in RerunCondition. The entire set can be Copyed because of this requirement.
StalledOnCoroutines
SucceededInErased
TyOrConstInferVar
Helper for InferCtxt::ty_or_const_infer_var_changed (see comment on that), used for traits::fulfill’s list of stalled_on inference variables and for merging ambiguity errors caused by the same inference variable during error reporting.
VisibleForLeakCheck
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. Unreachable is 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Β§

RerunResultExt

FunctionsΒ§

flatten_answer_tree
Flatten the Condition tree into a conjunction of predicates.
has_no_inference_or_external_constraints πŸ”’
has_only_region_constraints πŸ”’

Type AliasesΒ§

CanonicalInputData
CanonicalResponse
QueryResult
The result of evaluating a canonical query.
QueryResultOrRerunNonErased