Skip to content

Commit 3da257a

Browse files
Use SolverRelating in new solver
1 parent efb1c23 commit 3da257a

9 files changed

Lines changed: 68 additions & 97 deletions

File tree

‎compiler/rustc_infer/src/infer/at.rs‎

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -208,49 +208,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
208208
}
209209
}
210210

211-
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
212-
pubfnrelate_no_trace<T>(
213-
self,
214-
expected:T,
215-
variance: ty::Variance,
216-
actual:T,
217-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>,NoSolution>
218-
where
219-
T:Relate<TyCtxt<'tcx>>,
220-
{
221-
letmut op = TypeRelating::new(
222-
self.infcx,
223-
TypeTrace::dummy(self.cause),
224-
self.param_env,
225-
DefineOpaqueTypes::Yes,
226-
StructurallyRelateAliases::No,
227-
variance,
228-
);
229-
op.relate(expected, actual)?;
230-
Ok(op.into_obligations().into_iter().map(|o| o.into()).collect())
231-
}
232-
233-
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
234-
pubfneq_structurally_relating_aliases_no_trace<T>(
235-
self,
236-
expected:T,
237-
actual:T,
238-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>,NoSolution>
239-
where
240-
T:Relate<TyCtxt<'tcx>>,
241-
{
242-
letmut op = TypeRelating::new(
243-
self.infcx,
244-
TypeTrace::dummy(self.cause),
245-
self.param_env,
246-
DefineOpaqueTypes::Yes,
247-
StructurallyRelateAliases::Yes,
248-
ty::Invariant,
249-
);
250-
op.relate(expected, actual)?;
251-
Ok(op.into_obligations().into_iter().map(|o| o.into()).collect())
252-
}
253-
254211
/// Computes the least-upper-bound, or mutual supertype, of two
255212
/// values. The order of the arguments doesn't matter, but since
256213
/// this can result in an error (e.g., if asked to compute LUB of

‎compiler/rustc_infer/src/infer/context.rs‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
use rustc_hir::def_id::{DefId,LocalDefId};
33
use rustc_middle::infer::unify_key::EffectVarValue;
44
use rustc_middle::traits::ObligationCause;
5-
use rustc_middle::traits::solve::{Goal,NoSolution,SolverMode};
5+
use rustc_middle::traits::solve::SolverMode;
66
use rustc_middle::ty::fold::TypeFoldable;
7+
use rustc_middle::ty::relate::RelateResult;
78
use rustc_middle::ty::relate::combine::PredicateEmittingRelation;
8-
use rustc_middle::ty::relate::{Relate,RelateResult};
99
use rustc_middle::ty::{self,Ty,TyCtxt};
1010
use rustc_span::{DUMMY_SP,ErrorGuaranteed};
1111

@@ -210,26 +210,6 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
210210
self.set_tainted_by_errors(e)
211211
}
212212

213-
fnrelate<T:Relate<TyCtxt<'tcx>>>(
214-
&self,
215-
param_env: ty::ParamEnv<'tcx>,
216-
lhs:T,
217-
variance: ty::Variance,
218-
rhs:T,
219-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>,NoSolution>{
220-
self.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs)
221-
}
222-
223-
fneq_structurally_relating_aliases<T:Relate<TyCtxt<'tcx>>>(
224-
&self,
225-
param_env: ty::ParamEnv<'tcx>,
226-
lhs:T,
227-
rhs:T,
228-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>,NoSolution>{
229-
self.at(&ObligationCause::dummy(), param_env)
230-
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
231-
}
232-
233213
fnshallow_resolve(&self,ty:Ty<'tcx>) -> Ty<'tcx>{
234214
self.shallow_resolve(ty)
235215
}

‎compiler/rustc_infer/src/infer/mod.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use rustc_middle::infer::unify_key::{
3232
use rustc_middle::mir::ConstraintCategory;
3333
use rustc_middle::mir::interpret::{ErrorHandled,EvalToValTreeResult};
3434
use rustc_middle::traits::select;
35-
use rustc_middle::traits::solve::{Goal,NoSolution};
3635
pubuse rustc_middle::ty::IntVarValue;
3736
use rustc_middle::ty::error::{ExpectedFound,TypeError};
3837
use rustc_middle::ty::fold::{
@@ -340,7 +339,6 @@ pub enum ValuePairs<'tcx> {
340339
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
341340
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
342341
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
343-
Dummy,
344342
}
345343

346344
impl<'tcx>ValuePairs<'tcx>{
@@ -1638,10 +1636,6 @@ impl<'tcx> TypeTrace<'tcx> {
16381636
values:ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
16391637
}
16401638
}
1641-
1642-
fndummy(cause:&ObligationCause<'tcx>) -> TypeTrace<'tcx>{
1643-
TypeTrace{cause: cause.clone(),values:ValuePairs::Dummy}
1644-
}
16451639
}
16461640

16471641
impl<'tcx>SubregionOrigin<'tcx>{

‎compiler/rustc_infer/src/infer/relate/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub use rustc_middle::ty::relate::RelateResult;
66
pubuse rustc_type_ir::relate::combine::PredicateEmittingRelation;
77
pubuse rustc_type_ir::relate::*;
88

9-
#[allow(hidden_glob_reexports)]
109
mod generalize;
1110
mod higher_ranked;
1211
pub(super)mod lattice;

‎compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::iter;
1414
use rustc_index::IndexVec;
1515
use rustc_type_ir::fold::TypeFoldable;
1616
use rustc_type_ir::inherent::*;
17+
use rustc_type_ir::relate::solver_relating::RelateExt;
1718
use rustc_type_ir::{selfas ty,Canonical,CanonicalVarValues,InferCtxtLike,Interner};
1819
use tracing::{instrument, trace};
1920

‎compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_type_ir::data_structures::{HashMap, HashSet, ensure_sufficient_stack};
77
use rustc_type_ir::fold::{TypeFoldable,TypeFolder,TypeSuperFoldable};
88
use rustc_type_ir::inherent::*;
99
use rustc_type_ir::relate::Relate;
10+
use rustc_type_ir::relate::solver_relating::RelateExt;
1011
use rustc_type_ir::visit::{TypeSuperVisitable,TypeVisitable,TypeVisitableExt,TypeVisitor};
1112
use rustc_type_ir::{selfas ty,CanonicalVarValues,InferCtxtLike,Interner};
1213
use rustc_type_ir_macros::{Lift_Generic,TypeFoldable_Generic,TypeVisitable_Generic};

‎compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12851285
ValuePairs::ExistentialProjection(_) => {
12861286
(false,Mismatch::Fixed("existential projection"))
12871287
}
1288-
ValuePairs::Dummy => {
1289-
bug!("do not expect to report a type error from a ValuePairs::Dummy")
1290-
}
12911288
};
12921289
letSome(vals) = self.values_str(values)else{
12931290
// Derived error. Cancel the emitter.
@@ -1853,9 +1850,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18531850
let(exp, fnd) = self.cmp_fn_sig(&exp_found.expected,&exp_found.found);
18541851
Some((exp, fnd,None))
18551852
}
1856-
ValuePairs::Dummy => {
1857-
bug!("do not expect to report a type error from a ValuePairs::Dummy")
1858-
}
18591853
}
18601854
}
18611855

‎compiler/rustc_type_ir/src/infer_ctxt.rs‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
usecrate::fold::TypeFoldable;
2+
usecrate::relate::RelateResult;
23
usecrate::relate::combine::PredicateEmittingRelation;
3-
usecrate::relate::{Relate,RelateResult};
4-
usecrate::solve::{Goal,NoSolution,SolverMode};
4+
usecrate::solve::SolverMode;
55
usecrate::{selfas ty,Interner};
66

77
pubtraitInferCtxtLike:Sized{
@@ -98,21 +98,6 @@ pub trait InferCtxtLike: Sized {
9898

9999
fnset_tainted_by_errors(&self,e: <Self::InternerasInterner>::ErrorGuaranteed);
100100

101-
fnrelate<T:Relate<Self::Interner>>(
102-
&self,
103-
param_env: <Self::InternerasInterner>::ParamEnv,
104-
lhs:T,
105-
variance: ty::Variance,
106-
rhs:T,
107-
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>;
108-
109-
fneq_structurally_relating_aliases<T:Relate<Self::Interner>>(
110-
&self,
111-
param_env: <Self::InternerasInterner>::ParamEnv,
112-
lhs:T,
113-
rhs:T,
114-
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>;
115-
116101
fnshallow_resolve(
117102
&self,
118103
ty: <Self::InternerasInterner>::Ty,

‎compiler/rustc_type_ir/src/relate/solver_relating.rs‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
11
pubuse rustc_type_ir::relate::*;
2-
use rustc_type_ir::solve::Goal;
2+
use rustc_type_ir::solve::{Goal,NoSolution};
33
use rustc_type_ir::{selfas ty,InferCtxtLike,Interner};
44
use tracing::{debug, instrument};
55

66
useself::combine::{InferCtxtCombineExt,PredicateEmittingRelation};
77
usecrate::data_structures::DelayedSet;
88

9-
#[allow(unused)]
9+
pubtraitRelateExt:InferCtxtLike{
10+
fnrelate<T:Relate<Self::Interner>>(
11+
&self,
12+
param_env: <Self::InternerasInterner>::ParamEnv,
13+
lhs:T,
14+
variance: ty::Variance,
15+
rhs:T,
16+
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>;
17+
18+
fneq_structurally_relating_aliases<T:Relate<Self::Interner>>(
19+
&self,
20+
param_env: <Self::InternerasInterner>::ParamEnv,
21+
lhs:T,
22+
rhs:T,
23+
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>;
24+
}
25+
26+
impl<Infcx:InferCtxtLike>RelateExtforInfcx{
27+
fnrelate<T:Relate<Self::Interner>>(
28+
&self,
29+
param_env: <Self::InternerasInterner>::ParamEnv,
30+
lhs:T,
31+
variance: ty::Variance,
32+
rhs:T,
33+
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>
34+
{
35+
letmut relate =
36+
SolverRelating::new(self,StructurallyRelateAliases::No, variance, param_env);
37+
relate.relate(lhs, rhs)?;
38+
Ok(relate.goals)
39+
}
40+
41+
fneq_structurally_relating_aliases<T:Relate<Self::Interner>>(
42+
&self,
43+
param_env: <Self::InternerasInterner>::ParamEnv,
44+
lhs:T,
45+
rhs:T,
46+
) -> Result<Vec<Goal<Self::Interner, <Self::InternerasInterner>::Predicate>>,NoSolution>
47+
{
48+
letmut relate =
49+
SolverRelating::new(self,StructurallyRelateAliases::Yes, ty::Invariant, param_env);
50+
relate.relate(lhs, rhs)?;
51+
Ok(relate.goals)
52+
}
53+
}
54+
1055
/// Enforce that `a` is equal to or a subtype of `b`.
1156
pubstructSolverRelating<'infcx,Infcx,I:Interner>{
1257
infcx:&'infcxInfcx,
@@ -46,6 +91,21 @@ where
4691
Infcx:InferCtxtLike<Interner = I>,
4792
I:Interner,
4893
{
94+
fnnew(
95+
infcx:&'infcxInfcx,
96+
structurally_relate_aliases:StructurallyRelateAliases,
97+
ambient_variance: ty::Variance,
98+
param_env:I::ParamEnv,
99+
) -> Self{
100+
SolverRelating{
101+
infcx,
102+
structurally_relate_aliases,
103+
ambient_variance,
104+
param_env,
105+
goals:vec![],
106+
cache:Default::default(),
107+
}
108+
}
49109
}
50110

51111
impl<Infcx,I>TypeRelation<I>forSolverRelating<'_,Infcx,I>

0 commit comments

Comments
 (0)