1
Fork 0

inspect: strongly typed CandidateKind

This commit is contained in:
lcnr 2023-09-11 11:34:57 +02:00
parent 006d599435
commit 8225a2e9ec
11 changed files with 155 additions and 121 deletions

View file

@ -9,6 +9,9 @@ use crate::ty::{
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable,
TypeVisitor, TypeVisitor,
}; };
use rustc_span::def_id::DefId;
use super::BuiltinImplSource;
mod cache; mod cache;
pub mod inspect; pub mod inspect;
@ -235,3 +238,63 @@ pub enum IsNormalizesToHack {
Yes, Yes,
No, No,
} }
/// Possible ways the given goal can be proven.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CandidateSource {
/// A user written impl.
///
/// ## Examples
///
/// ```rust
/// fn main() {
/// let x: Vec<u32> = Vec::new();
/// // This uses the impl from the standard library to prove `Vec<T>: Clone`.
/// let y = x.clone();
/// }
/// ```
Impl(DefId),
/// A builtin impl generated by the compiler. When adding a new special
/// trait, try to use actual impls whenever possible. Builtin impls should
/// only be used in cases where the impl cannot be manually be written.
///
/// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
/// For a list of all traits with builtin impls, check out the
/// `EvalCtxt::assemble_builtin_impl_candidates` method.
BuiltinImpl(BuiltinImplSource),
/// An assumption from the environment.
///
/// More precisely we've used the `n-th` assumption in the `param_env`.
///
/// ## Examples
///
/// ```rust
/// fn is_clone<T: Clone>(x: T) -> (T, T) {
/// // This uses the assumption `T: Clone` from the `where`-bounds
/// // to prove `T: Clone`.
/// (x.clone(), x)
/// }
/// ```
ParamEnv(usize),
/// If the self type is an alias type, e.g. an opaque type or a projection,
/// we know the bounds on that alias to hold even without knowing its concrete
/// underlying type.
///
/// More precisely this candidate is using the `n-th` bound in the `item_bounds` of
/// the self type.
///
/// ## Examples
///
/// ```rust
/// trait Trait {
/// type Assoc: Clone;
/// }
///
/// fn foo<T: Trait>(x: <T as Trait>::Assoc) {
/// // We prove `<T as Trait>::Assoc` by looking at the bounds on `Assoc` in
/// // in the trait definition.
/// let _y = x.clone();
/// }
/// ```
AliasBound,
}

View file

@ -1,5 +1,6 @@
use super::{ use super::{
CanonicalInput, Certainty, Goal, IsNormalizesToHack, NoSolution, QueryInput, QueryResult, CandidateSource, CanonicalInput, Certainty, Goal, IsNormalizesToHack, NoSolution, QueryInput,
QueryResult,
}; };
use crate::ty; use crate::ty;
use format::ProofTreeFormatter; use format::ProofTreeFormatter;
@ -7,13 +8,13 @@ use std::fmt::{Debug, Write};
mod format; mod format;
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Debug, Eq, PartialEq)]
pub enum CacheHit { pub enum CacheHit {
Provisional, Provisional,
Global, Global,
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub struct GoalEvaluation<'tcx> { pub struct GoalEvaluation<'tcx> {
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>, pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
pub is_normalizes_to_hack: IsNormalizesToHack, pub is_normalizes_to_hack: IsNormalizesToHack,
@ -21,14 +22,14 @@ pub struct GoalEvaluation<'tcx> {
pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>, pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub struct CanonicalGoalEvaluation<'tcx> { pub struct CanonicalGoalEvaluation<'tcx> {
pub goal: CanonicalInput<'tcx>, pub goal: CanonicalInput<'tcx>,
pub kind: GoalEvaluationKind<'tcx>, pub kind: GoalEvaluationKind<'tcx>,
pub result: QueryResult<'tcx>, pub result: QueryResult<'tcx>,
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub enum GoalEvaluationKind<'tcx> { pub enum GoalEvaluationKind<'tcx> {
CacheHit(CacheHit), CacheHit(CacheHit),
Uncached { revisions: Vec<GoalEvaluationStep<'tcx>> }, Uncached { revisions: Vec<GoalEvaluationStep<'tcx>> },
@ -39,13 +40,13 @@ impl Debug for GoalEvaluation<'_> {
} }
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub struct AddedGoalsEvaluation<'tcx> { pub struct AddedGoalsEvaluation<'tcx> {
pub evaluations: Vec<Vec<GoalEvaluation<'tcx>>>, pub evaluations: Vec<Vec<GoalEvaluation<'tcx>>>,
pub result: Result<Certainty, NoSolution>, pub result: Result<Certainty, NoSolution>,
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub struct GoalEvaluationStep<'tcx> { pub struct GoalEvaluationStep<'tcx> {
pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>, pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
@ -55,24 +56,28 @@ pub struct GoalEvaluationStep<'tcx> {
pub result: QueryResult<'tcx>, pub result: QueryResult<'tcx>,
} }
#[derive(Eq, PartialEq, Hash, HashStable)] #[derive(Eq, PartialEq)]
pub struct GoalCandidate<'tcx> { pub struct GoalCandidate<'tcx> {
pub added_goals_evaluations: Vec<AddedGoalsEvaluation<'tcx>>, pub added_goals_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
pub candidates: Vec<GoalCandidate<'tcx>>, pub candidates: Vec<GoalCandidate<'tcx>>,
pub kind: CandidateKind<'tcx>, pub kind: ProbeKind<'tcx>,
} }
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Debug, PartialEq, Eq)]
pub enum CandidateKind<'tcx> { pub enum ProbeKind<'tcx> {
/// Probe entered when normalizing the self ty during candidate assembly /// Probe entered when normalizing the self ty during candidate assembly
NormalizedSelfTyAssembly, NormalizedSelfTyAssembly,
/// A normal candidate for proving a goal /// Some candidate to prove the current goal.
Candidate { name: String, result: QueryResult<'tcx> }, ///
/// FIXME: Remove this in favor of always using more strongly typed variants.
MiscCandidate { name: &'static str, result: QueryResult<'tcx> },
/// A candidate for proving a trait or alias-relate goal.
TraitCandidate { source: CandidateSource, result: QueryResult<'tcx> },
/// Used in the probe that wraps normalizing the non-self type for the unsize /// Used in the probe that wraps normalizing the non-self type for the unsize
/// trait, which is also structurally matched on. /// trait, which is also structurally matched on.
UnsizeAssembly, UnsizeAssembly,
/// During upcasting from some source object to target object type, used to /// During upcasting from some source object to target object type, used to
/// do a probe to find out what projection type(s) may be used to prove that /// do a probe to find out what projection type(s) may be used to prove that
/// the source type upholds all of the target type's object bounds. /// the source type upholds all of the target type's object bounds.
UpcastProbe, UpcastProjectionCompatibility,
} }

View file

@ -102,18 +102,21 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result { pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
match &candidate.kind { match &candidate.kind {
CandidateKind::NormalizedSelfTyAssembly => { ProbeKind::NormalizedSelfTyAssembly => {
writeln!(self.f, "NORMALIZING SELF TY FOR ASSEMBLY:") writeln!(self.f, "NORMALIZING SELF TY FOR ASSEMBLY:")
} }
CandidateKind::UnsizeAssembly => { ProbeKind::UnsizeAssembly => {
writeln!(self.f, "ASSEMBLING CANDIDATES FOR UNSIZING:") writeln!(self.f, "ASSEMBLING CANDIDATES FOR UNSIZING:")
} }
CandidateKind::UpcastProbe => { ProbeKind::UpcastProjectionCompatibility => {
writeln!(self.f, "PROBING FOR PROJECTION COMPATIBILITY FOR UPCASTING:") writeln!(self.f, "PROBING FOR PROJECTION COMPATIBILITY FOR UPCASTING:")
} }
CandidateKind::Candidate { name, result } => { ProbeKind::MiscCandidate { name, result } => {
writeln!(self.f, "CANDIDATE {name}: {result:?}") writeln!(self.f, "CANDIDATE {name}: {result:?}")
} }
ProbeKind::TraitCandidate { source, result } => {
writeln!(self.f, "CANDIDATE {source:?}: {result:?}")
}
}?; }?;
self.nested(|this| { self.nested(|this| {

View file

@ -125,7 +125,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
direction: ty::AliasRelationDirection, direction: ty::AliasRelationDirection,
invert: Invert, invert: Invert,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
self.probe_candidate("normalizes-to").enter(|ecx| { self.probe_misc_candidate("normalizes-to").enter(|ecx| {
ecx.normalizes_to_inner(param_env, alias, other, direction, invert)?; ecx.normalizes_to_inner(param_env, alias, other, direction, invert)?;
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}) })
@ -175,7 +175,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
alias_rhs: ty::AliasTy<'tcx>, alias_rhs: ty::AliasTy<'tcx>,
direction: ty::AliasRelationDirection, direction: ty::AliasRelationDirection,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
self.probe_candidate("args relate").enter(|ecx| { self.probe_misc_candidate("args relate").enter(|ecx| {
match direction { match direction {
ty::AliasRelationDirection::Equate => { ty::AliasRelationDirection::Equate => {
ecx.eq(param_env, alias_lhs, alias_rhs)?; ecx.eq(param_env, alias_lhs, alias_rhs)?;
@ -196,7 +196,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
rhs: ty::Term<'tcx>, rhs: ty::Term<'tcx>,
direction: ty::AliasRelationDirection, direction: ty::AliasRelationDirection,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
self.probe_candidate("bidir normalizes-to").enter(|ecx| { self.probe_misc_candidate("bidir normalizes-to").enter(|ecx| {
ecx.normalizes_to_inner( ecx.normalizes_to_inner(
param_env, param_env,
lhs.to_alias_ty(ecx.tcx()).unwrap(), lhs.to_alias_ty(ecx.tcx()).unwrap(),

View file

@ -5,8 +5,10 @@ use crate::traits::coherence;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::Reveal; use rustc_infer::traits::Reveal;
use rustc_middle::traits::solve::inspect::CandidateKind; use rustc_middle::traits::solve::inspect::ProbeKind;
use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult}; use rustc_middle::traits::solve::{
CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
};
use rustc_middle::traits::BuiltinImplSource; use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams}; use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -27,66 +29,6 @@ pub(super) struct Candidate<'tcx> {
pub(super) result: CanonicalResponse<'tcx>, pub(super) result: CanonicalResponse<'tcx>,
} }
/// Possible ways the given goal can be proven.
#[derive(Debug, Clone, Copy)]
pub(super) enum CandidateSource {
/// A user written impl.
///
/// ## Examples
///
/// ```rust
/// fn main() {
/// let x: Vec<u32> = Vec::new();
/// // This uses the impl from the standard library to prove `Vec<T>: Clone`.
/// let y = x.clone();
/// }
/// ```
Impl(DefId),
/// A builtin impl generated by the compiler. When adding a new special
/// trait, try to use actual impls whenever possible. Builtin impls should
/// only be used in cases where the impl cannot be manually be written.
///
/// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
/// For a list of all traits with builtin impls, check out the
/// [`EvalCtxt::assemble_builtin_impl_candidates`] method. Not
BuiltinImpl(BuiltinImplSource),
/// An assumption from the environment.
///
/// More precisely we've used the `n-th` assumption in the `param_env`.
///
/// ## Examples
///
/// ```rust
/// fn is_clone<T: Clone>(x: T) -> (T, T) {
/// // This uses the assumption `T: Clone` from the `where`-bounds
/// // to prove `T: Clone`.
/// (x.clone(), x)
/// }
/// ```
ParamEnv(usize),
/// If the self type is an alias type, e.g. an opaque type or a projection,
/// we know the bounds on that alias to hold even without knowing its concrete
/// underlying type.
///
/// More precisely this candidate is using the `n-th` bound in the `item_bounds` of
/// the self type.
///
/// ## Examples
///
/// ```rust
/// trait Trait {
/// type Assoc: Clone;
/// }
///
/// fn foo<T: Trait>(x: <T as Trait>::Assoc) {
/// // We prove `<T as Trait>::Assoc` by looking at the bounds on `Assoc` in
/// // in the trait definition.
/// let _y = x.clone();
/// }
/// ```
AliasBound,
}
/// Methods used to assemble candidates for either trait or projection goals. /// Methods used to assemble candidates for either trait or projection goals.
pub(super) trait GoalKind<'tcx>: pub(super) trait GoalKind<'tcx>:
TypeFoldable<TyCtxt<'tcx>> + Copy + Eq + std::fmt::Display TypeFoldable<TyCtxt<'tcx>> + Copy + Eq + std::fmt::Display
@ -399,7 +341,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
let &ty::Alias(_, projection_ty) = goal.predicate.self_ty().kind() else { return }; let &ty::Alias(_, projection_ty) = goal.predicate.self_ty().kind() else { return };
candidates.extend(self.probe(|_| CandidateKind::NormalizedSelfTyAssembly).enter(|ecx| { candidates.extend(self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
if num_steps < ecx.local_overflow_limit() { if num_steps < ecx.local_overflow_limit() {
let normalized_ty = ecx.next_ty_infer(); let normalized_ty = ecx.next_ty_infer();
let normalizes_to_goal = goal.with( let normalizes_to_goal = goal.with(
@ -910,7 +852,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
SolverMode::Coherence => {} SolverMode::Coherence => {}
}; };
let result = self.probe_candidate("coherence unknowable").enter(|ecx| { let result = self.probe_misc_candidate("coherence unknowable").enter(|ecx| {
let trait_ref = goal.predicate.trait_ref(tcx); let trait_ref = goal.predicate.trait_ref(tcx);
#[derive(Debug)] #[derive(Debug)]

View file

@ -920,7 +920,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
if candidate_key.def_id != key.def_id { if candidate_key.def_id != key.def_id {
continue; continue;
} }
values.extend(self.probe_candidate("opaque type storage").enter(|ecx| { values.extend(self.probe_misc_candidate("opaque type storage").enter(|ecx| {
for (a, b) in std::iter::zip(candidate_key.args, key.args) { for (a, b) in std::iter::zip(candidate_key.args, key.args) {
ecx.eq(param_env, a, b)?; ecx.eq(param_env, a, b)?;
} }

View file

@ -1,5 +1,5 @@
use super::EvalCtxt; use super::EvalCtxt;
use rustc_middle::traits::solve::{inspect, QueryResult}; use rustc_middle::traits::solve::{inspect, CandidateSource, QueryResult};
use std::marker::PhantomData; use std::marker::PhantomData;
pub(in crate::solve) struct ProbeCtxt<'me, 'a, 'tcx, F, T> { pub(in crate::solve) struct ProbeCtxt<'me, 'a, 'tcx, F, T> {
@ -10,7 +10,7 @@ pub(in crate::solve) struct ProbeCtxt<'me, 'a, 'tcx, F, T> {
impl<'tcx, F, T> ProbeCtxt<'_, '_, 'tcx, F, T> impl<'tcx, F, T> ProbeCtxt<'_, '_, 'tcx, F, T>
where where
F: FnOnce(&T) -> inspect::CandidateKind<'tcx>, F: FnOnce(&T) -> inspect::ProbeKind<'tcx>,
{ {
pub(in crate::solve) fn enter(self, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> T) -> T { pub(in crate::solve) fn enter(self, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> T) -> T {
let ProbeCtxt { ecx: outer_ecx, probe_kind, _result } = self; let ProbeCtxt { ecx: outer_ecx, probe_kind, _result } = self;
@ -28,8 +28,8 @@ where
}; };
let r = nested_ecx.infcx.probe(|_| f(&mut nested_ecx)); let r = nested_ecx.infcx.probe(|_| f(&mut nested_ecx));
if !outer_ecx.inspect.is_noop() { if !outer_ecx.inspect.is_noop() {
let cand_kind = probe_kind(&r); let probe_kind = probe_kind(&r);
nested_ecx.inspect.candidate_kind(cand_kind); nested_ecx.inspect.probe_kind(probe_kind);
outer_ecx.inspect.goal_candidate(nested_ecx.inspect); outer_ecx.inspect.goal_candidate(nested_ecx.inspect);
} }
r r
@ -41,25 +41,45 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
/// as expensive as necessary to output the desired information. /// as expensive as necessary to output the desired information.
pub(in crate::solve) fn probe<F, T>(&mut self, probe_kind: F) -> ProbeCtxt<'_, 'a, 'tcx, F, T> pub(in crate::solve) fn probe<F, T>(&mut self, probe_kind: F) -> ProbeCtxt<'_, 'a, 'tcx, F, T>
where where
F: FnOnce(&T) -> inspect::CandidateKind<'tcx>, F: FnOnce(&T) -> inspect::ProbeKind<'tcx>,
{ {
ProbeCtxt { ecx: self, probe_kind, _result: PhantomData } ProbeCtxt { ecx: self, probe_kind, _result: PhantomData }
} }
pub(in crate::solve) fn probe_candidate( pub(in crate::solve) fn probe_misc_candidate(
&mut self, &mut self,
name: &'static str, name: &'static str,
) -> ProbeCtxt< ) -> ProbeCtxt<
'_, '_,
'a, 'a,
'tcx, 'tcx,
impl FnOnce(&QueryResult<'tcx>) -> inspect::CandidateKind<'tcx>, impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>,
QueryResult<'tcx>, QueryResult<'tcx>,
> { > {
ProbeCtxt { ProbeCtxt {
ecx: self, ecx: self,
probe_kind: move |result: &QueryResult<'tcx>| inspect::CandidateKind::Candidate { probe_kind: move |result: &QueryResult<'tcx>| inspect::ProbeKind::MiscCandidate {
name: name.to_string(), name,
result: *result,
},
_result: PhantomData,
}
}
pub(in crate::solve) fn probe_trait_candidate(
&mut self,
source: CandidateSource,
) -> ProbeCtxt<
'_,
'a,
'tcx,
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>,
QueryResult<'tcx>,
> {
ProbeCtxt {
ecx: self,
probe_kind: move |result: &QueryResult<'tcx>| inspect::ProbeKind::TraitCandidate {
source,
result: *result, result: *result,
}, },
_result: PhantomData, _result: PhantomData,

View file

@ -4,14 +4,14 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt};
use rustc_infer::traits::{ use rustc_infer::traits::{
Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult, TraitEngine, Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult, TraitEngine,
}; };
use rustc_middle::traits::solve::{CanonicalInput, Certainty, Goal}; use rustc_middle::traits::solve::{CandidateSource, CanonicalInput, Certainty, Goal};
use rustc_middle::traits::{ use rustc_middle::traits::{
BuiltinImplSource, ImplSource, ImplSourceUserDefinedData, ObligationCause, SelectionError, BuiltinImplSource, ImplSource, ImplSourceUserDefinedData, ObligationCause, SelectionError,
}; };
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use crate::solve::assembly::{Candidate, CandidateSource}; use crate::solve::assembly::Candidate;
use crate::solve::eval_ctxt::{EvalCtxt, GenerateProofTree}; use crate::solve::eval_ctxt::{EvalCtxt, GenerateProofTree};
use crate::solve::inspect::ProofTreeBuilder; use crate::solve::inspect::ProofTreeBuilder;
use crate::traits::StructurallyNormalizeExt; use crate::traits::StructurallyNormalizeExt;

View file

@ -1,5 +1,5 @@
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::traits::solve::inspect::{self, CacheHit, CandidateKind}; use rustc_middle::traits::solve::inspect::{self, CacheHit, ProbeKind};
use rustc_middle::traits::solve::{ use rustc_middle::traits::solve::{
CanonicalInput, Certainty, Goal, IsNormalizesToHack, QueryInput, QueryResult, CanonicalInput, Certainty, Goal, IsNormalizesToHack, QueryInput, QueryResult,
}; };
@ -9,7 +9,7 @@ use rustc_session::config::DumpSolverProofTree;
use super::eval_ctxt::UseGlobalCache; use super::eval_ctxt::UseGlobalCache;
use super::GenerateProofTree; use super::GenerateProofTree;
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Eq, PartialEq, Debug)]
pub struct WipGoalEvaluation<'tcx> { pub struct WipGoalEvaluation<'tcx> {
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>, pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
pub evaluation: Option<WipCanonicalGoalEvaluation<'tcx>>, pub evaluation: Option<WipCanonicalGoalEvaluation<'tcx>>,
@ -28,7 +28,7 @@ impl<'tcx> WipGoalEvaluation<'tcx> {
} }
} }
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Eq, PartialEq, Debug)]
pub struct WipCanonicalGoalEvaluation<'tcx> { pub struct WipCanonicalGoalEvaluation<'tcx> {
pub goal: CanonicalInput<'tcx>, pub goal: CanonicalInput<'tcx>,
pub cache_hit: Option<CacheHit>, pub cache_hit: Option<CacheHit>,
@ -56,7 +56,7 @@ impl<'tcx> WipCanonicalGoalEvaluation<'tcx> {
} }
} }
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Eq, PartialEq, Debug)]
pub struct WipAddedGoalsEvaluation<'tcx> { pub struct WipAddedGoalsEvaluation<'tcx> {
pub evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>, pub evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>,
pub result: Option<Result<Certainty, NoSolution>>, pub result: Option<Result<Certainty, NoSolution>>,
@ -77,7 +77,7 @@ impl<'tcx> WipAddedGoalsEvaluation<'tcx> {
} }
} }
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Eq, PartialEq, Debug)]
pub struct WipGoalEvaluationStep<'tcx> { pub struct WipGoalEvaluationStep<'tcx> {
pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>, pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
@ -102,11 +102,11 @@ impl<'tcx> WipGoalEvaluationStep<'tcx> {
} }
} }
#[derive(Eq, PartialEq, Debug, Hash, HashStable)] #[derive(Eq, PartialEq, Debug)]
pub struct WipGoalCandidate<'tcx> { pub struct WipGoalCandidate<'tcx> {
pub added_goals_evaluations: Vec<WipAddedGoalsEvaluation<'tcx>>, pub added_goals_evaluations: Vec<WipAddedGoalsEvaluation<'tcx>>,
pub candidates: Vec<WipGoalCandidate<'tcx>>, pub candidates: Vec<WipGoalCandidate<'tcx>>,
pub kind: Option<CandidateKind<'tcx>>, pub kind: Option<ProbeKind<'tcx>>,
} }
impl<'tcx> WipGoalCandidate<'tcx> { impl<'tcx> WipGoalCandidate<'tcx> {
@ -357,11 +357,11 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
}) })
} }
pub fn candidate_kind(&mut self, candidate_kind: CandidateKind<'tcx>) { pub fn probe_kind(&mut self, probe_kind: ProbeKind<'tcx>) {
if let Some(this) = self.as_mut() { if let Some(this) = self.as_mut() {
match this { match this {
DebugSolver::GoalCandidate(this) => { DebugSolver::GoalCandidate(this) => {
assert_eq!(this.kind.replace(candidate_kind), None) assert_eq!(this.kind.replace(probe_kind), None)
} }
_ => unreachable!(), _ => unreachable!(),
} }

View file

@ -8,8 +8,9 @@ use rustc_hir::LangItem;
use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::specialization_graph::LeafDef; use rustc_infer::traits::specialization_graph::LeafDef;
use rustc_infer::traits::Reveal; use rustc_infer::traits::Reveal;
use rustc_middle::traits::solve::inspect::CandidateKind; use rustc_middle::traits::solve::{
use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult}; CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
};
use rustc_middle::traits::BuiltinImplSource; use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::ProjectionPredicate; use rustc_middle::ty::ProjectionPredicate;
@ -113,7 +114,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
if let Some(projection_pred) = assumption.as_projection_clause() { if let Some(projection_pred) = assumption.as_projection_clause() {
if projection_pred.projection_def_id() == goal.predicate.def_id() { if projection_pred.projection_def_id() == goal.predicate.def_id() {
let tcx = ecx.tcx(); let tcx = ecx.tcx();
ecx.probe_candidate("assumption").enter(|ecx| { ecx.probe_misc_candidate("assumption").enter(|ecx| {
let assumption_projection_pred = let assumption_projection_pred =
ecx.instantiate_binder_with_infer(projection_pred); ecx.instantiate_binder_with_infer(projection_pred);
ecx.eq( ecx.eq(
@ -155,7 +156,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
return Err(NoSolution); return Err(NoSolution);
} }
ecx.probe(|r| CandidateKind::Candidate { name: "impl".into(), result: *r }).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args); let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
@ -369,7 +370,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
let tcx = ecx.tcx(); let tcx = ecx.tcx();
ecx.probe_candidate("builtin pointee").enter(|ecx| { ecx.probe_misc_candidate("builtin pointee").enter(|ecx| {
let metadata_ty = match goal.predicate.self_ty().kind() { let metadata_ty = match goal.predicate.self_ty().kind() {
ty::Bool ty::Bool
| ty::Char | ty::Char
@ -578,7 +579,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
), ),
}; };
ecx.probe_candidate("builtin discriminant kind").enter(|ecx| { ecx.probe_misc_candidate("builtin discriminant kind").enter(|ecx| {
ecx.eq(goal.param_env, goal.predicate.term, discriminant_ty.into()) ecx.eq(goal.param_env, goal.predicate.term, discriminant_ty.into())
.expect("expected goal term to be fully unconstrained"); .expect("expected goal term to be fully unconstrained");
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

View file

@ -5,7 +5,7 @@ use super::{EvalCtxt, SolverMode};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{LangItem, Movability}; use rustc_hir::{LangItem, Movability};
use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::query::NoSolution;
use rustc_middle::traits::solve::inspect::CandidateKind; use rustc_middle::traits::solve::inspect::ProbeKind;
use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult}; use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult};
use rustc_middle::traits::{BuiltinImplSource, Reveal}; use rustc_middle::traits::{BuiltinImplSource, Reveal};
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
@ -61,7 +61,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
}, },
}; };
ecx.probe_candidate("impl").enter(|ecx| { ecx.probe_misc_candidate("impl").enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args); let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
@ -96,7 +96,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
&& trait_clause.polarity() == goal.predicate.polarity && trait_clause.polarity() == goal.predicate.polarity
{ {
// FIXME: Constness // FIXME: Constness
ecx.probe_candidate("assumption").enter(|ecx| { ecx.probe_misc_candidate("assumption").enter(|ecx| {
let assumption_trait_pred = ecx.instantiate_binder_with_infer(trait_clause); let assumption_trait_pred = ecx.instantiate_binder_with_infer(trait_clause);
ecx.eq( ecx.eq(
goal.param_env, goal.param_env,
@ -167,7 +167,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
let tcx = ecx.tcx(); let tcx = ecx.tcx();
ecx.probe_candidate("trait alias").enter(|ecx| { ecx.probe_misc_candidate("trait alias").enter(|ecx| {
let nested_obligations = tcx let nested_obligations = tcx
.predicates_of(goal.predicate.def_id()) .predicates_of(goal.predicate.def_id())
.instantiate(tcx, goal.predicate.trait_ref.args); .instantiate(tcx, goal.predicate.trait_ref.args);
@ -427,7 +427,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
ecx: &mut EvalCtxt<'_, 'tcx>, ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
ecx.probe(|_| CandidateKind::UnsizeAssembly).enter(|ecx| { ecx.probe(|_| ProbeKind::UnsizeAssembly).enter(|ecx| {
let a_ty = goal.predicate.self_ty(); let a_ty = goal.predicate.self_ty();
// We need to normalize the b_ty since it's destructured as a `dyn Trait`. // We need to normalize the b_ty since it's destructured as a `dyn Trait`.
let Some(b_ty) = let Some(b_ty) =
@ -491,7 +491,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
Err(NoSolution) => vec![], Err(NoSolution) => vec![],
}; };
ecx.probe(|_| CandidateKind::UnsizeAssembly).enter(|ecx| { ecx.probe(|_| ProbeKind::UnsizeAssembly).enter(|ecx| {
let a_ty = goal.predicate.self_ty(); let a_ty = goal.predicate.self_ty();
// We need to normalize the b_ty since it's matched structurally // We need to normalize the b_ty since it's matched structurally
// in the other functions below. // in the other functions below.
@ -597,7 +597,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
self.walk_vtable( self.walk_vtable(
a_principal.with_self_ty(tcx, a_ty), a_principal.with_self_ty(tcx, a_ty),
|ecx, new_a_principal, _, vtable_vptr_slot| { |ecx, new_a_principal, _, vtable_vptr_slot| {
if let Ok(resp) = ecx.probe_candidate("dyn upcast").enter(|ecx| { if let Ok(resp) = ecx.probe_misc_candidate("dyn upcast").enter(|ecx| {
ecx.consider_builtin_upcast_to_principal( ecx.consider_builtin_upcast_to_principal(
goal, goal,
a_data, a_data,
@ -640,7 +640,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
target_projection: ty::PolyExistentialProjection<'tcx>| { target_projection: ty::PolyExistentialProjection<'tcx>| {
source_projection.item_def_id() == target_projection.item_def_id() source_projection.item_def_id() == target_projection.item_def_id()
&& ecx && ecx
.probe(|_| CandidateKind::UpcastProbe) .probe(|_| ProbeKind::UpcastProjectionCompatibility)
.enter(|ecx| -> Result<(), NoSolution> { .enter(|ecx| -> Result<(), NoSolution> {
ecx.eq(param_env, source_projection, target_projection)?; ecx.eq(param_env, source_projection, target_projection)?;
let _ = ecx.try_evaluate_added_goals()?; let _ = ecx.try_evaluate_added_goals()?;
@ -918,7 +918,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
goal: Goal<'tcx, TraitPredicate<'tcx>>, goal: Goal<'tcx, TraitPredicate<'tcx>>,
constituent_tys: impl Fn(&EvalCtxt<'_, 'tcx>, Ty<'tcx>) -> Result<Vec<Ty<'tcx>>, NoSolution>, constituent_tys: impl Fn(&EvalCtxt<'_, 'tcx>, Ty<'tcx>) -> Result<Vec<Ty<'tcx>>, NoSolution>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
self.probe_candidate("constituent tys").enter(|ecx| { self.probe_misc_candidate("constituent tys").enter(|ecx| {
ecx.add_goals( ecx.add_goals(
constituent_tys(ecx, goal.predicate.self_ty())? constituent_tys(ecx, goal.predicate.self_ty())?
.into_iter() .into_iter()