Auto merge of #125230 - compiler-errors:uplift-query-stuff, r=lcnr
Uplift more query stuff - Uplift various query input/response internals - Uplift the `ProofTree` structures and make the `ProofTreeBuilder` stuff (mostly) generic over `Interner` - Stop using `TyCtxt::def_kind` in favor of `AliasTerm::kind` r? lcnr
This commit is contained in:
commit
7690f29bdb
41 changed files with 887 additions and 682 deletions
11
Cargo.lock
11
Cargo.lock
|
@ -4343,6 +4343,7 @@ dependencies = [
|
||||||
"rustc_hir_pretty",
|
"rustc_hir_pretty",
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
|
"rustc_next_trait_solver",
|
||||||
"rustc_query_system",
|
"rustc_query_system",
|
||||||
"rustc_serialize",
|
"rustc_serialize",
|
||||||
"rustc_session",
|
"rustc_session",
|
||||||
|
@ -4451,7 +4452,13 @@ dependencies = [
|
||||||
name = "rustc_next_trait_solver"
|
name = "rustc_next_trait_solver"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"derivative",
|
||||||
|
"rustc_ast_ir",
|
||||||
|
"rustc_data_structures",
|
||||||
|
"rustc_macros",
|
||||||
|
"rustc_serialize",
|
||||||
"rustc_type_ir",
|
"rustc_type_ir",
|
||||||
|
"rustc_type_ir_macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4752,6 +4759,7 @@ name = "rustc_trait_selection"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
|
"derivative",
|
||||||
"itertools 0.12.1",
|
"itertools 0.12.1",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_ir",
|
"rustc_ast_ir",
|
||||||
|
@ -4767,10 +4775,13 @@ dependencies = [
|
||||||
"rustc_next_trait_solver",
|
"rustc_next_trait_solver",
|
||||||
"rustc_parse_format",
|
"rustc_parse_format",
|
||||||
"rustc_query_system",
|
"rustc_query_system",
|
||||||
|
"rustc_serialize",
|
||||||
"rustc_session",
|
"rustc_session",
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_target",
|
"rustc_target",
|
||||||
"rustc_transmute",
|
"rustc_transmute",
|
||||||
|
"rustc_type_ir",
|
||||||
|
"rustc_type_ir_macros",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
|
@ -385,19 +385,31 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
|
||||||
a: Self,
|
a: Self,
|
||||||
b: Self,
|
b: Self,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
use GenericArgKind::*;
|
|
||||||
TypeTrace {
|
TypeTrace {
|
||||||
cause: cause.clone(),
|
cause: cause.clone(),
|
||||||
values: match (a.unpack(), b.unpack()) {
|
values: match (a.unpack(), b.unpack()) {
|
||||||
(Lifetime(a), Lifetime(b)) => Regions(ExpectedFound::new(a_is_expected, a, b)),
|
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
|
||||||
(Type(a), Type(b)) => Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
Regions(ExpectedFound::new(a_is_expected, a, b))
|
||||||
(Const(a), Const(b)) => {
|
}
|
||||||
|
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
|
||||||
|
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
||||||
|
}
|
||||||
|
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
|
||||||
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
(Lifetime(_), Type(_) | Const(_))
|
(
|
||||||
| (Type(_), Lifetime(_) | Const(_))
|
GenericArgKind::Lifetime(_),
|
||||||
| (Const(_), Lifetime(_) | Type(_)) => {
|
GenericArgKind::Type(_) | GenericArgKind::Const(_),
|
||||||
|
)
|
||||||
|
| (
|
||||||
|
GenericArgKind::Type(_),
|
||||||
|
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_),
|
||||||
|
)
|
||||||
|
| (
|
||||||
|
GenericArgKind::Const(_),
|
||||||
|
GenericArgKind::Lifetime(_) | GenericArgKind::Type(_),
|
||||||
|
) => {
|
||||||
bug!("relating different kinds: {a:?} {b:?}")
|
bug!("relating different kinds: {a:?} {b:?}")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -78,9 +78,9 @@ impl<T: Hash> Hash for Obligation<'_, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, P> From<Obligation<'tcx, P>> for ty::Goal<'tcx, P> {
|
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
|
||||||
fn from(value: Obligation<'tcx, P>) -> Self {
|
fn from(value: Obligation<'tcx, P>) -> Self {
|
||||||
ty::Goal { param_env: value.param_env, predicate: value.predicate }
|
solve::Goal { param_env: value.param_env, predicate: value.predicate }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
|
rustc_next_trait_solver = { path = "../rustc_next_trait_solver" }
|
||||||
rustc_query_system = { path = "../rustc_query_system" }
|
rustc_query_system = { path = "../rustc_query_system" }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
|
|
|
@ -61,7 +61,7 @@ macro_rules! arena_types {
|
||||||
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
|
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
|
||||||
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
|
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
|
||||||
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
|
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
|
||||||
[] canonical_goal_evaluation: rustc_middle::traits::solve::inspect::GoalEvaluationStep<'tcx>,
|
[] canonical_goal_evaluation: rustc_next_trait_solver::solve::inspect::GoalEvaluationStep<rustc_middle::ty::TyCtxt<'tcx>>,
|
||||||
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
|
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
|
||||||
[] type_op_subtype:
|
[] type_op_subtype:
|
||||||
rustc_middle::infer::canonical::Canonical<'tcx,
|
rustc_middle::infer::canonical::Canonical<'tcx,
|
||||||
|
|
|
@ -23,23 +23,20 @@
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
|
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||||
use rustc_type_ir::Canonical as IrCanonical;
|
pub use rustc_type_ir as ir;
|
||||||
use rustc_type_ir::CanonicalVarInfo as IrCanonicalVarInfo;
|
|
||||||
pub use rustc_type_ir::{CanonicalTyVarKind, CanonicalVarKind};
|
pub use rustc_type_ir::{CanonicalTyVarKind, CanonicalVarKind};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::ops::Index;
|
|
||||||
|
|
||||||
use crate::infer::MemberConstraint;
|
use crate::infer::MemberConstraint;
|
||||||
use crate::mir::ConstraintCategory;
|
use crate::mir::ConstraintCategory;
|
||||||
use crate::ty::GenericArg;
|
use crate::ty::GenericArg;
|
||||||
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
|
use crate::ty::{self, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
|
||||||
|
|
||||||
pub type Canonical<'tcx, V> = IrCanonical<TyCtxt<'tcx>, V>;
|
|
||||||
|
|
||||||
pub type CanonicalVarInfo<'tcx> = IrCanonicalVarInfo<TyCtxt<'tcx>>;
|
|
||||||
|
|
||||||
|
pub type Canonical<'tcx, V> = ir::Canonical<TyCtxt<'tcx>, V>;
|
||||||
|
pub type CanonicalVarInfo<'tcx> = ir::CanonicalVarInfo<TyCtxt<'tcx>>;
|
||||||
|
pub type CanonicalVarValues<'tcx> = ir::CanonicalVarValues<TyCtxt<'tcx>>;
|
||||||
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
|
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
|
||||||
|
|
||||||
impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {
|
impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {
|
||||||
|
@ -51,74 +48,6 @@ impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
|
||||||
///
|
|
||||||
/// When you canonicalize a value `V`, you get back one of these
|
|
||||||
/// vectors with the original values that were replaced by canonical
|
|
||||||
/// variables. You will need to supply it later to instantiate the
|
|
||||||
/// canonicalized query response.
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable)]
|
|
||||||
#[derive(HashStable, TypeFoldable, TypeVisitable)]
|
|
||||||
pub struct CanonicalVarValues<'tcx> {
|
|
||||||
pub var_values: ty::GenericArgsRef<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CanonicalVarValues<'_> {
|
|
||||||
pub fn is_identity(&self) -> bool {
|
|
||||||
self.var_values.iter().enumerate().all(|(bv, arg)| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(r) => {
|
|
||||||
matches!(*r, ty::ReBound(ty::INNERMOST, br) if br.var.as_usize() == bv)
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
matches!(*ty.kind(), ty::Bound(ty::INNERMOST, bt) if bt.var.as_usize() == bv)
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(ct) => {
|
|
||||||
matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc.as_usize() == bv)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_identity_modulo_regions(&self) -> bool {
|
|
||||||
let mut var = ty::BoundVar::ZERO;
|
|
||||||
for arg in self.var_values {
|
|
||||||
match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(r) => {
|
|
||||||
if let ty::ReBound(ty::INNERMOST, br) = *r
|
|
||||||
&& var == br.var
|
|
||||||
{
|
|
||||||
var = var + 1;
|
|
||||||
} else {
|
|
||||||
// It's ok if this region var isn't unique
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
if let ty::Bound(ty::INNERMOST, bt) = *ty.kind()
|
|
||||||
&& var == bt.var
|
|
||||||
{
|
|
||||||
var = var + 1;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(ct) => {
|
|
||||||
if let ty::ConstKind::Bound(ty::INNERMOST, bc) = ct.kind()
|
|
||||||
&& var == bc
|
|
||||||
{
|
|
||||||
var = var + 1;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When we canonicalize a value to form a query, we wind up replacing
|
/// When we canonicalize a value to form a query, we wind up replacing
|
||||||
/// various parts of it with canonical variables. This struct stores
|
/// various parts of it with canonical variables. This struct stores
|
||||||
/// those replaced bits to remember for when we process the query
|
/// those replaced bits to remember for when we process the query
|
||||||
|
@ -218,78 +147,6 @@ TrivialTypeTraversalImpls! {
|
||||||
crate::infer::canonical::Certainty,
|
crate::infer::canonical::Certainty,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> CanonicalVarValues<'tcx> {
|
|
||||||
// Given a list of canonical variables, construct a set of values which are
|
|
||||||
// the identity response.
|
|
||||||
pub fn make_identity(
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
infos: CanonicalVarInfos<'tcx>,
|
|
||||||
) -> CanonicalVarValues<'tcx> {
|
|
||||||
CanonicalVarValues {
|
|
||||||
var_values: tcx.mk_args_from_iter(infos.iter().enumerate().map(
|
|
||||||
|(i, info)| -> ty::GenericArg<'tcx> {
|
|
||||||
match info.kind {
|
|
||||||
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
|
|
||||||
Ty::new_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i).into())
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
|
|
||||||
let br = ty::BoundRegion {
|
|
||||||
var: ty::BoundVar::from_usize(i),
|
|
||||||
kind: ty::BrAnon,
|
|
||||||
};
|
|
||||||
ty::Region::new_bound(tcx, ty::INNERMOST, br).into()
|
|
||||||
}
|
|
||||||
CanonicalVarKind::Effect => ty::Const::new_bound(
|
|
||||||
tcx,
|
|
||||||
ty::INNERMOST,
|
|
||||||
ty::BoundVar::from_usize(i),
|
|
||||||
tcx.types.bool,
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
CanonicalVarKind::Const(_, ty)
|
|
||||||
| CanonicalVarKind::PlaceholderConst(_, ty) => ty::Const::new_bound(
|
|
||||||
tcx,
|
|
||||||
ty::INNERMOST,
|
|
||||||
ty::BoundVar::from_usize(i),
|
|
||||||
ty,
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates dummy var values which should not be used in a
|
|
||||||
/// canonical response.
|
|
||||||
pub fn dummy() -> CanonicalVarValues<'tcx> {
|
|
||||||
CanonicalVarValues { var_values: ty::List::empty() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.var_values.len()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> IntoIterator for &'a CanonicalVarValues<'tcx> {
|
|
||||||
type Item = GenericArg<'tcx>;
|
|
||||||
type IntoIter = ::std::iter::Copied<::std::slice::Iter<'a, GenericArg<'tcx>>>;
|
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
self.var_values.iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
|
|
||||||
type Output = GenericArg<'tcx>;
|
|
||||||
|
|
||||||
fn index(&self, value: BoundVar) -> &GenericArg<'tcx> {
|
|
||||||
&self.var_values[value.as_usize()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CanonicalParamEnvCache<'tcx> {
|
pub struct CanonicalParamEnvCache<'tcx> {
|
||||||
map: Lock<
|
map: Lock<
|
||||||
|
|
|
@ -9,7 +9,6 @@ pub mod specialization_graph;
|
||||||
mod structural_impls;
|
mod structural_impls;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
use crate::infer::canonical::Canonical;
|
|
||||||
use crate::mir::ConstraintCategory;
|
use crate::mir::ConstraintCategory;
|
||||||
use crate::ty::abstract_const::NotConstEvaluatable;
|
use crate::ty::abstract_const::NotConstEvaluatable;
|
||||||
use crate::ty::GenericArgsRef;
|
use crate::ty::GenericArgsRef;
|
||||||
|
@ -32,6 +31,8 @@ use std::borrow::Cow;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
||||||
|
// FIXME: Remove this import and import via `solve::`
|
||||||
|
pub use rustc_next_trait_solver::solve::BuiltinImplSource;
|
||||||
|
|
||||||
/// Depending on the stage of compilation, we want projection to be
|
/// Depending on the stage of compilation, we want projection to be
|
||||||
/// more or less conservative.
|
/// more or less conservative.
|
||||||
|
@ -736,32 +737,6 @@ pub struct ImplSourceUserDefinedData<'tcx, N> {
|
||||||
pub nested: Vec<N>,
|
pub nested: Vec<N>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Debug)]
|
|
||||||
pub enum BuiltinImplSource {
|
|
||||||
/// Some builtin impl we don't need to differentiate. This should be used
|
|
||||||
/// unless more specific information is necessary.
|
|
||||||
Misc,
|
|
||||||
/// A builtin impl for trait objects.
|
|
||||||
///
|
|
||||||
/// The vtable is formed by concatenating together the method lists of
|
|
||||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
|
||||||
/// be provided when necessary; this is the start of `upcast_trait_ref`'s methods
|
|
||||||
/// in that vtable.
|
|
||||||
Object { vtable_base: usize },
|
|
||||||
/// The vtable is formed by concatenating together the method lists of
|
|
||||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
|
||||||
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
|
|
||||||
/// within that vtable.
|
|
||||||
TraitUpcasting { vtable_vptr_slot: Option<usize> },
|
|
||||||
/// Unsizing a tuple like `(A, B, ..., X)` to `(A, B, ..., Y)` if `X` unsizes to `Y`.
|
|
||||||
///
|
|
||||||
/// This needs to be a separate variant as it is still unstable and we need to emit
|
|
||||||
/// a feature error when using it on stable.
|
|
||||||
TupleUnsizing,
|
|
||||||
}
|
|
||||||
|
|
||||||
TrivialTypeTraversalImpls! { BuiltinImplSource }
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
|
||||||
pub enum ObjectSafetyViolation {
|
pub enum ObjectSafetyViolation {
|
||||||
/// `Self: Sized` declared on the trait.
|
/// `Self: Sized` declared on the trait.
|
||||||
|
|
|
@ -12,6 +12,8 @@ use crate::ty::GenericArg;
|
||||||
use crate::ty::{self, Ty, TyCtxt};
|
use crate::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
// FIXME: Remove this import and import via `traits::solve`.
|
||||||
|
pub use rustc_next_trait_solver::solve::NoSolution;
|
||||||
|
|
||||||
pub mod type_op {
|
pub mod type_op {
|
||||||
use crate::ty::fold::TypeFoldable;
|
use crate::ty::fold::TypeFoldable;
|
||||||
|
@ -89,9 +91,6 @@ pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
|
||||||
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
|
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
|
||||||
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
|
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Hash, HashStable, PartialEq, Eq)]
|
|
||||||
pub struct NoSolution;
|
|
||||||
|
|
||||||
impl<'tcx> From<TypeError<'tcx>> for NoSolution {
|
impl<'tcx> From<TypeError<'tcx>> for NoSolution {
|
||||||
fn from(_: TypeError<'tcx>) -> NoSolution {
|
fn from(_: TypeError<'tcx>) -> NoSolution {
|
||||||
NoSolution
|
NoSolution
|
||||||
|
|
|
@ -1,97 +1,24 @@
|
||||||
use rustc_ast_ir::try_visit;
|
use rustc_ast_ir::try_visit;
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_next_trait_solver as ir;
|
||||||
|
pub use rustc_next_trait_solver::solve::*;
|
||||||
|
|
||||||
use crate::infer::canonical::{CanonicalVarValues, QueryRegionConstraints};
|
use crate::infer::canonical::QueryRegionConstraints;
|
||||||
use crate::traits::query::NoSolution;
|
|
||||||
use crate::traits::Canonical;
|
|
||||||
use crate::ty::{
|
use crate::ty::{
|
||||||
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
|
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
|
||||||
};
|
};
|
||||||
// FIXME(compiler-errors): remove this import in favor of `use rustc_middle::ty::Goal`.
|
|
||||||
pub use crate::ty::Goal;
|
|
||||||
|
|
||||||
use super::BuiltinImplSource;
|
|
||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
pub mod inspect;
|
|
||||||
|
|
||||||
pub use cache::{CacheData, EvaluationCache};
|
pub use cache::{CacheData, EvaluationCache};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
pub type Goal<'tcx, P> = ir::solve::Goal<TyCtxt<'tcx>, P>;
|
||||||
pub struct Response<'tcx> {
|
pub type QueryInput<'tcx, P> = ir::solve::QueryInput<TyCtxt<'tcx>, P>;
|
||||||
pub certainty: Certainty,
|
pub type QueryResult<'tcx> = ir::solve::QueryResult<TyCtxt<'tcx>>;
|
||||||
pub var_values: CanonicalVarValues<'tcx>,
|
pub type CandidateSource<'tcx> = ir::solve::CandidateSource<TyCtxt<'tcx>>;
|
||||||
/// Additional constraints returned by this query.
|
pub type CanonicalInput<'tcx, P = ty::Predicate<'tcx>> = ir::solve::CanonicalInput<TyCtxt<'tcx>, P>;
|
||||||
pub external_constraints: ExternalConstraints<'tcx>,
|
pub type CanonicalResponse<'tcx> = ir::solve::CanonicalResponse<TyCtxt<'tcx>>;
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
|
||||||
pub enum Certainty {
|
|
||||||
Yes,
|
|
||||||
Maybe(MaybeCause),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Certainty {
|
|
||||||
pub const AMBIGUOUS: Certainty = Certainty::Maybe(MaybeCause::Ambiguity);
|
|
||||||
|
|
||||||
/// Use this function to merge the certainty of multiple nested subgoals.
|
|
||||||
///
|
|
||||||
/// Given an impl like `impl<T: Foo + Bar> Baz for T {}`, we have 2 nested
|
|
||||||
/// subgoals whenever we use the impl as a candidate: `T: Foo` and `T: Bar`.
|
|
||||||
/// If evaluating `T: Foo` results in ambiguity and `T: Bar` results in
|
|
||||||
/// success, we merge these two responses. This results in ambiguity.
|
|
||||||
///
|
|
||||||
/// If we unify ambiguity with overflow, we return overflow. This doesn't matter
|
|
||||||
/// inside of the solver as we do not distinguish ambiguity from overflow. It does
|
|
||||||
/// however matter for diagnostics. If `T: Foo` resulted in overflow and `T: Bar`
|
|
||||||
/// in ambiguity without changing the inference state, we still want to tell the
|
|
||||||
/// user that `T: Baz` results in overflow.
|
|
||||||
pub fn unify_with(self, other: Certainty) -> Certainty {
|
|
||||||
match (self, other) {
|
|
||||||
(Certainty::Yes, Certainty::Yes) => Certainty::Yes,
|
|
||||||
(Certainty::Yes, Certainty::Maybe(_)) => other,
|
|
||||||
(Certainty::Maybe(_), Certainty::Yes) => self,
|
|
||||||
(Certainty::Maybe(a), Certainty::Maybe(b)) => Certainty::Maybe(a.unify_with(b)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn overflow(suggest_increasing_limit: bool) -> Certainty {
|
|
||||||
Certainty::Maybe(MaybeCause::Overflow { suggest_increasing_limit })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Why we failed to evaluate a goal.
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
|
||||||
pub enum MaybeCause {
|
|
||||||
/// We failed due to ambiguity. This ambiguity can either
|
|
||||||
/// be a true ambiguity, i.e. there are multiple different answers,
|
|
||||||
/// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
|
|
||||||
Ambiguity,
|
|
||||||
/// We gave up due to an overflow, most often by hitting the recursion limit.
|
|
||||||
Overflow { suggest_increasing_limit: bool },
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MaybeCause {
|
|
||||||
fn unify_with(self, other: MaybeCause) -> MaybeCause {
|
|
||||||
match (self, other) {
|
|
||||||
(MaybeCause::Ambiguity, MaybeCause::Ambiguity) => MaybeCause::Ambiguity,
|
|
||||||
(MaybeCause::Ambiguity, MaybeCause::Overflow { .. }) => other,
|
|
||||||
(MaybeCause::Overflow { .. }, MaybeCause::Ambiguity) => self,
|
|
||||||
(
|
|
||||||
MaybeCause::Overflow { suggest_increasing_limit: a },
|
|
||||||
MaybeCause::Overflow { suggest_increasing_limit: b },
|
|
||||||
) => MaybeCause::Overflow { suggest_increasing_limit: a || b },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
|
||||||
pub struct QueryInput<'tcx, T> {
|
|
||||||
pub goal: Goal<'tcx, T>,
|
|
||||||
pub predefined_opaques_in_body: PredefinedOpaques<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional constraints returned on success.
|
/// Additional constraints returned on success.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default)]
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default)]
|
||||||
|
@ -110,18 +37,6 @@ impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CanonicalInput<'tcx, T = ty::Predicate<'tcx>> = Canonical<'tcx, QueryInput<'tcx, T>>;
|
|
||||||
|
|
||||||
pub type CanonicalResponse<'tcx> = Canonical<'tcx, Response<'tcx>>;
|
|
||||||
|
|
||||||
/// The result of evaluating a canonical query.
|
|
||||||
///
|
|
||||||
/// FIXME: We use a different type than the existing canonical queries. This is because
|
|
||||||
/// we need to add a `Certainty` for `overflow` and may want to restructure this code without
|
|
||||||
/// having to worry about changes to currently used code. Once we've made progress on this
|
|
||||||
/// solver, merge the two responses again.
|
|
||||||
pub type QueryResult<'tcx> = Result<CanonicalResponse<'tcx>, NoSolution>;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
|
||||||
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
|
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
|
||||||
|
|
||||||
|
@ -228,91 +143,3 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
|
||||||
self.opaque_types.visit_with(visitor)
|
self.opaque_types.visit_with(visitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Why a specific goal has to be proven.
|
|
||||||
///
|
|
||||||
/// This is necessary as we treat nested goals different depending on
|
|
||||||
/// their source.
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TypeVisitable, TypeFoldable)]
|
|
||||||
pub enum GoalSource {
|
|
||||||
Misc,
|
|
||||||
/// We're proving a where-bound of an impl.
|
|
||||||
///
|
|
||||||
/// FIXME(-Znext-solver=coinductive): Explain how and why this
|
|
||||||
/// changes whether cycles are coinductive.
|
|
||||||
///
|
|
||||||
/// This also impacts whether we erase constraints on overflow.
|
|
||||||
/// Erasing constraints is generally very useful for perf and also
|
|
||||||
/// results in better error messages by avoiding spurious errors.
|
|
||||||
/// We do not erase overflow constraints in `normalizes-to` goals unless
|
|
||||||
/// they are from an impl where-clause. This is necessary due to
|
|
||||||
/// backwards compatability, cc trait-system-refactor-initiatitive#70.
|
|
||||||
ImplWhereBound,
|
|
||||||
/// Instantiating a higher-ranked goal and re-proving it.
|
|
||||||
InstantiateHigherRanked,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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,
|
|
||||||
/// A candidate that is registered only during coherence to represent some
|
|
||||||
/// yet-unknown impl that could be produced downstream without violating orphan
|
|
||||||
/// rules.
|
|
||||||
// FIXME: Merge this with the forced ambiguity candidates, so those don't use `Misc`.
|
|
||||||
CoherenceUnknowable,
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct EvaluationCache<'tcx> {
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub struct CacheData<'tcx> {
|
pub struct CacheData<'tcx> {
|
||||||
pub result: QueryResult<'tcx>,
|
pub result: QueryResult<'tcx>,
|
||||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||||
pub reached_depth: usize,
|
pub reached_depth: usize,
|
||||||
pub encountered_overflow: bool,
|
pub encountered_overflow: bool,
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ impl<'tcx> EvaluationCache<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
key: CanonicalInput<'tcx>,
|
key: CanonicalInput<'tcx>,
|
||||||
proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||||
reached_depth: usize,
|
reached_depth: usize,
|
||||||
encountered_overflow: bool,
|
encountered_overflow: bool,
|
||||||
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
|
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
|
||||||
|
@ -105,7 +105,7 @@ struct Success<'tcx> {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct QueryData<'tcx> {
|
pub struct QueryData<'tcx> {
|
||||||
pub result: QueryResult<'tcx>,
|
pub result: QueryResult<'tcx>,
|
||||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The cache entry for a goal `CanonicalInput`.
|
/// The cache entry for a goal `CanonicalInput`.
|
||||||
|
|
|
@ -89,18 +89,23 @@ use std::ops::{Bound, Deref};
|
||||||
#[allow(rustc::usage_of_ty_tykind)]
|
#[allow(rustc::usage_of_ty_tykind)]
|
||||||
impl<'tcx> Interner for TyCtxt<'tcx> {
|
impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||||
type DefId = DefId;
|
type DefId = DefId;
|
||||||
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
|
|
||||||
type AdtDef = ty::AdtDef<'tcx>;
|
type AdtDef = ty::AdtDef<'tcx>;
|
||||||
|
|
||||||
type GenericArgs = ty::GenericArgsRef<'tcx>;
|
type GenericArgs = ty::GenericArgsRef<'tcx>;
|
||||||
type OwnItemArgs = &'tcx [ty::GenericArg<'tcx>];
|
type OwnItemArgs = &'tcx [ty::GenericArg<'tcx>];
|
||||||
type GenericArg = ty::GenericArg<'tcx>;
|
type GenericArg = ty::GenericArg<'tcx>;
|
||||||
|
|
||||||
type Term = ty::Term<'tcx>;
|
type Term = ty::Term<'tcx>;
|
||||||
|
|
||||||
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
|
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
|
||||||
type BoundVars = &'tcx List<ty::BoundVariableKind>;
|
type BoundVars = &'tcx List<ty::BoundVariableKind>;
|
||||||
type BoundVar = ty::BoundVariableKind;
|
type BoundVar = ty::BoundVariableKind;
|
||||||
|
|
||||||
type CanonicalVars = CanonicalVarInfos<'tcx>;
|
type CanonicalVars = CanonicalVarInfos<'tcx>;
|
||||||
|
type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
|
||||||
|
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
|
||||||
|
type ExternalConstraints = ExternalConstraints<'tcx>;
|
||||||
|
type GoalEvaluationSteps = &'tcx [solve::inspect::GoalEvaluationStep<TyCtxt<'tcx>>];
|
||||||
|
|
||||||
type Ty = Ty<'tcx>;
|
type Ty = Ty<'tcx>;
|
||||||
type Tys = &'tcx List<Ty<'tcx>>;
|
type Tys = &'tcx List<Ty<'tcx>>;
|
||||||
type FnInputTys = &'tcx [Ty<'tcx>];
|
type FnInputTys = &'tcx [Ty<'tcx>];
|
||||||
|
|
|
@ -11,6 +11,7 @@ use rustc_ast_ir::walk_visitable_list;
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_errors::{DiagArgValue, IntoDiagArg};
|
use rustc_errors::{DiagArgValue, IntoDiagArg};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
use rustc_macros::extension;
|
||||||
use rustc_macros::{
|
use rustc_macros::{
|
||||||
Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
|
Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
|
||||||
};
|
};
|
||||||
|
@ -25,6 +26,8 @@ use std::num::NonZero;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
pub type GenericArgKind<'tcx> = rustc_type_ir::GenericArgKind<TyCtxt<'tcx>>;
|
||||||
|
|
||||||
/// An entity in the Rust type system, which can be one of
|
/// An entity in the Rust type system, which can be one of
|
||||||
/// several kinds (types, lifetimes, and consts).
|
/// several kinds (types, lifetimes, and consts).
|
||||||
/// To reduce memory usage, a `GenericArg` is an interned pointer,
|
/// To reduce memory usage, a `GenericArg` is an interned pointer,
|
||||||
|
@ -49,6 +52,14 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
|
||||||
|
type Kind = GenericArgKind<'tcx>;
|
||||||
|
|
||||||
|
fn kind(self) -> Self::Kind {
|
||||||
|
self.unpack()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
unsafe impl<'tcx> rustc_data_structures::sync::DynSend for GenericArg<'tcx> where
|
unsafe impl<'tcx> rustc_data_structures::sync::DynSend for GenericArg<'tcx> where
|
||||||
&'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): rustc_data_structures::sync::DynSend
|
&'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): rustc_data_structures::sync::DynSend
|
||||||
|
@ -79,13 +90,7 @@ const TYPE_TAG: usize = 0b00;
|
||||||
const REGION_TAG: usize = 0b01;
|
const REGION_TAG: usize = 0b01;
|
||||||
const CONST_TAG: usize = 0b10;
|
const CONST_TAG: usize = 0b10;
|
||||||
|
|
||||||
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, HashStable)]
|
#[extension(trait GenericArgPackExt<'tcx>)]
|
||||||
pub enum GenericArgKind<'tcx> {
|
|
||||||
Lifetime(ty::Region<'tcx>),
|
|
||||||
Type(Ty<'tcx>),
|
|
||||||
Const(ty::Const<'tcx>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> GenericArgKind<'tcx> {
|
impl<'tcx> GenericArgKind<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pack(self) -> GenericArg<'tcx> {
|
fn pack(self) -> GenericArg<'tcx> {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::ty::fast_reject::SimplifiedType;
|
||||||
use crate::ty::util::Discr;
|
use crate::ty::util::Discr;
|
||||||
pub use adt::*;
|
pub use adt::*;
|
||||||
pub use assoc::*;
|
pub use assoc::*;
|
||||||
pub use generic_args::*;
|
pub use generic_args::{GenericArgKind, *};
|
||||||
pub use generics::*;
|
pub use generics::*;
|
||||||
pub use intrinsic::IntrinsicDef;
|
pub use intrinsic::IntrinsicDef;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
@ -97,13 +97,12 @@ pub use self::parameterized::ParameterizedOverTcx;
|
||||||
pub use self::pattern::{Pattern, PatternKind};
|
pub use self::pattern::{Pattern, PatternKind};
|
||||||
pub use self::predicate::{
|
pub use self::predicate::{
|
||||||
AliasTerm, Clause, ClauseKind, CoercePredicate, ExistentialPredicate,
|
AliasTerm, Clause, ClauseKind, CoercePredicate, ExistentialPredicate,
|
||||||
ExistentialPredicateStableCmpExt, ExistentialProjection, ExistentialTraitRef, Goal,
|
ExistentialPredicateStableCmpExt, ExistentialProjection, ExistentialTraitRef, NormalizesTo,
|
||||||
NormalizesTo, OutlivesPredicate, PolyCoercePredicate, PolyExistentialPredicate,
|
OutlivesPredicate, PolyCoercePredicate, PolyExistentialPredicate, PolyExistentialProjection,
|
||||||
PolyExistentialProjection, PolyExistentialTraitRef, PolyProjectionPredicate,
|
PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate,
|
||||||
PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef,
|
PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate,
|
||||||
PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
|
PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef,
|
||||||
RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, TraitPredicate, TraitRef,
|
TraitPredicate, TraitRef, TypeOutlivesPredicate,
|
||||||
TypeOutlivesPredicate,
|
|
||||||
};
|
};
|
||||||
pub use self::region::{
|
pub use self::region::{
|
||||||
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,
|
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::ty::{
|
||||||
Upcast, UpcastFrom, WithCachedTypeInfo,
|
Upcast, UpcastFrom, WithCachedTypeInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Goal<'tcx, P> = ir::Goal<TyCtxt<'tcx>, P>;
|
|
||||||
pub type TraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>;
|
pub type TraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>;
|
||||||
pub type AliasTerm<'tcx> = ir::AliasTerm<TyCtxt<'tcx>>;
|
pub type AliasTerm<'tcx> = ir::AliasTerm<TyCtxt<'tcx>>;
|
||||||
pub type ProjectionPredicate<'tcx> = ir::ProjectionPredicate<TyCtxt<'tcx>>;
|
pub type ProjectionPredicate<'tcx> = ir::ProjectionPredicate<TyCtxt<'tcx>>;
|
||||||
|
|
|
@ -396,6 +396,12 @@ pub struct BoundRegion {
|
||||||
pub kind: BoundRegionKind,
|
pub kind: BoundRegionKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundRegion {
|
||||||
|
fn var(self) -> BoundVar {
|
||||||
|
self.var
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl core::fmt::Debug for BoundRegion {
|
impl core::fmt::Debug for BoundRegion {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
|
|
|
@ -1199,6 +1199,12 @@ pub struct BoundTy {
|
||||||
pub kind: BoundTyKind,
|
pub kind: BoundTyKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundTy {
|
||||||
|
fn var(self) -> BoundVar {
|
||||||
|
self.var
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
|
||||||
#[derive(HashStable)]
|
#[derive(HashStable)]
|
||||||
pub enum BoundTyKind {
|
pub enum BoundTyKind {
|
||||||
|
@ -1601,6 +1607,10 @@ impl<'tcx> Ty<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
|
impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
|
||||||
|
fn new_bool(tcx: TyCtxt<'tcx>) -> Self {
|
||||||
|
tcx.types.bool
|
||||||
|
}
|
||||||
|
|
||||||
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
|
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
|
||||||
Ty::new_bound(tcx, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
|
Ty::new_bound(tcx, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,19 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc_type_ir = { path = "../rustc_type_ir", default-features = false }
|
rustc_type_ir = { path = "../rustc_type_ir", default-features = false }
|
||||||
|
derivative = "2.2.0"
|
||||||
|
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||||
|
rustc_type_ir_macros = { path = "../rustc_type_ir_macros" }
|
||||||
|
rustc_serialize = { path = "../rustc_serialize", optional = true }
|
||||||
|
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||||
|
rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nightly"]
|
default = ["nightly"]
|
||||||
nightly = [
|
nightly = [
|
||||||
"rustc_type_ir/nightly",
|
"rustc_type_ir/nightly",
|
||||||
]
|
"rustc_macros",
|
||||||
|
"rustc_serialize",
|
||||||
|
"rustc_data_structures",
|
||||||
|
"rustc_ast_ir/nightly",
|
||||||
|
]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod canonicalizer;
|
pub mod canonicalizer;
|
||||||
|
pub mod solve;
|
||||||
|
|
1
compiler/rustc_next_trait_solver/src/solve.rs
Normal file
1
compiler/rustc_next_trait_solver/src/solve.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub use rustc_type_ir::solve::*;
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
bitflags = "2.4.1"
|
bitflags = "2.4.1"
|
||||||
|
derivative = "2.2.0"
|
||||||
itertools = "0.12"
|
itertools = "0.12"
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||||
|
@ -21,10 +22,13 @@ rustc_middle = { path = "../rustc_middle" }
|
||||||
rustc_next_trait_solver = { path = "../rustc_next_trait_solver" }
|
rustc_next_trait_solver = { path = "../rustc_next_trait_solver" }
|
||||||
rustc_parse_format = { path = "../rustc_parse_format" }
|
rustc_parse_format = { path = "../rustc_parse_format" }
|
||||||
rustc_query_system = { path = "../rustc_query_system" }
|
rustc_query_system = { path = "../rustc_query_system" }
|
||||||
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
rustc_target = { path = "../rustc_target" }
|
rustc_target = { path = "../rustc_target" }
|
||||||
rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] }
|
rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] }
|
||||||
|
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||||
|
rustc_type_ir_macros = { path = "../rustc_type_ir_macros" }
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
# tidy-alphabetical-end
|
# tidy-alphabetical-end
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub(super) mod structural_traits;
|
||||||
/// and the `result` when using the given `source`.
|
/// and the `result` when using the given `source`.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(super) struct Candidate<'tcx> {
|
pub(super) struct Candidate<'tcx> {
|
||||||
pub(super) source: CandidateSource,
|
pub(super) source: CandidateSource<'tcx>,
|
||||||
pub(super) result: CanonicalResponse<'tcx>,
|
pub(super) result: CanonicalResponse<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub(super) trait GoalKind<'tcx>:
|
||||||
/// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
|
/// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
|
||||||
fn probe_and_match_goal_against_assumption(
|
fn probe_and_match_goal_against_assumption(
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
assumption: ty::Clause<'tcx>,
|
assumption: ty::Clause<'tcx>,
|
||||||
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
||||||
|
@ -58,7 +58,7 @@ pub(super) trait GoalKind<'tcx>:
|
||||||
/// goal by equating it with the assumption.
|
/// goal by equating it with the assumption.
|
||||||
fn probe_and_consider_implied_clause(
|
fn probe_and_consider_implied_clause(
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
parent_source: CandidateSource,
|
parent_source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
assumption: ty::Clause<'tcx>,
|
assumption: ty::Clause<'tcx>,
|
||||||
requirements: impl IntoIterator<Item = (GoalSource, Goal<'tcx, ty::Predicate<'tcx>>)>,
|
requirements: impl IntoIterator<Item = (GoalSource, Goal<'tcx, ty::Predicate<'tcx>>)>,
|
||||||
|
@ -76,7 +76,7 @@ pub(super) trait GoalKind<'tcx>:
|
||||||
/// since they're not implied by the well-formedness of the object type.
|
/// since they're not implied by the well-formedness of the object type.
|
||||||
fn probe_and_consider_object_bound_candidate(
|
fn probe_and_consider_object_bound_candidate(
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
assumption: ty::Clause<'tcx>,
|
assumption: ty::Clause<'tcx>,
|
||||||
) -> Result<Candidate<'tcx>, NoSolution> {
|
) -> Result<Candidate<'tcx>, NoSolution> {
|
||||||
|
|
|
@ -6,9 +6,8 @@ use rustc_hir::{def_id::DefId, Movability, Mutability};
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::traits::solve::Goal;
|
||||||
self, Goal, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast,
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast};
|
||||||
};
|
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
use crate::solve::EvalCtxt;
|
use crate::solve::EvalCtxt;
|
||||||
|
|
|
@ -40,13 +40,13 @@ trait ResponseT<'tcx> {
|
||||||
fn var_values(&self) -> CanonicalVarValues<'tcx>;
|
fn var_values(&self) -> CanonicalVarValues<'tcx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ResponseT<'tcx> for Response<'tcx> {
|
impl<'tcx> ResponseT<'tcx> for Response<TyCtxt<'tcx>> {
|
||||||
fn var_values(&self) -> CanonicalVarValues<'tcx> {
|
fn var_values(&self) -> CanonicalVarValues<'tcx> {
|
||||||
self.var_values
|
self.var_values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T> ResponseT<'tcx> for inspect::State<'tcx, T> {
|
impl<'tcx, T> ResponseT<'tcx> for inspect::State<TyCtxt<'tcx>, T> {
|
||||||
fn var_values(&self) -> CanonicalVarValues<'tcx> {
|
fn var_values(&self) -> CanonicalVarValues<'tcx> {
|
||||||
self.var_values
|
self.var_values
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ pub(in crate::solve) fn make_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>
|
||||||
var_values: &[ty::GenericArg<'tcx>],
|
var_values: &[ty::GenericArg<'tcx>],
|
||||||
max_input_universe: ty::UniverseIndex,
|
max_input_universe: ty::UniverseIndex,
|
||||||
data: T,
|
data: T,
|
||||||
) -> inspect::CanonicalState<'tcx, T> {
|
) -> inspect::CanonicalState<TyCtxt<'tcx>, T> {
|
||||||
let var_values = CanonicalVarValues { var_values: infcx.tcx.mk_args(var_values) };
|
let var_values = CanonicalVarValues { var_values: infcx.tcx.mk_args(var_values) };
|
||||||
let state = inspect::State { var_values, data };
|
let state = inspect::State { var_values, data };
|
||||||
let state = state.fold_with(&mut EagerResolver::new(infcx));
|
let state = state.fold_with(&mut EagerResolver::new(infcx));
|
||||||
|
@ -414,7 +414,7 @@ pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt
|
||||||
span: Span,
|
span: Span,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
orig_values: &mut Vec<ty::GenericArg<'tcx>>,
|
orig_values: &mut Vec<ty::GenericArg<'tcx>>,
|
||||||
state: inspect::CanonicalState<'tcx, T>,
|
state: inspect::CanonicalState<TyCtxt<'tcx>, T>,
|
||||||
) -> T {
|
) -> T {
|
||||||
// In case any fresh inference variables have been created between `state`
|
// In case any fresh inference variables have been created between `state`
|
||||||
// and the previous instantiation, extend `orig_values` for it.
|
// and the previous instantiation, extend `orig_values` for it.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
use std::io::Write;
|
||||||
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::at::ToTrace;
|
use rustc_infer::infer::at::ToTrace;
|
||||||
|
@ -8,13 +11,12 @@ use rustc_infer::infer::{
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
|
use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_macros::{extension, HashStable};
|
use rustc_macros::{extension, HashStable, HashStable_NoContext, TyDecodable, TyEncodable};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
||||||
use rustc_middle::traits::solve::inspect;
|
|
||||||
use rustc_middle::traits::solve::{
|
use rustc_middle::traits::solve::{
|
||||||
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
|
inspect, CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques,
|
||||||
QueryResult,
|
PredefinedOpaquesData, QueryResult,
|
||||||
};
|
};
|
||||||
use rustc_middle::traits::specialization_graph;
|
use rustc_middle::traits::specialization_graph;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
|
@ -23,8 +25,8 @@ use rustc_middle::ty::{
|
||||||
};
|
};
|
||||||
use rustc_session::config::DumpSolverProofTree;
|
use rustc_session::config::DumpSolverProofTree;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
use std::io::Write;
|
use rustc_type_ir::{self as ir, Interner};
|
||||||
use std::ops::ControlFlow;
|
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
|
||||||
|
|
||||||
use crate::traits::coherence;
|
use crate::traits::coherence;
|
||||||
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
|
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
|
||||||
|
@ -85,7 +87,7 @@ pub struct EvalCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub(super) search_graph: &'a mut SearchGraph<'tcx>,
|
pub(super) search_graph: &'a mut SearchGraph<'tcx>,
|
||||||
|
|
||||||
nested_goals: NestedGoals<'tcx>,
|
nested_goals: NestedGoals<TyCtxt<'tcx>>,
|
||||||
|
|
||||||
// Has this `EvalCtxt` errored out with `NoSolution` in `try_evaluate_added_goals`?
|
// Has this `EvalCtxt` errored out with `NoSolution` in `try_evaluate_added_goals`?
|
||||||
//
|
//
|
||||||
|
@ -95,11 +97,15 @@ pub struct EvalCtxt<'a, 'tcx> {
|
||||||
// evaluation code.
|
// evaluation code.
|
||||||
tainted: Result<(), NoSolution>,
|
tainted: Result<(), NoSolution>,
|
||||||
|
|
||||||
pub(super) inspect: ProofTreeBuilder<'tcx>,
|
pub(super) inspect: ProofTreeBuilder<TyCtxt<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
pub(super) struct NestedGoals<'tcx> {
|
#[derivative(Clone(bound = ""), Debug(bound = ""), Default(bound = ""))]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
|
||||||
|
#[derive(TyDecodable, TyEncodable, HashStable_NoContext)]
|
||||||
|
// FIXME: This can be made crate-private once `EvalCtxt` also lives in this crate.
|
||||||
|
pub struct NestedGoals<I: Interner> {
|
||||||
/// These normalizes-to goals are treated specially during the evaluation
|
/// These normalizes-to goals are treated specially during the evaluation
|
||||||
/// loop. In each iteration we take the RHS of the projection, replace it with
|
/// loop. In each iteration we take the RHS of the projection, replace it with
|
||||||
/// a fresh inference variable, and only after evaluating that goal do we
|
/// a fresh inference variable, and only after evaluating that goal do we
|
||||||
|
@ -110,17 +116,17 @@ pub(super) struct NestedGoals<'tcx> {
|
||||||
///
|
///
|
||||||
/// Forgetting to replace the RHS with a fresh inference variable when we evaluate
|
/// Forgetting to replace the RHS with a fresh inference variable when we evaluate
|
||||||
/// this goal results in an ICE..
|
/// this goal results in an ICE..
|
||||||
pub(super) normalizes_to_goals: Vec<Goal<'tcx, ty::NormalizesTo<'tcx>>>,
|
pub normalizes_to_goals: Vec<ir::solve::Goal<I, ir::NormalizesTo<I>>>,
|
||||||
/// The rest of the goals which have not yet processed or remain ambiguous.
|
/// The rest of the goals which have not yet processed or remain ambiguous.
|
||||||
pub(super) goals: Vec<(GoalSource, Goal<'tcx, ty::Predicate<'tcx>>)>,
|
pub goals: Vec<(GoalSource, ir::solve::Goal<I, I::Predicate>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> NestedGoals<'tcx> {
|
impl<I: Interner> NestedGoals<I> {
|
||||||
pub(super) fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { normalizes_to_goals: Vec::new(), goals: Vec::new() }
|
Self { normalizes_to_goals: Vec::new(), goals: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.normalizes_to_goals.is_empty() && self.goals.is_empty()
|
self.normalizes_to_goals.is_empty() && self.goals.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +149,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
||||||
generate_proof_tree: GenerateProofTree,
|
generate_proof_tree: GenerateProofTree,
|
||||||
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<'tcx>>) {
|
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<TyCtxt<'tcx>>>)
|
||||||
|
{
|
||||||
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
|
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
|
||||||
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
|
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
|
||||||
})
|
})
|
||||||
|
@ -166,7 +173,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
generate_proof_tree: GenerateProofTree,
|
generate_proof_tree: GenerateProofTree,
|
||||||
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> R,
|
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> R,
|
||||||
) -> (R, Option<inspect::GoalEvaluation<'tcx>>) {
|
) -> (R, Option<inspect::GoalEvaluation<TyCtxt<'tcx>>>) {
|
||||||
let mode = if infcx.intercrate { SolverMode::Coherence } else { SolverMode::Normal };
|
let mode = if infcx.intercrate { SolverMode::Coherence } else { SolverMode::Normal };
|
||||||
let mut search_graph = search_graph::SearchGraph::new(mode);
|
let mut search_graph = search_graph::SearchGraph::new(mode);
|
||||||
|
|
||||||
|
@ -220,7 +227,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
search_graph: &'a mut search_graph::SearchGraph<'tcx>,
|
search_graph: &'a mut search_graph::SearchGraph<'tcx>,
|
||||||
canonical_input: CanonicalInput<'tcx>,
|
canonical_input: CanonicalInput<'tcx>,
|
||||||
canonical_goal_evaluation: &mut ProofTreeBuilder<'tcx>,
|
canonical_goal_evaluation: &mut ProofTreeBuilder<TyCtxt<'tcx>>,
|
||||||
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>, Goal<'tcx, ty::Predicate<'tcx>>) -> R,
|
f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>, Goal<'tcx, ty::Predicate<'tcx>>) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
let intercrate = match search_graph.solver_mode() {
|
let intercrate = match search_graph.solver_mode() {
|
||||||
|
@ -282,7 +289,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
search_graph: &'a mut search_graph::SearchGraph<'tcx>,
|
search_graph: &'a mut search_graph::SearchGraph<'tcx>,
|
||||||
canonical_input: CanonicalInput<'tcx>,
|
canonical_input: CanonicalInput<'tcx>,
|
||||||
goal_evaluation: &mut ProofTreeBuilder<'tcx>,
|
goal_evaluation: &mut ProofTreeBuilder<TyCtxt<'tcx>>,
|
||||||
) -> QueryResult<'tcx> {
|
) -> QueryResult<'tcx> {
|
||||||
let mut canonical_goal_evaluation =
|
let mut canonical_goal_evaluation =
|
||||||
goal_evaluation.new_canonical_goal_evaluation(canonical_input);
|
goal_evaluation.new_canonical_goal_evaluation(canonical_input);
|
||||||
|
|
|
@ -2,10 +2,9 @@ use crate::solve::assembly::Candidate;
|
||||||
|
|
||||||
use super::EvalCtxt;
|
use super::EvalCtxt;
|
||||||
use rustc_infer::traits::BuiltinImplSource;
|
use rustc_infer::traits::BuiltinImplSource;
|
||||||
use rustc_middle::traits::{
|
use rustc_middle::traits::query::NoSolution;
|
||||||
query::NoSolution,
|
use rustc_middle::traits::solve::{inspect, CandidateSource, QueryResult};
|
||||||
solve::{inspect, CandidateSource, QueryResult},
|
use rustc_middle::ty::TyCtxt;
|
||||||
};
|
|
||||||
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> {
|
||||||
|
@ -16,7 +15,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::ProbeKind<'tcx>,
|
F: FnOnce(&T) -> inspect::ProbeKind<TyCtxt<'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;
|
||||||
|
@ -51,12 +50,12 @@ where
|
||||||
|
|
||||||
pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, 'tcx, F> {
|
pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, 'tcx, F> {
|
||||||
cx: ProbeCtxt<'me, 'a, 'tcx, F, QueryResult<'tcx>>,
|
cx: ProbeCtxt<'me, 'a, 'tcx, F, QueryResult<'tcx>>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, F> TraitProbeCtxt<'_, '_, 'tcx, F>
|
impl<'tcx, F> TraitProbeCtxt<'_, '_, 'tcx, F>
|
||||||
where
|
where
|
||||||
F: FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>,
|
F: FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
#[instrument(level = "debug", skip_all, fields(source = ?self.source))]
|
#[instrument(level = "debug", skip_all, fields(source = ?self.source))]
|
||||||
pub(in crate::solve) fn enter(
|
pub(in crate::solve) fn enter(
|
||||||
|
@ -72,7 +71,7 @@ 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::ProbeKind<'tcx>,
|
F: FnOnce(&T) -> inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
ProbeCtxt { ecx: self, probe_kind, _result: PhantomData }
|
ProbeCtxt { ecx: self, probe_kind, _result: PhantomData }
|
||||||
}
|
}
|
||||||
|
@ -80,16 +79,24 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
||||||
pub(in crate::solve) fn probe_builtin_trait_candidate(
|
pub(in crate::solve) fn probe_builtin_trait_candidate(
|
||||||
&mut self,
|
&mut self,
|
||||||
source: BuiltinImplSource,
|
source: BuiltinImplSource,
|
||||||
) -> TraitProbeCtxt<'_, 'a, 'tcx, impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>>
|
) -> TraitProbeCtxt<
|
||||||
{
|
'_,
|
||||||
|
'a,
|
||||||
|
'tcx,
|
||||||
|
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
|
> {
|
||||||
self.probe_trait_candidate(CandidateSource::BuiltinImpl(source))
|
self.probe_trait_candidate(CandidateSource::BuiltinImpl(source))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::solve) fn probe_trait_candidate(
|
pub(in crate::solve) fn probe_trait_candidate(
|
||||||
&mut self,
|
&mut self,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
) -> TraitProbeCtxt<'_, 'a, 'tcx, impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>>
|
) -> TraitProbeCtxt<
|
||||||
{
|
'_,
|
||||||
|
'a,
|
||||||
|
'tcx,
|
||||||
|
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
|
> {
|
||||||
TraitProbeCtxt {
|
TraitProbeCtxt {
|
||||||
cx: ProbeCtxt {
|
cx: ProbeCtxt {
|
||||||
ecx: self,
|
ecx: self,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::ops::ControlFlow;
|
||||||
|
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
use rustc_infer::traits::solve::inspect::ProbeKind;
|
|
||||||
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
|
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
|
||||||
use rustc_infer::traits::{
|
use rustc_infer::traits::{
|
||||||
self, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation,
|
self, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation,
|
||||||
|
@ -15,7 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
|
|
||||||
use super::eval_ctxt::GenerateProofTree;
|
use super::eval_ctxt::GenerateProofTree;
|
||||||
use super::inspect::{InspectCandidate, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor};
|
use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor};
|
||||||
use super::{Certainty, InferCtxtEvalExt};
|
use super::{Certainty, InferCtxtEvalExt};
|
||||||
|
|
||||||
/// A trait engine using the new trait solver.
|
/// A trait engine using the new trait solver.
|
||||||
|
@ -319,8 +318,8 @@ impl<'tcx> BestObligation<'tcx> {
|
||||||
/// *don't* hold and which have impl-where clauses that also don't hold.
|
/// *don't* hold and which have impl-where clauses that also don't hold.
|
||||||
fn non_trivial_candidates<'a>(
|
fn non_trivial_candidates<'a>(
|
||||||
&self,
|
&self,
|
||||||
goal: &'a InspectGoal<'a, 'tcx>,
|
goal: &'a inspect::InspectGoal<'a, 'tcx>,
|
||||||
) -> Vec<InspectCandidate<'a, 'tcx>> {
|
) -> Vec<inspect::InspectCandidate<'a, 'tcx>> {
|
||||||
let mut candidates = goal.candidates();
|
let mut candidates = goal.candidates();
|
||||||
match self.consider_ambiguities {
|
match self.consider_ambiguities {
|
||||||
true => {
|
true => {
|
||||||
|
@ -370,15 +369,17 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
|
||||||
self.obligation.cause.span
|
self.obligation.cause.span
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_goal(&mut self, goal: &super::inspect::InspectGoal<'_, 'tcx>) -> Self::Result {
|
fn visit_goal(&mut self, goal: &inspect::InspectGoal<'_, 'tcx>) -> Self::Result {
|
||||||
let candidates = self.non_trivial_candidates(goal);
|
let candidates = self.non_trivial_candidates(goal);
|
||||||
let [candidate] = candidates.as_slice() else {
|
let [candidate] = candidates.as_slice() else {
|
||||||
return ControlFlow::Break(self.obligation.clone());
|
return ControlFlow::Break(self.obligation.clone());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Don't walk into impls that have `do_not_recommend`.
|
// Don't walk into impls that have `do_not_recommend`.
|
||||||
if let ProbeKind::TraitCandidate { source: CandidateSource::Impl(impl_def_id), result: _ } =
|
if let inspect::ProbeKind::TraitCandidate {
|
||||||
candidate.kind()
|
source: CandidateSource::Impl(impl_def_id),
|
||||||
|
result: _,
|
||||||
|
} = candidate.kind()
|
||||||
&& goal.infcx().tcx.has_attr(impl_def_id, sym::do_not_recommend)
|
&& goal.infcx().tcx.has_attr(impl_def_id, sym::do_not_recommend)
|
||||||
{
|
{
|
||||||
return ControlFlow::Break(self.obligation.clone());
|
return ControlFlow::Break(self.obligation.clone());
|
||||||
|
@ -475,13 +476,16 @@ enum ChildMode<'tcx> {
|
||||||
|
|
||||||
fn derive_cause<'tcx>(
|
fn derive_cause<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
candidate_kind: ProbeKind<'tcx>,
|
candidate_kind: inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
mut cause: ObligationCause<'tcx>,
|
mut cause: ObligationCause<'tcx>,
|
||||||
idx: usize,
|
idx: usize,
|
||||||
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> ObligationCause<'tcx> {
|
) -> ObligationCause<'tcx> {
|
||||||
match candidate_kind {
|
match candidate_kind {
|
||||||
ProbeKind::TraitCandidate { source: CandidateSource::Impl(impl_def_id), result: _ } => {
|
inspect::ProbeKind::TraitCandidate {
|
||||||
|
source: CandidateSource::Impl(impl_def_id),
|
||||||
|
result: _,
|
||||||
|
} => {
|
||||||
if let Some((_, span)) =
|
if let Some((_, span)) =
|
||||||
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
|
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
|
||||||
{
|
{
|
||||||
|
@ -495,7 +499,10 @@ fn derive_cause<'tcx>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => {
|
inspect::ProbeKind::TraitCandidate {
|
||||||
|
source: CandidateSource::BuiltinImpl(..),
|
||||||
|
result: _,
|
||||||
|
} => {
|
||||||
cause = cause.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerived);
|
cause = cause.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerived);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc_middle::traits::query::NoSolution;
|
||||||
use rustc_middle::traits::solve::{inspect, QueryResult};
|
use rustc_middle::traits::solve::{inspect, QueryResult};
|
||||||
use rustc_middle::traits::solve::{Certainty, Goal};
|
use rustc_middle::traits::solve::{Certainty, Goal};
|
||||||
use rustc_middle::traits::ObligationCause;
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::TypeFoldable;
|
use rustc_middle::ty::{TyCtxt, TypeFoldable};
|
||||||
use rustc_middle::{bug, ty};
|
use rustc_middle::{bug, ty};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ pub struct InspectGoal<'a, 'tcx> {
|
||||||
orig_values: Vec<ty::GenericArg<'tcx>>,
|
orig_values: Vec<ty::GenericArg<'tcx>>,
|
||||||
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
||||||
result: Result<Certainty, NoSolution>,
|
result: Result<Certainty, NoSolution>,
|
||||||
evaluation_kind: inspect::CanonicalGoalEvaluationKind<'tcx>,
|
evaluation_kind: inspect::CanonicalGoalEvaluationKind<TyCtxt<'tcx>>,
|
||||||
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
|
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
|
||||||
source: GoalSource,
|
source: GoalSource,
|
||||||
}
|
}
|
||||||
|
@ -88,16 +88,17 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
|
||||||
|
|
||||||
pub struct InspectCandidate<'a, 'tcx> {
|
pub struct InspectCandidate<'a, 'tcx> {
|
||||||
goal: &'a InspectGoal<'a, 'tcx>,
|
goal: &'a InspectGoal<'a, 'tcx>,
|
||||||
kind: inspect::ProbeKind<'tcx>,
|
kind: inspect::ProbeKind<TyCtxt<'tcx>>,
|
||||||
nested_goals: Vec<(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>)>,
|
nested_goals:
|
||||||
final_state: inspect::CanonicalState<'tcx, ()>,
|
Vec<(GoalSource, inspect::CanonicalState<TyCtxt<'tcx>, Goal<'tcx, ty::Predicate<'tcx>>>)>,
|
||||||
impl_args: Option<inspect::CanonicalState<'tcx, ty::GenericArgsRef<'tcx>>>,
|
final_state: inspect::CanonicalState<TyCtxt<'tcx>, ()>,
|
||||||
|
impl_args: Option<inspect::CanonicalState<TyCtxt<'tcx>, ty::GenericArgsRef<'tcx>>>,
|
||||||
result: QueryResult<'tcx>,
|
result: QueryResult<'tcx>,
|
||||||
shallow_certainty: Certainty,
|
shallow_certainty: Certainty,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
||||||
pub fn kind(&self) -> inspect::ProbeKind<'tcx> {
|
pub fn kind(&self) -> inspect::ProbeKind<TyCtxt<'tcx>> {
|
||||||
self.kind
|
self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,9 +281,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
|
||||||
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,
|
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,
|
||||||
nested_goals: &mut Vec<(
|
nested_goals: &mut Vec<(
|
||||||
GoalSource,
|
GoalSource,
|
||||||
inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>,
|
inspect::CanonicalState<TyCtxt<'tcx>, Goal<'tcx, ty::Predicate<'tcx>>>,
|
||||||
)>,
|
)>,
|
||||||
probe: &inspect::Probe<'tcx>,
|
probe: &inspect::Probe<TyCtxt<'tcx>>,
|
||||||
) {
|
) {
|
||||||
let mut shallow_certainty = None;
|
let mut shallow_certainty = None;
|
||||||
let mut impl_args = None;
|
let mut impl_args = None;
|
||||||
|
@ -387,7 +388,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
|
||||||
fn new(
|
fn new(
|
||||||
infcx: &'a InferCtxt<'tcx>,
|
infcx: &'a InferCtxt<'tcx>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
root: inspect::GoalEvaluation<'tcx>,
|
root: inspect::GoalEvaluation<TyCtxt<'tcx>>,
|
||||||
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
|
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
|
||||||
source: GoalSource,
|
source: GoalSource,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
@ -9,11 +9,12 @@ use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::infer::canonical::CanonicalVarValues;
|
use rustc_middle::infer::canonical::CanonicalVarValues;
|
||||||
use rustc_middle::traits::query::NoSolution;
|
use rustc_middle::traits::query::NoSolution;
|
||||||
use rustc_middle::traits::solve::{
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
use rustc_next_trait_solver::solve::{
|
||||||
CanonicalInput, Certainty, Goal, GoalSource, QueryInput, QueryResult,
|
CanonicalInput, Certainty, Goal, GoalSource, QueryInput, QueryResult,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
|
||||||
use rustc_session::config::DumpSolverProofTree;
|
use rustc_session::config::DumpSolverProofTree;
|
||||||
|
use rustc_type_ir::Interner;
|
||||||
|
|
||||||
use crate::solve::eval_ctxt::canonical;
|
use crate::solve::eval_ctxt::canonical;
|
||||||
use crate::solve::{self, inspect, GenerateProofTree};
|
use crate::solve::{self, inspect, GenerateProofTree};
|
||||||
|
@ -38,49 +39,51 @@ use crate::solve::{self, inspect, GenerateProofTree};
|
||||||
/// trees. At the end of trait solving `ProofTreeBuilder::finalize`
|
/// trees. At the end of trait solving `ProofTreeBuilder::finalize`
|
||||||
/// is called to recursively convert the whole structure to a
|
/// is called to recursively convert the whole structure to a
|
||||||
/// finished proof tree.
|
/// finished proof tree.
|
||||||
pub(in crate::solve) struct ProofTreeBuilder<'tcx> {
|
pub(in crate::solve) struct ProofTreeBuilder<I: Interner> {
|
||||||
state: Option<Box<DebugSolver<'tcx>>>,
|
state: Option<Box<DebugSolver<I>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current state of the proof tree builder, at most places
|
/// The current state of the proof tree builder, at most places
|
||||||
/// in the code, only one or two variants are actually possible.
|
/// in the code, only one or two variants are actually possible.
|
||||||
///
|
///
|
||||||
/// We simply ICE in case that assumption is broken.
|
/// We simply ICE in case that assumption is broken.
|
||||||
#[derive(Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
enum DebugSolver<'tcx> {
|
#[derivative(Debug(bound = ""))]
|
||||||
|
enum DebugSolver<I: Interner> {
|
||||||
Root,
|
Root,
|
||||||
GoalEvaluation(WipGoalEvaluation<'tcx>),
|
GoalEvaluation(WipGoalEvaluation<I>),
|
||||||
CanonicalGoalEvaluation(WipCanonicalGoalEvaluation<'tcx>),
|
CanonicalGoalEvaluation(WipCanonicalGoalEvaluation<I>),
|
||||||
GoalEvaluationStep(WipGoalEvaluationStep<'tcx>),
|
GoalEvaluationStep(WipGoalEvaluationStep<I>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> From<WipGoalEvaluation<'tcx>> for DebugSolver<'tcx> {
|
impl<I: Interner> From<WipGoalEvaluation<I>> for DebugSolver<I> {
|
||||||
fn from(g: WipGoalEvaluation<'tcx>) -> DebugSolver<'tcx> {
|
fn from(g: WipGoalEvaluation<I>) -> DebugSolver<I> {
|
||||||
DebugSolver::GoalEvaluation(g)
|
DebugSolver::GoalEvaluation(g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> From<WipCanonicalGoalEvaluation<'tcx>> for DebugSolver<'tcx> {
|
impl<I: Interner> From<WipCanonicalGoalEvaluation<I>> for DebugSolver<I> {
|
||||||
fn from(g: WipCanonicalGoalEvaluation<'tcx>) -> DebugSolver<'tcx> {
|
fn from(g: WipCanonicalGoalEvaluation<I>) -> DebugSolver<I> {
|
||||||
DebugSolver::CanonicalGoalEvaluation(g)
|
DebugSolver::CanonicalGoalEvaluation(g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> From<WipGoalEvaluationStep<'tcx>> for DebugSolver<'tcx> {
|
impl<I: Interner> From<WipGoalEvaluationStep<I>> for DebugSolver<I> {
|
||||||
fn from(g: WipGoalEvaluationStep<'tcx>) -> DebugSolver<'tcx> {
|
fn from(g: WipGoalEvaluationStep<I>) -> DebugSolver<I> {
|
||||||
DebugSolver::GoalEvaluationStep(g)
|
DebugSolver::GoalEvaluationStep(g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
struct WipGoalEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
struct WipGoalEvaluation<I: Interner> {
|
||||||
pub kind: WipGoalEvaluationKind<'tcx>,
|
pub uncanonicalized_goal: Goal<I, I::Predicate>,
|
||||||
pub evaluation: Option<WipCanonicalGoalEvaluation<'tcx>>,
|
pub kind: WipGoalEvaluationKind<I>,
|
||||||
|
pub evaluation: Option<WipCanonicalGoalEvaluation<I>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipGoalEvaluation<'tcx> {
|
impl<I: Interner> WipGoalEvaluation<I> {
|
||||||
fn finalize(self) -> inspect::GoalEvaluation<'tcx> {
|
fn finalize(self) -> inspect::GoalEvaluation<I> {
|
||||||
inspect::GoalEvaluation {
|
inspect::GoalEvaluation {
|
||||||
uncanonicalized_goal: self.uncanonicalized_goal,
|
uncanonicalized_goal: self.uncanonicalized_goal,
|
||||||
kind: match self.kind {
|
kind: match self.kind {
|
||||||
|
@ -94,21 +97,23 @@ impl<'tcx> WipGoalEvaluation<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
pub(in crate::solve) enum WipGoalEvaluationKind<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
Root { orig_values: Vec<ty::GenericArg<'tcx>> },
|
pub(in crate::solve) enum WipGoalEvaluationKind<I: Interner> {
|
||||||
|
Root { orig_values: Vec<I::GenericArg> },
|
||||||
Nested,
|
Nested,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub(in crate::solve) enum WipCanonicalGoalEvaluationKind<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""))]
|
||||||
|
pub(in crate::solve) enum WipCanonicalGoalEvaluationKind<I: Interner> {
|
||||||
Overflow,
|
Overflow,
|
||||||
CycleInStack,
|
CycleInStack,
|
||||||
ProvisionalCacheHit,
|
ProvisionalCacheHit,
|
||||||
Interned { revisions: &'tcx [inspect::GoalEvaluationStep<'tcx>] },
|
Interned { revisions: I::GoalEvaluationSteps },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for WipCanonicalGoalEvaluationKind<'_> {
|
impl<I: Interner> std::fmt::Debug for WipCanonicalGoalEvaluationKind<I> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Overflow => write!(f, "Overflow"),
|
Self::Overflow => write!(f, "Overflow"),
|
||||||
|
@ -119,18 +124,19 @@ impl std::fmt::Debug for WipCanonicalGoalEvaluationKind<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
struct WipCanonicalGoalEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
goal: CanonicalInput<'tcx>,
|
struct WipCanonicalGoalEvaluation<I: Interner> {
|
||||||
kind: Option<WipCanonicalGoalEvaluationKind<'tcx>>,
|
goal: CanonicalInput<I>,
|
||||||
|
kind: Option<WipCanonicalGoalEvaluationKind<I>>,
|
||||||
/// Only used for uncached goals. After we finished evaluating
|
/// Only used for uncached goals. After we finished evaluating
|
||||||
/// the goal, this is interned and moved into `kind`.
|
/// the goal, this is interned and moved into `kind`.
|
||||||
revisions: Vec<WipGoalEvaluationStep<'tcx>>,
|
revisions: Vec<WipGoalEvaluationStep<I>>,
|
||||||
result: Option<QueryResult<'tcx>>,
|
result: Option<QueryResult<I>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipCanonicalGoalEvaluation<'tcx> {
|
impl<I: Interner> WipCanonicalGoalEvaluation<I> {
|
||||||
fn finalize(self) -> inspect::CanonicalGoalEvaluation<'tcx> {
|
fn finalize(self) -> inspect::CanonicalGoalEvaluation<I> {
|
||||||
assert!(self.revisions.is_empty());
|
assert!(self.revisions.is_empty());
|
||||||
let kind = match self.kind.unwrap() {
|
let kind = match self.kind.unwrap() {
|
||||||
WipCanonicalGoalEvaluationKind::Overflow => {
|
WipCanonicalGoalEvaluationKind::Overflow => {
|
||||||
|
@ -151,14 +157,15 @@ impl<'tcx> WipCanonicalGoalEvaluation<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
struct WipAddedGoalsEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>,
|
struct WipAddedGoalsEvaluation<I: Interner> {
|
||||||
|
evaluations: Vec<Vec<WipGoalEvaluation<I>>>,
|
||||||
result: Option<Result<Certainty, NoSolution>>,
|
result: Option<Result<Certainty, NoSolution>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipAddedGoalsEvaluation<'tcx> {
|
impl<I: Interner> WipAddedGoalsEvaluation<I> {
|
||||||
fn finalize(self) -> inspect::AddedGoalsEvaluation<'tcx> {
|
fn finalize(self) -> inspect::AddedGoalsEvaluation<I> {
|
||||||
inspect::AddedGoalsEvaluation {
|
inspect::AddedGoalsEvaluation {
|
||||||
evaluations: self
|
evaluations: self
|
||||||
.evaluations
|
.evaluations
|
||||||
|
@ -172,22 +179,23 @@ impl<'tcx> WipAddedGoalsEvaluation<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
struct WipGoalEvaluationStep<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
|
struct WipGoalEvaluationStep<I: Interner> {
|
||||||
/// Unlike `EvalCtxt::var_values`, we append a new
|
/// Unlike `EvalCtxt::var_values`, we append a new
|
||||||
/// generic arg here whenever we create a new inference
|
/// generic arg here whenever we create a new inference
|
||||||
/// variable.
|
/// variable.
|
||||||
///
|
///
|
||||||
/// This is necessary as we otherwise don't unify these
|
/// This is necessary as we otherwise don't unify these
|
||||||
/// vars when instantiating multiple `CanonicalState`.
|
/// vars when instantiating multiple `CanonicalState`.
|
||||||
var_values: Vec<ty::GenericArg<'tcx>>,
|
var_values: Vec<I::GenericArg>,
|
||||||
instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
|
instantiated_goal: QueryInput<I, I::Predicate>,
|
||||||
probe_depth: usize,
|
probe_depth: usize,
|
||||||
evaluation: WipProbe<'tcx>,
|
evaluation: WipProbe<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipGoalEvaluationStep<'tcx> {
|
impl<I: Interner> WipGoalEvaluationStep<I> {
|
||||||
fn current_evaluation_scope(&mut self) -> &mut WipProbe<'tcx> {
|
fn current_evaluation_scope(&mut self) -> &mut WipProbe<I> {
|
||||||
let mut current = &mut self.evaluation;
|
let mut current = &mut self.evaluation;
|
||||||
for _ in 0..self.probe_depth {
|
for _ in 0..self.probe_depth {
|
||||||
match current.steps.last_mut() {
|
match current.steps.last_mut() {
|
||||||
|
@ -198,7 +206,7 @@ impl<'tcx> WipGoalEvaluationStep<'tcx> {
|
||||||
current
|
current
|
||||||
}
|
}
|
||||||
|
|
||||||
fn added_goals_evaluation(&mut self) -> &mut WipAddedGoalsEvaluation<'tcx> {
|
fn added_goals_evaluation(&mut self) -> &mut WipAddedGoalsEvaluation<I> {
|
||||||
let mut current = &mut self.evaluation;
|
let mut current = &mut self.evaluation;
|
||||||
loop {
|
loop {
|
||||||
match current.steps.last_mut() {
|
match current.steps.last_mut() {
|
||||||
|
@ -209,7 +217,7 @@ impl<'tcx> WipGoalEvaluationStep<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(self) -> inspect::GoalEvaluationStep<'tcx> {
|
fn finalize(self) -> inspect::GoalEvaluationStep<I> {
|
||||||
let evaluation = self.evaluation.finalize();
|
let evaluation = self.evaluation.finalize();
|
||||||
match evaluation.kind {
|
match evaluation.kind {
|
||||||
inspect::ProbeKind::Root { .. } => (),
|
inspect::ProbeKind::Root { .. } => (),
|
||||||
|
@ -219,16 +227,17 @@ impl<'tcx> WipGoalEvaluationStep<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
struct WipProbe<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
|
struct WipProbe<I: Interner> {
|
||||||
initial_num_var_values: usize,
|
initial_num_var_values: usize,
|
||||||
steps: Vec<WipProbeStep<'tcx>>,
|
steps: Vec<WipProbeStep<I>>,
|
||||||
kind: Option<inspect::ProbeKind<'tcx>>,
|
kind: Option<inspect::ProbeKind<I>>,
|
||||||
final_state: Option<inspect::CanonicalState<'tcx, ()>>,
|
final_state: Option<inspect::CanonicalState<I, ()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipProbe<'tcx> {
|
impl<I: Interner> WipProbe<I> {
|
||||||
fn finalize(self) -> inspect::Probe<'tcx> {
|
fn finalize(self) -> inspect::Probe<I> {
|
||||||
inspect::Probe {
|
inspect::Probe {
|
||||||
steps: self.steps.into_iter().map(WipProbeStep::finalize).collect(),
|
steps: self.steps.into_iter().map(WipProbeStep::finalize).collect(),
|
||||||
kind: self.kind.unwrap(),
|
kind: self.kind.unwrap(),
|
||||||
|
@ -237,17 +246,18 @@ impl<'tcx> WipProbe<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
enum WipProbeStep<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
|
||||||
AddGoal(GoalSource, inspect::CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
|
enum WipProbeStep<I: Interner> {
|
||||||
EvaluateGoals(WipAddedGoalsEvaluation<'tcx>),
|
AddGoal(GoalSource, inspect::CanonicalState<I, Goal<I, I::Predicate>>),
|
||||||
NestedProbe(WipProbe<'tcx>),
|
EvaluateGoals(WipAddedGoalsEvaluation<I>),
|
||||||
|
NestedProbe(WipProbe<I>),
|
||||||
MakeCanonicalResponse { shallow_certainty: Certainty },
|
MakeCanonicalResponse { shallow_certainty: Certainty },
|
||||||
RecordImplArgs { impl_args: inspect::CanonicalState<'tcx, ty::GenericArgsRef<'tcx>> },
|
RecordImplArgs { impl_args: inspect::CanonicalState<I, I::GenericArgs> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> WipProbeStep<'tcx> {
|
impl<I: Interner> WipProbeStep<I> {
|
||||||
fn finalize(self) -> inspect::ProbeStep<'tcx> {
|
fn finalize(self) -> inspect::ProbeStep<I> {
|
||||||
match self {
|
match self {
|
||||||
WipProbeStep::AddGoal(source, goal) => inspect::ProbeStep::AddGoal(source, goal),
|
WipProbeStep::AddGoal(source, goal) => inspect::ProbeStep::AddGoal(source, goal),
|
||||||
WipProbeStep::EvaluateGoals(eval) => inspect::ProbeStep::EvaluateGoals(eval.finalize()),
|
WipProbeStep::EvaluateGoals(eval) => inspect::ProbeStep::EvaluateGoals(eval.finalize()),
|
||||||
|
@ -262,26 +272,27 @@ impl<'tcx> WipProbeStep<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ProofTreeBuilder<'tcx> {
|
// FIXME: Genericize this impl.
|
||||||
fn new(state: impl Into<DebugSolver<'tcx>>) -> ProofTreeBuilder<'tcx> {
|
impl<'tcx> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
|
fn new(state: impl Into<DebugSolver<TyCtxt<'tcx>>>) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
ProofTreeBuilder { state: Some(Box::new(state.into())) }
|
ProofTreeBuilder { state: Some(Box::new(state.into())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nested<T: Into<DebugSolver<'tcx>>>(&self, state: impl FnOnce() -> T) -> Self {
|
fn nested<T: Into<DebugSolver<TyCtxt<'tcx>>>>(&self, state: impl FnOnce() -> T) -> Self {
|
||||||
ProofTreeBuilder { state: self.state.as_ref().map(|_| Box::new(state().into())) }
|
ProofTreeBuilder { state: self.state.as_ref().map(|_| Box::new(state().into())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_mut(&mut self) -> Option<&mut DebugSolver<'tcx>> {
|
fn as_mut(&mut self) -> Option<&mut DebugSolver<TyCtxt<'tcx>>> {
|
||||||
self.state.as_deref_mut()
|
self.state.as_deref_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder<'tcx> {
|
pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
let mut nested = ProofTreeBuilder { state: self.state.take() };
|
let mut nested = ProofTreeBuilder { state: self.state.take() };
|
||||||
nested.enter_probe();
|
nested.enter_probe();
|
||||||
nested
|
nested
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalize(self) -> Option<inspect::GoalEvaluation<'tcx>> {
|
pub fn finalize(self) -> Option<inspect::GoalEvaluation<TyCtxt<'tcx>>> {
|
||||||
match *self.state? {
|
match *self.state? {
|
||||||
DebugSolver::GoalEvaluation(wip_goal_evaluation) => {
|
DebugSolver::GoalEvaluation(wip_goal_evaluation) => {
|
||||||
Some(wip_goal_evaluation.finalize())
|
Some(wip_goal_evaluation.finalize())
|
||||||
|
@ -293,7 +304,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
pub fn new_maybe_root(
|
pub fn new_maybe_root(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
generate_proof_tree: GenerateProofTree,
|
generate_proof_tree: GenerateProofTree,
|
||||||
) -> ProofTreeBuilder<'tcx> {
|
) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
match generate_proof_tree {
|
match generate_proof_tree {
|
||||||
GenerateProofTree::Never => ProofTreeBuilder::new_noop(),
|
GenerateProofTree::Never => ProofTreeBuilder::new_noop(),
|
||||||
GenerateProofTree::IfEnabled => {
|
GenerateProofTree::IfEnabled => {
|
||||||
|
@ -311,11 +322,11 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_root() -> ProofTreeBuilder<'tcx> {
|
pub fn new_root() -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
ProofTreeBuilder::new(DebugSolver::Root)
|
ProofTreeBuilder::new(DebugSolver::Root)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_noop() -> ProofTreeBuilder<'tcx> {
|
pub fn new_noop() -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
ProofTreeBuilder { state: None }
|
ProofTreeBuilder { state: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,10 +336,10 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
|
|
||||||
pub(in crate::solve) fn new_goal_evaluation(
|
pub(in crate::solve) fn new_goal_evaluation(
|
||||||
&mut self,
|
&mut self,
|
||||||
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
goal: Goal<TyCtxt<'tcx>, ty::Predicate<'tcx>>,
|
||||||
orig_values: &[ty::GenericArg<'tcx>],
|
orig_values: &[ty::GenericArg<'tcx>],
|
||||||
kind: solve::GoalEvaluationKind,
|
kind: solve::GoalEvaluationKind,
|
||||||
) -> ProofTreeBuilder<'tcx> {
|
) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
self.nested(|| WipGoalEvaluation {
|
self.nested(|| WipGoalEvaluation {
|
||||||
uncanonicalized_goal: goal,
|
uncanonicalized_goal: goal,
|
||||||
kind: match kind {
|
kind: match kind {
|
||||||
|
@ -343,8 +354,8 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
|
|
||||||
pub fn new_canonical_goal_evaluation(
|
pub fn new_canonical_goal_evaluation(
|
||||||
&mut self,
|
&mut self,
|
||||||
goal: CanonicalInput<'tcx>,
|
goal: CanonicalInput<TyCtxt<'tcx>>,
|
||||||
) -> ProofTreeBuilder<'tcx> {
|
) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
self.nested(|| WipCanonicalGoalEvaluation {
|
self.nested(|| WipCanonicalGoalEvaluation {
|
||||||
goal,
|
goal,
|
||||||
kind: None,
|
kind: None,
|
||||||
|
@ -356,7 +367,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
pub fn finalize_evaluation(
|
pub fn finalize_evaluation(
|
||||||
&mut self,
|
&mut self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]> {
|
) -> Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]> {
|
||||||
self.as_mut().map(|this| match this {
|
self.as_mut().map(|this| match this {
|
||||||
DebugSolver::CanonicalGoalEvaluation(evaluation) => {
|
DebugSolver::CanonicalGoalEvaluation(evaluation) => {
|
||||||
let revisions = mem::take(&mut evaluation.revisions)
|
let revisions = mem::take(&mut evaluation.revisions)
|
||||||
|
@ -371,7 +382,10 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn canonical_goal_evaluation(&mut self, canonical_goal_evaluation: ProofTreeBuilder<'tcx>) {
|
pub fn canonical_goal_evaluation(
|
||||||
|
&mut self,
|
||||||
|
canonical_goal_evaluation: ProofTreeBuilder<TyCtxt<'tcx>>,
|
||||||
|
) {
|
||||||
if let Some(this) = self.as_mut() {
|
if let Some(this) = self.as_mut() {
|
||||||
match (this, *canonical_goal_evaluation.state.unwrap()) {
|
match (this, *canonical_goal_evaluation.state.unwrap()) {
|
||||||
(
|
(
|
||||||
|
@ -386,7 +400,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goal_evaluation_kind(&mut self, kind: WipCanonicalGoalEvaluationKind<'tcx>) {
|
pub fn goal_evaluation_kind(&mut self, kind: WipCanonicalGoalEvaluationKind<TyCtxt<'tcx>>) {
|
||||||
if let Some(this) = self.as_mut() {
|
if let Some(this) = self.as_mut() {
|
||||||
match this {
|
match this {
|
||||||
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
||||||
|
@ -397,7 +411,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder<'tcx>) {
|
pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder<TyCtxt<'tcx>>) {
|
||||||
if let Some(this) = self.as_mut() {
|
if let Some(this) = self.as_mut() {
|
||||||
match (this, *goal_evaluation.state.unwrap()) {
|
match (this, *goal_evaluation.state.unwrap()) {
|
||||||
(
|
(
|
||||||
|
@ -418,8 +432,8 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
pub fn new_goal_evaluation_step(
|
pub fn new_goal_evaluation_step(
|
||||||
&mut self,
|
&mut self,
|
||||||
var_values: CanonicalVarValues<'tcx>,
|
var_values: CanonicalVarValues<'tcx>,
|
||||||
instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
|
instantiated_goal: QueryInput<TyCtxt<'tcx>, ty::Predicate<'tcx>>,
|
||||||
) -> ProofTreeBuilder<'tcx> {
|
) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
self.nested(|| WipGoalEvaluationStep {
|
self.nested(|| WipGoalEvaluationStep {
|
||||||
var_values: var_values.var_values.to_vec(),
|
var_values: var_values.var_values.to_vec(),
|
||||||
instantiated_goal,
|
instantiated_goal,
|
||||||
|
@ -433,7 +447,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder<'tcx>) {
|
pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder<TyCtxt<'tcx>>) {
|
||||||
if let Some(this) = self.as_mut() {
|
if let Some(this) = self.as_mut() {
|
||||||
match (this, *goal_evaluation_step.state.unwrap()) {
|
match (this, *goal_evaluation_step.state.unwrap()) {
|
||||||
(
|
(
|
||||||
|
@ -474,7 +488,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn probe_kind(&mut self, probe_kind: inspect::ProbeKind<'tcx>) {
|
pub fn probe_kind(&mut self, probe_kind: inspect::ProbeKind<TyCtxt<'tcx>>) {
|
||||||
match self.as_mut() {
|
match self.as_mut() {
|
||||||
None => {}
|
None => {}
|
||||||
Some(DebugSolver::GoalEvaluationStep(state)) => {
|
Some(DebugSolver::GoalEvaluationStep(state)) => {
|
||||||
|
@ -510,7 +524,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
max_input_universe: ty::UniverseIndex,
|
max_input_universe: ty::UniverseIndex,
|
||||||
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
|
goal: Goal<TyCtxt<'tcx>, ty::NormalizesTo<'tcx>>,
|
||||||
) {
|
) {
|
||||||
self.add_goal(
|
self.add_goal(
|
||||||
infcx,
|
infcx,
|
||||||
|
@ -525,7 +539,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
max_input_universe: ty::UniverseIndex,
|
max_input_universe: ty::UniverseIndex,
|
||||||
source: GoalSource,
|
source: GoalSource,
|
||||||
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
goal: Goal<TyCtxt<'tcx>, ty::Predicate<'tcx>>,
|
||||||
) {
|
) {
|
||||||
match self.as_mut() {
|
match self.as_mut() {
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -579,7 +593,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish_probe(mut self) -> ProofTreeBuilder<'tcx> {
|
pub fn finish_probe(mut self) -> ProofTreeBuilder<TyCtxt<'tcx>> {
|
||||||
match self.as_mut() {
|
match self.as_mut() {
|
||||||
None => {}
|
None => {}
|
||||||
Some(DebugSolver::GoalEvaluationStep(state)) => {
|
Some(DebugSolver::GoalEvaluationStep(state)) => {
|
||||||
|
@ -627,7 +641,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query_result(&mut self, result: QueryResult<'tcx>) {
|
pub fn query_result(&mut self, result: QueryResult<TyCtxt<'tcx>>) {
|
||||||
if let Some(this) = self.as_mut() {
|
if let Some(this) = self.as_mut() {
|
||||||
match this {
|
match this {
|
||||||
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
||||||
|
|
|
@ -20,11 +20,11 @@ use rustc_macros::extension;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
||||||
use rustc_middle::traits::solve::{
|
use rustc_middle::traits::solve::{
|
||||||
CanonicalResponse, Certainty, ExternalConstraintsData, GoalSource, QueryResult, Response,
|
CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, QueryResult, Response,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, AliasRelationDirection, CoercePredicate, Goal, RegionOutlivesPredicate, SubtypePredicate,
|
self, AliasRelationDirection, CoercePredicate, RegionOutlivesPredicate, SubtypePredicate, Ty,
|
||||||
Ty, TyCtxt, TypeOutlivesPredicate, UniverseIndex,
|
TyCtxt, TypeOutlivesPredicate, UniverseIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod alias_relate;
|
mod alias_relate;
|
||||||
|
@ -74,7 +74,7 @@ enum GoalEvaluationKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[extension(trait CanonicalResponseExt)]
|
#[extension(trait CanonicalResponseExt)]
|
||||||
impl<'tcx> Canonical<'tcx, Response<'tcx>> {
|
impl<'tcx> Canonical<'tcx, Response<TyCtxt<'tcx>>> {
|
||||||
fn has_no_inference_or_external_constraints(&self) -> bool {
|
fn has_no_inference_or_external_constraints(&self) -> bool {
|
||||||
self.value.external_constraints.region_constraints.is_empty()
|
self.value.external_constraints.region_constraints.is_empty()
|
||||||
&& self.value.var_values.is_identity()
|
&& self.value.var_values.is_identity()
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::traits::specialization_graph;
|
||||||
use super::assembly::structural_traits::AsyncCallableRelevantTypes;
|
use super::assembly::structural_traits::AsyncCallableRelevantTypes;
|
||||||
use super::assembly::{self, structural_traits, Candidate};
|
use super::assembly::{self, structural_traits, Candidate};
|
||||||
use super::{EvalCtxt, GoalSource};
|
use super::{EvalCtxt, GoalSource};
|
||||||
use rustc_hir::def::DefKind;
|
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::LangItem;
|
use rustc_hir::LangItem;
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
|
@ -54,23 +53,15 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
goal: Goal<'tcx, NormalizesTo<'tcx>>,
|
goal: Goal<'tcx, NormalizesTo<'tcx>>,
|
||||||
) -> QueryResult<'tcx> {
|
) -> QueryResult<'tcx> {
|
||||||
let def_id = goal.predicate.def_id();
|
match goal.predicate.alias.kind(self.tcx()) {
|
||||||
match self.tcx().def_kind(def_id) {
|
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
|
||||||
DefKind::AssocTy | DefKind::AssocConst => {
|
let candidates = self.assemble_and_evaluate_candidates(goal);
|
||||||
match self.tcx().associated_item(def_id).container {
|
self.merge_candidates(candidates)
|
||||||
ty::AssocItemContainer::TraitContainer => {
|
|
||||||
let candidates = self.assemble_and_evaluate_candidates(goal);
|
|
||||||
self.merge_candidates(candidates)
|
|
||||||
}
|
|
||||||
ty::AssocItemContainer::ImplContainer => {
|
|
||||||
self.normalize_inherent_associated_type(goal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DefKind::AnonConst => self.normalize_anon_const(goal),
|
ty::AliasTermKind::InherentTy => self.normalize_inherent_associated_type(goal),
|
||||||
DefKind::TyAlias => self.normalize_weak_type(goal),
|
ty::AliasTermKind::OpaqueTy => self.normalize_opaque_type(goal),
|
||||||
DefKind::OpaqueTy => self.normalize_opaque_type(goal),
|
ty::AliasTermKind::WeakTy => self.normalize_weak_type(goal),
|
||||||
kind => bug!("unknown DefKind {} in normalizes-to goal: {goal:#?}", kind.descr(def_id)),
|
ty::AliasTermKind::UnevaluatedConst => self.normalize_anon_const(goal),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +99,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
||||||
|
|
||||||
fn probe_and_match_goal_against_assumption(
|
fn probe_and_match_goal_against_assumption(
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
assumption: ty::Clause<'tcx>,
|
assumption: ty::Clause<'tcx>,
|
||||||
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
||||||
|
|
|
@ -253,8 +253,8 @@ impl<'tcx> SearchGraph<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
input: CanonicalInput<'tcx>,
|
input: CanonicalInput<'tcx>,
|
||||||
inspect: &mut ProofTreeBuilder<'tcx>,
|
inspect: &mut ProofTreeBuilder<TyCtxt<'tcx>>,
|
||||||
mut prove_goal: impl FnMut(&mut Self, &mut ProofTreeBuilder<'tcx>) -> QueryResult<'tcx>,
|
mut prove_goal: impl FnMut(&mut Self, &mut ProofTreeBuilder<TyCtxt<'tcx>>) -> QueryResult<'tcx>,
|
||||||
) -> QueryResult<'tcx> {
|
) -> QueryResult<'tcx> {
|
||||||
// Check for overflow.
|
// Check for overflow.
|
||||||
let Some(available_depth) = Self::allowed_depth_for_nested(tcx, &self.stack) else {
|
let Some(available_depth) = Self::allowed_depth_for_nested(tcx, &self.stack) else {
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
||||||
|
|
||||||
fn probe_and_match_goal_against_assumption(
|
fn probe_and_match_goal_against_assumption(
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
assumption: ty::Clause<'tcx>,
|
assumption: ty::Clause<'tcx>,
|
||||||
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
|
||||||
|
@ -821,7 +821,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
fn consider_builtin_upcast_to_principal(
|
fn consider_builtin_upcast_to_principal(
|
||||||
&mut self,
|
&mut self,
|
||||||
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
|
goal: Goal<'tcx, (Ty<'tcx>, Ty<'tcx>)>,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
a_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
a_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||||
a_region: ty::Region<'tcx>,
|
a_region: ty::Region<'tcx>,
|
||||||
b_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
b_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||||
|
@ -1149,7 +1149,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
/// wrapped in one.
|
/// wrapped in one.
|
||||||
fn probe_and_evaluate_goal_for_constituent_tys(
|
fn probe_and_evaluate_goal_for_constituent_tys(
|
||||||
&mut self,
|
&mut self,
|
||||||
source: CandidateSource,
|
source: CandidateSource<'tcx>,
|
||||||
goal: Goal<'tcx, TraitPredicate<'tcx>>,
|
goal: Goal<'tcx, TraitPredicate<'tcx>>,
|
||||||
constituent_tys: impl Fn(
|
constituent_tys: impl Fn(
|
||||||
&EvalCtxt<'_, 'tcx>,
|
&EvalCtxt<'_, 'tcx>,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
|
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
|
||||||
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
|
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::ops::Index;
|
||||||
|
|
||||||
use crate::inherent::*;
|
use crate::inherent::*;
|
||||||
use crate::{Interner, UniverseIndex};
|
use crate::{self as ty, Interner, UniverseIndex};
|
||||||
|
|
||||||
/// A "canonicalized" type `V` is one where all free inference
|
/// A "canonicalized" type `V` is one where all free inference
|
||||||
/// variables have been rewritten to "canonical vars". These are
|
/// variables have been rewritten to "canonical vars". These are
|
||||||
|
@ -257,3 +258,139 @@ pub enum CanonicalTyVarKind {
|
||||||
/// Floating-point type variable `?F` (that can only be unified with float types).
|
/// Floating-point type variable `?F` (that can only be unified with float types).
|
||||||
Float,
|
Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
///
|
||||||
|
/// When you canonicalize a value `V`, you get back one of these
|
||||||
|
/// vectors with the original values that were replaced by canonical
|
||||||
|
/// variables. You will need to supply it later to instantiate the
|
||||||
|
/// canonicalized query response.
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = ""),
|
||||||
|
Copy(bound = ""),
|
||||||
|
PartialEq(bound = ""),
|
||||||
|
Eq(bound = ""),
|
||||||
|
Hash(bound = ""),
|
||||||
|
Debug(bound = "")
|
||||||
|
)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
|
||||||
|
pub struct CanonicalVarValues<I: Interner> {
|
||||||
|
pub var_values: I::GenericArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Interner> CanonicalVarValues<I> {
|
||||||
|
pub fn is_identity(&self) -> bool {
|
||||||
|
self.var_values.into_iter().enumerate().all(|(bv, arg)| match arg.kind() {
|
||||||
|
ty::GenericArgKind::Lifetime(r) => {
|
||||||
|
matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if br.var().as_usize() == bv)
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Type(ty) => {
|
||||||
|
matches!(ty.kind(), ty::Bound(ty::INNERMOST, bt) if bt.var().as_usize() == bv)
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Const(ct) => {
|
||||||
|
matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc.var().as_usize() == bv)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_identity_modulo_regions(&self) -> bool {
|
||||||
|
let mut var = ty::BoundVar::ZERO;
|
||||||
|
for arg in self.var_values {
|
||||||
|
match arg.kind() {
|
||||||
|
ty::GenericArgKind::Lifetime(r) => {
|
||||||
|
if matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if var == br.var()) {
|
||||||
|
var = var + 1;
|
||||||
|
} else {
|
||||||
|
// It's ok if this region var isn't an identity variable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Type(ty) => {
|
||||||
|
if matches!(ty.kind(), ty::Bound(ty::INNERMOST, bt) if var == bt.var()) {
|
||||||
|
var = var + 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Const(ct) => {
|
||||||
|
if matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if var == bc.var())
|
||||||
|
{
|
||||||
|
var = var + 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a list of canonical variables, construct a set of values which are
|
||||||
|
// the identity response.
|
||||||
|
pub fn make_identity(tcx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
|
||||||
|
CanonicalVarValues {
|
||||||
|
var_values: tcx.mk_args_from_iter(infos.into_iter().enumerate().map(
|
||||||
|
|(i, info)| -> I::GenericArg {
|
||||||
|
match info.kind {
|
||||||
|
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
|
||||||
|
Ty::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
|
||||||
|
Region::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
CanonicalVarKind::Effect => Const::new_anon_bound(
|
||||||
|
tcx,
|
||||||
|
ty::INNERMOST,
|
||||||
|
ty::BoundVar::from_usize(i),
|
||||||
|
Ty::new_bool(tcx),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
CanonicalVarKind::Const(_, ty)
|
||||||
|
| CanonicalVarKind::PlaceholderConst(_, ty) => Const::new_anon_bound(
|
||||||
|
tcx,
|
||||||
|
ty::INNERMOST,
|
||||||
|
ty::BoundVar::from_usize(i),
|
||||||
|
ty,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates dummy var values which should not be used in a
|
||||||
|
/// canonical response.
|
||||||
|
pub fn dummy() -> CanonicalVarValues<I> {
|
||||||
|
CanonicalVarValues { var_values: Default::default() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.var_values.len()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, I: Interner> IntoIterator for &'a CanonicalVarValues<I> {
|
||||||
|
type Item = I::GenericArg;
|
||||||
|
type IntoIter = <I::GenericArgs as IntoIterator>::IntoIter;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.var_values.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Interner> Index<ty::BoundVar> for CanonicalVarValues<I> {
|
||||||
|
type Output = I::GenericArg;
|
||||||
|
|
||||||
|
fn index(&self, value: ty::BoundVar) -> &I::GenericArg {
|
||||||
|
&self.var_values[value.as_usize()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
18
compiler/rustc_type_ir/src/generic_arg.rs
Normal file
18
compiler/rustc_type_ir/src/generic_arg.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
|
||||||
|
|
||||||
|
use crate::Interner;
|
||||||
|
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = ""),
|
||||||
|
Copy(bound = ""),
|
||||||
|
Debug(bound = ""),
|
||||||
|
Eq(bound = ""),
|
||||||
|
PartialEq(bound = "")
|
||||||
|
)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
|
||||||
|
pub enum GenericArgKind<I: Interner> {
|
||||||
|
Lifetime(I::Region),
|
||||||
|
Type(I::Ty),
|
||||||
|
Const(I::Const),
|
||||||
|
}
|
|
@ -1,3 +1,8 @@
|
||||||
|
//! 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).
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -21,6 +26,8 @@ pub trait Ty<I: Interner<Ty = Self>>:
|
||||||
+ TypeSuperFoldable<I>
|
+ TypeSuperFoldable<I>
|
||||||
+ Flags
|
+ Flags
|
||||||
{
|
{
|
||||||
|
fn new_bool(interner: I) -> Self;
|
||||||
|
|
||||||
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
|
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
|
||||||
|
|
||||||
fn new_alias(interner: I, kind: AliasTyKind, alias_ty: AliasTy<I>) -> Self;
|
fn new_alias(interner: I, kind: AliasTyKind, alias_ty: AliasTy<I>) -> Self;
|
||||||
|
@ -79,6 +86,7 @@ pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
|
||||||
+ Eq
|
+ Eq
|
||||||
+ IntoIterator<Item = I::GenericArg>
|
+ IntoIterator<Item = I::GenericArg>
|
||||||
+ Deref<Target: Deref<Target = [I::GenericArg]>>
|
+ Deref<Target: Deref<Target = [I::GenericArg]>>
|
||||||
|
+ Default
|
||||||
{
|
{
|
||||||
fn type_at(self, i: usize) -> I::Ty;
|
fn type_at(self, i: usize) -> I::Ty;
|
||||||
|
|
||||||
|
@ -111,3 +119,7 @@ pub trait BoundVars<I: Interner> {
|
||||||
|
|
||||||
fn has_no_bound_vars(&self) -> bool;
|
fn has_no_bound_vars(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BoundVarLike<I: Interner> {
|
||||||
|
fn var(self) -> BoundVar;
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@ use std::ops::Deref;
|
||||||
|
|
||||||
use crate::inherent::*;
|
use crate::inherent::*;
|
||||||
use crate::ir_print::IrPrint;
|
use crate::ir_print::IrPrint;
|
||||||
|
use crate::solve::inspect::GoalEvaluationStep;
|
||||||
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
|
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
|
||||||
use crate::{
|
use crate::{
|
||||||
AliasTerm, AliasTermKind, AliasTy, AliasTyKind, CanonicalVarInfo, CoercePredicate,
|
AliasTerm, AliasTermKind, AliasTy, AliasTyKind, CanonicalVarInfo, CoercePredicate,
|
||||||
DebugWithInfcx, ExistentialProjection, ExistentialTraitRef, FnSig, NormalizesTo,
|
DebugWithInfcx, ExistentialProjection, ExistentialTraitRef, FnSig, GenericArgKind,
|
||||||
ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef,
|
NormalizesTo, ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Interner:
|
pub trait Interner:
|
||||||
|
@ -28,14 +29,13 @@ pub trait Interner:
|
||||||
+ IrPrint<FnSig<Self>>
|
+ IrPrint<FnSig<Self>>
|
||||||
{
|
{
|
||||||
type DefId: Copy + Debug + Hash + Eq;
|
type DefId: Copy + Debug + Hash + Eq;
|
||||||
type DefiningOpaqueTypes: Copy + Debug + Hash + Default + Eq + TypeVisitable<Self>;
|
|
||||||
type AdtDef: Copy + Debug + Hash + Eq;
|
type AdtDef: Copy + Debug + Hash + Eq;
|
||||||
|
|
||||||
type GenericArgs: GenericArgs<Self>;
|
type GenericArgs: GenericArgs<Self>;
|
||||||
/// The slice of args for a specific item. For a GAT like `type Foo<'a>`, it will be `['a]`,
|
/// The slice of args for a specific item. For a GAT like `type Foo<'a>`, it will be `['a]`,
|
||||||
/// not including the args from the parent item (trait or impl).
|
/// not including the args from the parent item (trait or impl).
|
||||||
type OwnItemArgs: Copy + Debug + Hash + Eq;
|
type OwnItemArgs: Copy + Debug + Hash + Eq;
|
||||||
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Eq + IntoKind<Kind = GenericArgKind<Self>>;
|
||||||
type Term: Copy + Debug + Hash + Eq;
|
type Term: Copy + Debug + Hash + Eq;
|
||||||
|
|
||||||
type Binder<T: TypeVisitable<Self>>: BoundVars<Self> + TypeSuperVisitable<Self>;
|
type Binder<T: TypeVisitable<Self>>: BoundVars<Self> + TypeSuperVisitable<Self>;
|
||||||
|
@ -43,13 +43,17 @@ pub trait Interner:
|
||||||
type BoundVar;
|
type BoundVar;
|
||||||
|
|
||||||
type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator<Item = CanonicalVarInfo<Self>>;
|
type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator<Item = CanonicalVarInfo<Self>>;
|
||||||
|
type PredefinedOpaques: Copy + Debug + Hash + Eq;
|
||||||
|
type DefiningOpaqueTypes: Copy + Debug + Hash + Default + Eq + TypeVisitable<Self>;
|
||||||
|
type ExternalConstraints: Copy + Debug + Hash + Eq;
|
||||||
|
type GoalEvaluationSteps: Copy + Debug + Hash + Eq + Deref<Target = [GoalEvaluationStep<Self>]>;
|
||||||
|
|
||||||
// Kinds of tys
|
// Kinds of tys
|
||||||
type Ty: Ty<Self>;
|
type Ty: Ty<Self>;
|
||||||
type Tys: Tys<Self>;
|
type Tys: Tys<Self>;
|
||||||
type FnInputTys: Copy + Debug + Hash + Eq + Deref<Target = [Self::Ty]>;
|
type FnInputTys: Copy + Debug + Hash + Eq + Deref<Target = [Self::Ty]>;
|
||||||
type ParamTy: Copy + Debug + Hash + Eq;
|
type ParamTy: Copy + Debug + Hash + Eq;
|
||||||
type BoundTy: Copy + Debug + Hash + Eq;
|
type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
|
||||||
type PlaceholderTy: PlaceholderLike;
|
type PlaceholderTy: PlaceholderLike;
|
||||||
|
|
||||||
// Things stored inside of tys
|
// Things stored inside of tys
|
||||||
|
@ -66,7 +70,7 @@ pub trait Interner:
|
||||||
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
||||||
type PlaceholderConst: PlaceholderLike;
|
type PlaceholderConst: PlaceholderLike;
|
||||||
type ParamConst: Copy + Debug + Hash + Eq;
|
type ParamConst: Copy + Debug + Hash + Eq;
|
||||||
type BoundConst: Copy + Debug + Hash + Eq;
|
type BoundConst: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
|
||||||
type ValueConst: Copy + Debug + Hash + Eq;
|
type ValueConst: Copy + Debug + Hash + Eq;
|
||||||
type ExprConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
type ExprConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
||||||
|
|
||||||
|
@ -74,7 +78,7 @@ pub trait Interner:
|
||||||
type Region: Region<Self>;
|
type Region: Region<Self>;
|
||||||
type EarlyParamRegion: Copy + Debug + Hash + Eq;
|
type EarlyParamRegion: Copy + Debug + Hash + Eq;
|
||||||
type LateParamRegion: Copy + Debug + Hash + Eq;
|
type LateParamRegion: Copy + Debug + Hash + Eq;
|
||||||
type BoundRegion: Copy + Debug + Hash + Eq;
|
type BoundRegion: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
|
||||||
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Eq;
|
||||||
type PlaceholderRegion: PlaceholderLike;
|
type PlaceholderRegion: PlaceholderLike;
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ use std::sync::Arc as Lrc;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod visit;
|
pub mod visit;
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
pub mod codec;
|
pub mod codec;
|
||||||
pub mod fold;
|
pub mod fold;
|
||||||
pub mod inherent;
|
pub mod inherent;
|
||||||
pub mod ir_print;
|
pub mod ir_print;
|
||||||
pub mod lift;
|
pub mod lift;
|
||||||
|
pub mod solve;
|
||||||
pub mod ty_info;
|
pub mod ty_info;
|
||||||
pub mod ty_kind;
|
pub mod ty_kind;
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ mod canonical;
|
||||||
mod const_kind;
|
mod const_kind;
|
||||||
mod debug;
|
mod debug;
|
||||||
mod flags;
|
mod flags;
|
||||||
|
mod generic_arg;
|
||||||
mod infcx;
|
mod infcx;
|
||||||
mod interner;
|
mod interner;
|
||||||
mod predicate;
|
mod predicate;
|
||||||
|
@ -48,6 +49,7 @@ pub use codec::*;
|
||||||
pub use const_kind::*;
|
pub use const_kind::*;
|
||||||
pub use debug::{DebugWithInfcx, WithInfcx};
|
pub use debug::{DebugWithInfcx, WithInfcx};
|
||||||
pub use flags::*;
|
pub use flags::*;
|
||||||
|
pub use generic_arg::*;
|
||||||
pub use infcx::InferCtxtLike;
|
pub use infcx::InferCtxtLike;
|
||||||
pub use interner::*;
|
pub use interner::*;
|
||||||
pub use predicate::*;
|
pub use predicate::*;
|
||||||
|
@ -368,6 +370,12 @@ rustc_index::newtype_index! {
|
||||||
pub struct BoundVar {}
|
pub struct BoundVar {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<I: Interner> inherent::BoundVarLike<I> for BoundVar {
|
||||||
|
fn var(self) -> BoundVar {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents the various closure traits in the language. This
|
/// Represents the various closure traits in the language. This
|
||||||
/// will determine the type of the environment (`self`, in the
|
/// will determine the type of the environment (`self`, in the
|
||||||
/// desugaring) argument that the closure expects.
|
/// desugaring) argument that the closure expects.
|
||||||
|
|
|
@ -8,42 +8,9 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
|
||||||
use crate::inherent::*;
|
use crate::inherent::*;
|
||||||
use crate::visit::TypeVisitableExt as _;
|
use crate::visit::TypeVisitableExt as _;
|
||||||
use crate::{
|
use crate::{
|
||||||
AliasTy, AliasTyKind, DebugWithInfcx, InferCtxtLike, Interner, UnevaluatedConst, Upcast,
|
AliasTy, AliasTyKind, DebugWithInfcx, InferCtxtLike, Interner, UnevaluatedConst, WithInfcx,
|
||||||
WithInfcx,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A goal is a statement, i.e. `predicate`, we want to prove
|
|
||||||
/// given some assumptions, i.e. `param_env`.
|
|
||||||
///
|
|
||||||
/// Most of the time the `param_env` contains the `where`-bounds of the function
|
|
||||||
/// we're currently typechecking while the `predicate` is some trait bound.
|
|
||||||
#[derive(derivative::Derivative)]
|
|
||||||
#[derivative(
|
|
||||||
Clone(bound = "P: Clone"),
|
|
||||||
Copy(bound = "P: Copy"),
|
|
||||||
Hash(bound = "P: Hash"),
|
|
||||||
PartialEq(bound = "P: PartialEq"),
|
|
||||||
Eq(bound = "P: Eq"),
|
|
||||||
Debug(bound = "P: fmt::Debug")
|
|
||||||
)]
|
|
||||||
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
|
|
||||||
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
|
|
||||||
pub struct Goal<I: Interner, P> {
|
|
||||||
pub param_env: I::ParamEnv,
|
|
||||||
pub predicate: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner, P> Goal<I, P> {
|
|
||||||
pub fn new(tcx: I, param_env: I::ParamEnv, predicate: impl Upcast<I, P>) -> Goal<I, P> {
|
|
||||||
Goal { param_env, predicate: predicate.upcast(tcx) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates the goal to one with a different `predicate` but the same `param_env`.
|
|
||||||
pub fn with<Q>(self, tcx: I, predicate: impl Upcast<I, Q>) -> Goal<I, Q> {
|
|
||||||
Goal { param_env: self.param_env, predicate: predicate.upcast(tcx) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A complete reference to a trait. These take numerous guises in syntax,
|
/// A complete reference to a trait. These take numerous guises in syntax,
|
||||||
/// but perhaps the most recognizable form is in a where-clause:
|
/// but perhaps the most recognizable form is in a where-clause:
|
||||||
/// ```ignore (illustrative)
|
/// ```ignore (illustrative)
|
||||||
|
|
278
compiler/rustc_type_ir/src/solve.rs
Normal file
278
compiler/rustc_type_ir/src/solve.rs
Normal file
|
@ -0,0 +1,278 @@
|
||||||
|
pub mod inspect;
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
|
||||||
|
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
|
||||||
|
|
||||||
|
use crate::{Canonical, CanonicalVarValues, Interner, Upcast};
|
||||||
|
|
||||||
|
pub type CanonicalInput<I, T = <I as Interner>::Predicate> = Canonical<I, QueryInput<I, T>>;
|
||||||
|
pub type CanonicalResponse<I> = Canonical<I, Response<I>>;
|
||||||
|
/// The result of evaluating a canonical query.
|
||||||
|
///
|
||||||
|
/// FIXME: We use a different type than the existing canonical queries. This is because
|
||||||
|
/// we need to add a `Certainty` for `overflow` and may want to restructure this code without
|
||||||
|
/// having to worry about changes to currently used code. Once we've made progress on this
|
||||||
|
/// solver, merge the two responses again.
|
||||||
|
pub type QueryResult<I> = Result<CanonicalResponse<I>, NoSolution>;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
|
#[derive(TypeFoldable_Generic, TypeVisitable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
|
||||||
|
pub struct NoSolution;
|
||||||
|
|
||||||
|
/// A goal is a statement, i.e. `predicate`, we want to prove
|
||||||
|
/// given some assumptions, i.e. `param_env`.
|
||||||
|
///
|
||||||
|
/// Most of the time the `param_env` contains the `where`-bounds of the function
|
||||||
|
/// we're currently typechecking while the `predicate` is some trait bound.
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = "P: Clone"),
|
||||||
|
Copy(bound = "P: Copy"),
|
||||||
|
Hash(bound = "P: Hash"),
|
||||||
|
PartialEq(bound = "P: PartialEq"),
|
||||||
|
Eq(bound = "P: Eq"),
|
||||||
|
Debug(bound = "P: fmt::Debug")
|
||||||
|
)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
|
||||||
|
pub struct Goal<I: Interner, P> {
|
||||||
|
pub param_env: I::ParamEnv,
|
||||||
|
pub predicate: P,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Interner, P> Goal<I, P> {
|
||||||
|
pub fn new(tcx: I, param_env: I::ParamEnv, predicate: impl Upcast<I, P>) -> Goal<I, P> {
|
||||||
|
Goal { param_env, predicate: predicate.upcast(tcx) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the goal to one with a different `predicate` but the same `param_env`.
|
||||||
|
pub fn with<Q>(self, tcx: I, predicate: impl Upcast<I, Q>) -> Goal<I, Q> {
|
||||||
|
Goal { param_env: self.param_env, predicate: predicate.upcast(tcx) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why a specific goal has to be proven.
|
||||||
|
///
|
||||||
|
/// This is necessary as we treat nested goals different depending on
|
||||||
|
/// their source.
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
|
||||||
|
pub enum GoalSource {
|
||||||
|
Misc,
|
||||||
|
/// We're proving a where-bound of an impl.
|
||||||
|
///
|
||||||
|
/// FIXME(-Znext-solver=coinductive): Explain how and why this
|
||||||
|
/// changes whether cycles are coinductive.
|
||||||
|
///
|
||||||
|
/// This also impacts whether we erase constraints on overflow.
|
||||||
|
/// Erasing constraints is generally very useful for perf and also
|
||||||
|
/// results in better error messages by avoiding spurious errors.
|
||||||
|
/// We do not erase overflow constraints in `normalizes-to` goals unless
|
||||||
|
/// they are from an impl where-clause. This is necessary due to
|
||||||
|
/// backwards compatability, cc trait-system-refactor-initiatitive#70.
|
||||||
|
ImplWhereBound,
|
||||||
|
/// Instantiating a higher-ranked goal and re-proving it.
|
||||||
|
InstantiateHigherRanked,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = "Goal<I, P>: Clone"),
|
||||||
|
Copy(bound = "Goal<I, P>: Copy"),
|
||||||
|
Hash(bound = "Goal<I, P>: Hash"),
|
||||||
|
PartialEq(bound = "Goal<I, P>: PartialEq"),
|
||||||
|
Eq(bound = "Goal<I, P>: Eq"),
|
||||||
|
Debug(bound = "Goal<I, P>: fmt::Debug")
|
||||||
|
)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
|
||||||
|
pub struct QueryInput<I: Interner, P> {
|
||||||
|
pub goal: Goal<I, P>,
|
||||||
|
pub predefined_opaques_in_body: I::PredefinedOpaques,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Possible ways the given goal can be proven.
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = ""),
|
||||||
|
Copy(bound = ""),
|
||||||
|
Hash(bound = ""),
|
||||||
|
PartialEq(bound = ""),
|
||||||
|
Eq(bound = ""),
|
||||||
|
Debug(bound = "")
|
||||||
|
)]
|
||||||
|
pub enum CandidateSource<I: Interner> {
|
||||||
|
/// 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(I::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,
|
||||||
|
/// A candidate that is registered only during coherence to represent some
|
||||||
|
/// yet-unknown impl that could be produced downstream without violating orphan
|
||||||
|
/// rules.
|
||||||
|
// FIXME: Merge this with the forced ambiguity candidates, so those don't use `Misc`.
|
||||||
|
CoherenceUnknowable,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext, TyEncodable, TyDecodable))]
|
||||||
|
pub enum BuiltinImplSource {
|
||||||
|
/// Some builtin impl we don't need to differentiate. This should be used
|
||||||
|
/// unless more specific information is necessary.
|
||||||
|
Misc,
|
||||||
|
/// A builtin impl for trait objects.
|
||||||
|
///
|
||||||
|
/// The vtable is formed by concatenating together the method lists of
|
||||||
|
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||||
|
/// be provided when necessary; this is the start of `upcast_trait_ref`'s methods
|
||||||
|
/// in that vtable.
|
||||||
|
Object { vtable_base: usize },
|
||||||
|
/// The vtable is formed by concatenating together the method lists of
|
||||||
|
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||||
|
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
|
||||||
|
/// within that vtable.
|
||||||
|
TraitUpcasting { vtable_vptr_slot: Option<usize> },
|
||||||
|
/// Unsizing a tuple like `(A, B, ..., X)` to `(A, B, ..., Y)` if `X` unsizes to `Y`.
|
||||||
|
///
|
||||||
|
/// This needs to be a separate variant as it is still unstable and we need to emit
|
||||||
|
/// a feature error when using it on stable.
|
||||||
|
TupleUnsizing,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(
|
||||||
|
Clone(bound = ""),
|
||||||
|
Copy(bound = ""),
|
||||||
|
Hash(bound = ""),
|
||||||
|
PartialEq(bound = ""),
|
||||||
|
Eq(bound = ""),
|
||||||
|
Debug(bound = "")
|
||||||
|
)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
|
||||||
|
pub struct Response<I: Interner> {
|
||||||
|
pub certainty: Certainty,
|
||||||
|
pub var_values: CanonicalVarValues<I>,
|
||||||
|
/// Additional constraints returned by this query.
|
||||||
|
pub external_constraints: I::ExternalConstraints,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
|
||||||
|
pub enum Certainty {
|
||||||
|
Yes,
|
||||||
|
Maybe(MaybeCause),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Certainty {
|
||||||
|
pub const AMBIGUOUS: Certainty = Certainty::Maybe(MaybeCause::Ambiguity);
|
||||||
|
|
||||||
|
/// Use this function to merge the certainty of multiple nested subgoals.
|
||||||
|
///
|
||||||
|
/// Given an impl like `impl<T: Foo + Bar> Baz for T {}`, we have 2 nested
|
||||||
|
/// subgoals whenever we use the impl as a candidate: `T: Foo` and `T: Bar`.
|
||||||
|
/// If evaluating `T: Foo` results in ambiguity and `T: Bar` results in
|
||||||
|
/// success, we merge these two responses. This results in ambiguity.
|
||||||
|
///
|
||||||
|
/// If we unify ambiguity with overflow, we return overflow. This doesn't matter
|
||||||
|
/// inside of the solver as we do not distinguish ambiguity from overflow. It does
|
||||||
|
/// however matter for diagnostics. If `T: Foo` resulted in overflow and `T: Bar`
|
||||||
|
/// in ambiguity without changing the inference state, we still want to tell the
|
||||||
|
/// user that `T: Baz` results in overflow.
|
||||||
|
pub fn unify_with(self, other: Certainty) -> Certainty {
|
||||||
|
match (self, other) {
|
||||||
|
(Certainty::Yes, Certainty::Yes) => Certainty::Yes,
|
||||||
|
(Certainty::Yes, Certainty::Maybe(_)) => other,
|
||||||
|
(Certainty::Maybe(_), Certainty::Yes) => self,
|
||||||
|
(Certainty::Maybe(a), Certainty::Maybe(b)) => Certainty::Maybe(a.unify_with(b)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn overflow(suggest_increasing_limit: bool) -> Certainty {
|
||||||
|
Certainty::Maybe(MaybeCause::Overflow { suggest_increasing_limit })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why we failed to evaluate a goal.
|
||||||
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
|
||||||
|
pub enum MaybeCause {
|
||||||
|
/// We failed due to ambiguity. This ambiguity can either
|
||||||
|
/// be a true ambiguity, i.e. there are multiple different answers,
|
||||||
|
/// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
|
||||||
|
Ambiguity,
|
||||||
|
/// We gave up due to an overflow, most often by hitting the recursion limit.
|
||||||
|
Overflow { suggest_increasing_limit: bool },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MaybeCause {
|
||||||
|
fn unify_with(self, other: MaybeCause) -> MaybeCause {
|
||||||
|
match (self, other) {
|
||||||
|
(MaybeCause::Ambiguity, MaybeCause::Ambiguity) => MaybeCause::Ambiguity,
|
||||||
|
(MaybeCause::Ambiguity, MaybeCause::Overflow { .. }) => other,
|
||||||
|
(MaybeCause::Overflow { .. }, MaybeCause::Ambiguity) => self,
|
||||||
|
(
|
||||||
|
MaybeCause::Overflow { suggest_increasing_limit: a },
|
||||||
|
MaybeCause::Overflow { suggest_increasing_limit: b },
|
||||||
|
) => MaybeCause::Overflow { suggest_increasing_limit: a || b },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,113 +18,133 @@
|
||||||
//!
|
//!
|
||||||
//! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
|
//! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
|
||||||
|
|
||||||
use super::{
|
|
||||||
CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, NoSolution,
|
|
||||||
QueryInput, QueryResult,
|
|
||||||
};
|
|
||||||
use crate::{infer::canonical::CanonicalVarValues, ty};
|
|
||||||
use format::ProofTreeFormatter;
|
|
||||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
|
||||||
use std::fmt::{Debug, Write};
|
|
||||||
|
|
||||||
mod format;
|
mod format;
|
||||||
|
|
||||||
|
use std::fmt::{Debug, Write};
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
|
||||||
|
|
||||||
|
use self::format::ProofTreeFormatter;
|
||||||
|
use crate::solve::{
|
||||||
|
CandidateSource, CanonicalInput, Certainty, Goal, GoalSource, NoSolution, QueryInput,
|
||||||
|
QueryResult,
|
||||||
|
};
|
||||||
|
use crate::{Canonical, CanonicalVarValues, Interner};
|
||||||
|
|
||||||
/// Some `data` together with information about how they relate to the input
|
/// Some `data` together with information about how they relate to the input
|
||||||
/// of the canonical query.
|
/// of the canonical query.
|
||||||
///
|
///
|
||||||
/// This is only ever used as [CanonicalState]. Any type information in proof
|
/// This is only ever used as [CanonicalState]. Any type information in proof
|
||||||
/// trees used mechanically has to be canonicalized as we otherwise leak
|
/// trees used mechanically has to be canonicalized as we otherwise leak
|
||||||
/// inference variables from a nested `InferCtxt`.
|
/// inference variables from a nested `InferCtxt`.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, TypeFoldable, TypeVisitable)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct State<'tcx, T> {
|
#[derivative(
|
||||||
pub var_values: CanonicalVarValues<'tcx>,
|
Clone(bound = "T: Clone"),
|
||||||
|
Copy(bound = "T: Copy"),
|
||||||
|
PartialEq(bound = "T: PartialEq"),
|
||||||
|
Eq(bound = "T: Eq"),
|
||||||
|
Hash(bound = "T: Hash"),
|
||||||
|
Debug(bound = "T: Debug")
|
||||||
|
)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
pub struct State<I: Interner, T> {
|
||||||
|
pub var_values: CanonicalVarValues<I>,
|
||||||
pub data: T,
|
pub data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CanonicalState<'tcx, T> = Canonical<'tcx, State<'tcx, T>>;
|
pub type CanonicalState<I, T> = Canonical<I, State<I, T>>;
|
||||||
|
|
||||||
/// When evaluating the root goals we also store the
|
/// When evaluating the root goals we also store the
|
||||||
/// original values for the `CanonicalVarValues` of the
|
/// original values for the `CanonicalVarValues` of the
|
||||||
/// canonicalized goal. We use this to map any [CanonicalState]
|
/// canonicalized goal. We use this to map any [CanonicalState]
|
||||||
/// from the local `InferCtxt` of the solver query to
|
/// from the local `InferCtxt` of the solver query to
|
||||||
/// the `InferCtxt` of the caller.
|
/// the `InferCtxt` of the caller.
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub enum GoalEvaluationKind<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
Root { orig_values: Vec<ty::GenericArg<'tcx>> },
|
pub enum GoalEvaluationKind<I: Interner> {
|
||||||
|
Root { orig_values: Vec<I::GenericArg> },
|
||||||
Nested,
|
Nested,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct GoalEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""))]
|
||||||
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
pub struct GoalEvaluation<I: Interner> {
|
||||||
pub kind: GoalEvaluationKind<'tcx>,
|
pub uncanonicalized_goal: Goal<I, I::Predicate>,
|
||||||
pub evaluation: CanonicalGoalEvaluation<'tcx>,
|
pub kind: GoalEvaluationKind<I>,
|
||||||
|
pub evaluation: CanonicalGoalEvaluation<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct CanonicalGoalEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
pub goal: CanonicalInput<'tcx>,
|
pub struct CanonicalGoalEvaluation<I: Interner> {
|
||||||
pub kind: CanonicalGoalEvaluationKind<'tcx>,
|
pub goal: CanonicalInput<I>,
|
||||||
pub result: QueryResult<'tcx>,
|
pub kind: CanonicalGoalEvaluationKind<I>,
|
||||||
|
pub result: QueryResult<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
pub enum CanonicalGoalEvaluationKind<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
|
pub enum CanonicalGoalEvaluationKind<I: Interner> {
|
||||||
Overflow,
|
Overflow,
|
||||||
CycleInStack,
|
CycleInStack,
|
||||||
ProvisionalCacheHit,
|
ProvisionalCacheHit,
|
||||||
Evaluation { revisions: &'tcx [GoalEvaluationStep<'tcx>] },
|
Evaluation { revisions: I::GoalEvaluationSteps },
|
||||||
}
|
}
|
||||||
impl Debug for GoalEvaluation<'_> {
|
impl<I: Interner> Debug for GoalEvaluation<I> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
ProofTreeFormatter::new(f).format_goal_evaluation(self)
|
ProofTreeFormatter::new(f).format_goal_evaluation(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct AddedGoalsEvaluation<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
pub evaluations: Vec<Vec<GoalEvaluation<'tcx>>>,
|
pub struct AddedGoalsEvaluation<I: Interner> {
|
||||||
|
pub evaluations: Vec<Vec<GoalEvaluation<I>>>,
|
||||||
pub result: Result<Certainty, NoSolution>,
|
pub result: Result<Certainty, NoSolution>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct GoalEvaluationStep<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
|
pub struct GoalEvaluationStep<I: Interner> {
|
||||||
|
pub instantiated_goal: QueryInput<I, I::Predicate>,
|
||||||
|
|
||||||
/// The actual evaluation of the goal, always `ProbeKind::Root`.
|
/// The actual evaluation of the goal, always `ProbeKind::Root`.
|
||||||
pub evaluation: Probe<'tcx>,
|
pub evaluation: Probe<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A self-contained computation during trait solving. This either
|
/// A self-contained computation during trait solving. This either
|
||||||
/// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation
|
/// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation
|
||||||
/// of a goal.
|
/// of a goal.
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub struct Probe<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""))]
|
||||||
|
pub struct Probe<I: Interner> {
|
||||||
/// What happened inside of this probe in chronological order.
|
/// What happened inside of this probe in chronological order.
|
||||||
pub steps: Vec<ProbeStep<'tcx>>,
|
pub steps: Vec<ProbeStep<I>>,
|
||||||
pub kind: ProbeKind<'tcx>,
|
pub kind: ProbeKind<I>,
|
||||||
pub final_state: CanonicalState<'tcx, ()>,
|
pub final_state: CanonicalState<I, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Probe<'_> {
|
impl<I: Interner> Debug for Probe<I> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
ProofTreeFormatter::new(f).format_probe(self)
|
ProofTreeFormatter::new(f).format_probe(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
pub enum ProbeStep<'tcx> {
|
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""), Debug(bound = ""))]
|
||||||
|
pub enum ProbeStep<I: Interner> {
|
||||||
/// We added a goal to the `EvalCtxt` which will get proven
|
/// We added a goal to the `EvalCtxt` which will get proven
|
||||||
/// the next time `EvalCtxt::try_evaluate_added_goals` is called.
|
/// the next time `EvalCtxt::try_evaluate_added_goals` is called.
|
||||||
AddGoal(GoalSource, CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
|
AddGoal(GoalSource, CanonicalState<I, Goal<I, I::Predicate>>),
|
||||||
/// The inside of a `EvalCtxt::try_evaluate_added_goals` call.
|
/// The inside of a `EvalCtxt::try_evaluate_added_goals` call.
|
||||||
EvaluateGoals(AddedGoalsEvaluation<'tcx>),
|
EvaluateGoals(AddedGoalsEvaluation<I>),
|
||||||
/// A call to `probe` while proving the current goal. This is
|
/// A call to `probe` while proving the current goal. This is
|
||||||
/// used whenever there are multiple candidates to prove the
|
/// used whenever there are multiple candidates to prove the
|
||||||
/// current goalby .
|
/// current goalby .
|
||||||
NestedProbe(Probe<'tcx>),
|
NestedProbe(Probe<I>),
|
||||||
/// A trait goal was satisfied by an impl candidate.
|
/// A trait goal was satisfied by an impl candidate.
|
||||||
RecordImplArgs { impl_args: CanonicalState<'tcx, ty::GenericArgsRef<'tcx>> },
|
RecordImplArgs { impl_args: CanonicalState<I, I::GenericArgs> },
|
||||||
/// A call to `EvalCtxt::evaluate_added_goals_make_canonical_response` with
|
/// A call to `EvalCtxt::evaluate_added_goals_make_canonical_response` with
|
||||||
/// `Certainty` was made. This is the certainty passed in, so it's not unified
|
/// `Certainty` was made. This is the certainty passed in, so it's not unified
|
||||||
/// with the certainty of the `try_evaluate_added_goals` that is done within;
|
/// with the certainty of the `try_evaluate_added_goals` that is done within;
|
||||||
|
@ -136,16 +156,25 @@ pub enum ProbeStep<'tcx> {
|
||||||
/// What kind of probe we're in. In case the probe represents a candidate, or
|
/// What kind of probe we're in. In case the probe represents a candidate, or
|
||||||
/// the final result of the current goal - via [ProbeKind::Root] - we also
|
/// the final result of the current goal - via [ProbeKind::Root] - we also
|
||||||
/// store the [QueryResult].
|
/// store the [QueryResult].
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(derivative::Derivative)]
|
||||||
pub enum ProbeKind<'tcx> {
|
#[derivative(
|
||||||
|
Clone(bound = ""),
|
||||||
|
Copy(bound = ""),
|
||||||
|
PartialEq(bound = ""),
|
||||||
|
Eq(bound = ""),
|
||||||
|
Hash(bound = ""),
|
||||||
|
Debug(bound = "")
|
||||||
|
)]
|
||||||
|
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||||
|
pub enum ProbeKind<I: Interner> {
|
||||||
/// The root inference context while proving a goal.
|
/// The root inference context while proving a goal.
|
||||||
Root { result: QueryResult<'tcx> },
|
Root { result: QueryResult<I> },
|
||||||
/// Trying to normalize an alias by at least one step in `NormalizesTo`.
|
/// Trying to normalize an alias by at least one step in `NormalizesTo`.
|
||||||
TryNormalizeNonRigid { result: QueryResult<'tcx> },
|
TryNormalizeNonRigid { result: QueryResult<I> },
|
||||||
/// Probe entered when normalizing the self ty during candidate assembly
|
/// Probe entered when normalizing the self ty during candidate assembly
|
||||||
NormalizedSelfTyAssembly,
|
NormalizedSelfTyAssembly,
|
||||||
/// A candidate for proving a trait or alias-relate goal.
|
/// A candidate for proving a trait or alias-relate goal.
|
||||||
TraitCandidate { source: CandidateSource, result: QueryResult<'tcx> },
|
TraitCandidate { source: CandidateSource<I>, result: QueryResult<I> },
|
||||||
/// 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,
|
||||||
|
@ -156,5 +185,5 @@ pub enum ProbeKind<'tcx> {
|
||||||
/// Looking for param-env candidates that satisfy the trait ref for a projection.
|
/// Looking for param-env candidates that satisfy the trait ref for a projection.
|
||||||
ShadowedEnvProbing,
|
ShadowedEnvProbing,
|
||||||
/// Try to unify an opaque type with an existing key in the storage.
|
/// Try to unify an opaque type with an existing key in the storage.
|
||||||
OpaqueTypeStorageLookup { result: QueryResult<'tcx> },
|
OpaqueTypeStorageLookup { result: QueryResult<I> },
|
||||||
}
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub(super) struct ProofTreeFormatter<'a, 'b> {
|
pub(super) struct ProofTreeFormatter<'a, 'b, I> {
|
||||||
f: &'a mut (dyn Write + 'b),
|
f: &'a mut (dyn Write + 'b),
|
||||||
|
_interner: PhantomData<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum IndentorState {
|
enum IndentorState {
|
||||||
|
@ -36,23 +39,24 @@ impl Write for Indentor<'_, '_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
|
impl<'a, 'b, I: Interner> ProofTreeFormatter<'a, 'b, I> {
|
||||||
pub(super) fn new(f: &'a mut (dyn Write + 'b)) -> Self {
|
pub(super) fn new(f: &'a mut (dyn Write + 'b)) -> Self {
|
||||||
ProofTreeFormatter { f }
|
ProofTreeFormatter { f, _interner: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nested<F>(&mut self, func: F) -> std::fmt::Result
|
fn nested<F>(&mut self, func: F) -> std::fmt::Result
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut ProofTreeFormatter<'_, '_>) -> std::fmt::Result,
|
F: FnOnce(&mut ProofTreeFormatter<'_, '_, I>) -> std::fmt::Result,
|
||||||
{
|
{
|
||||||
write!(self.f, " {{")?;
|
write!(self.f, " {{")?;
|
||||||
func(&mut ProofTreeFormatter {
|
func(&mut ProofTreeFormatter {
|
||||||
f: &mut Indentor { f: self.f, state: IndentorState::StartWithNewline },
|
f: &mut Indentor { f: self.f, state: IndentorState::StartWithNewline },
|
||||||
|
_interner: PhantomData,
|
||||||
})?;
|
})?;
|
||||||
writeln!(self.f, "}}")
|
writeln!(self.f, "}}")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<'_>) -> std::fmt::Result {
|
pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<I>) -> std::fmt::Result {
|
||||||
let goal_text = match eval.kind {
|
let goal_text = match eval.kind {
|
||||||
GoalEvaluationKind::Root { orig_values: _ } => "ROOT GOAL",
|
GoalEvaluationKind::Root { orig_values: _ } => "ROOT GOAL",
|
||||||
GoalEvaluationKind::Nested => "GOAL",
|
GoalEvaluationKind::Nested => "GOAL",
|
||||||
|
@ -63,7 +67,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
|
||||||
|
|
||||||
pub(super) fn format_canonical_goal_evaluation(
|
pub(super) fn format_canonical_goal_evaluation(
|
||||||
&mut self,
|
&mut self,
|
||||||
eval: &CanonicalGoalEvaluation<'_>,
|
eval: &CanonicalGoalEvaluation<I>,
|
||||||
) -> std::fmt::Result {
|
) -> std::fmt::Result {
|
||||||
writeln!(self.f, "GOAL: {:?}", eval.goal)?;
|
writeln!(self.f, "GOAL: {:?}", eval.goal)?;
|
||||||
|
|
||||||
|
@ -89,13 +93,13 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
|
||||||
|
|
||||||
pub(super) fn format_evaluation_step(
|
pub(super) fn format_evaluation_step(
|
||||||
&mut self,
|
&mut self,
|
||||||
evaluation_step: &GoalEvaluationStep<'_>,
|
evaluation_step: &GoalEvaluationStep<I>,
|
||||||
) -> std::fmt::Result {
|
) -> std::fmt::Result {
|
||||||
writeln!(self.f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
|
writeln!(self.f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
|
||||||
self.format_probe(&evaluation_step.evaluation)
|
self.format_probe(&evaluation_step.evaluation)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn format_probe(&mut self, probe: &Probe<'_>) -> std::fmt::Result {
|
pub(super) fn format_probe(&mut self, probe: &Probe<I>) -> std::fmt::Result {
|
||||||
match &probe.kind {
|
match &probe.kind {
|
||||||
ProbeKind::Root { result } => {
|
ProbeKind::Root { result } => {
|
||||||
write!(self.f, "ROOT RESULT: {result:?}")
|
write!(self.f, "ROOT RESULT: {result:?}")
|
||||||
|
@ -150,7 +154,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
|
||||||
|
|
||||||
pub(super) fn format_added_goals_evaluation(
|
pub(super) fn format_added_goals_evaluation(
|
||||||
&mut self,
|
&mut self,
|
||||||
added_goals_evaluation: &AddedGoalsEvaluation<'_>,
|
added_goals_evaluation: &AddedGoalsEvaluation<I>,
|
||||||
) -> std::fmt::Result {
|
) -> std::fmt::Result {
|
||||||
writeln!(self.f, "TRY_EVALUATE_ADDED_GOALS: {:?}", added_goals_evaluation.result)?;
|
writeln!(self.f, "TRY_EVALUATE_ADDED_GOALS: {:?}", added_goals_evaluation.result)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue