Skip to content

Commit 47e9b97

Browse files
authored
Unrolled build for rust-lang#127333
Rollup merge of rust-lang#127333 - compiler-errors:infer_ctxt_like-again, r=lcnr Split `SolverDelegate` back out from `InferCtxtLike` This is because in order to uplift things like the `Generalizer` and other `TypeRelation`s, we want to be able to interface with `InferCtxtLike` (and `InferCtxt` as its implementation), rather that `SolverDelegate`, which only really exists as a hack to be able to define some downstream methods in `rustc_type_ir`. r? lcnr
2 parents 5c08cc7 + 27588d1 commit 47e9b97

File tree

13 files changed

+286
-262
lines changed

13 files changed

+286
-262
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,7 @@ dependencies = [
41704170
"rustc_middle",
41714171
"rustc_span",
41724172
"rustc_target",
4173+
"rustc_type_ir",
41734174
"smallvec",
41744175
"tracing",
41754176
]

compiler/rustc_infer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rustc_macros = { path = "../rustc_macros" }
1818
rustc_middle = { path = "../rustc_middle" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
21+
rustc_type_ir = { path = "../rustc_type_ir" }
2122
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2223
tracing = "0.1"
2324
# tidy-alphabetical-end
+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
///! Definition of `InferCtxtLike` from the librarified type layer.
2+
use rustc_hir::def_id::{DefId, LocalDefId};
3+
use rustc_middle::traits::solve::{Goal, NoSolution, SolverMode};
4+
use rustc_middle::traits::ObligationCause;
5+
use rustc_middle::ty::fold::TypeFoldable;
6+
use rustc_middle::ty::{self, Ty, TyCtxt};
7+
use rustc_span::DUMMY_SP;
8+
use rustc_type_ir::relate::Relate;
9+
use rustc_type_ir::InferCtxtLike;
10+
11+
use super::{BoundRegionConversionTime, InferCtxt, SubregionOrigin};
12+
13+
impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
14+
type Interner = TyCtxt<'tcx>;
15+
16+
fn cx(&self) -> TyCtxt<'tcx> {
17+
self.tcx
18+
}
19+
20+
fn solver_mode(&self) -> ty::solve::SolverMode {
21+
match self.intercrate {
22+
true => SolverMode::Coherence,
23+
false => SolverMode::Normal,
24+
}
25+
}
26+
27+
fn universe(&self) -> ty::UniverseIndex {
28+
self.universe()
29+
}
30+
31+
fn create_next_universe(&self) -> ty::UniverseIndex {
32+
self.create_next_universe()
33+
}
34+
35+
fn universe_of_ty(&self, vid: ty::TyVid) -> Option<ty::UniverseIndex> {
36+
match self.probe_ty_var(vid) {
37+
Err(universe) => Some(universe),
38+
Ok(_) => None,
39+
}
40+
}
41+
42+
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
43+
match self.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) {
44+
Err(universe) => Some(universe),
45+
Ok(_) => None,
46+
}
47+
}
48+
49+
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex> {
50+
match self.probe_const_var(ct) {
51+
Err(universe) => Some(universe),
52+
Ok(_) => None,
53+
}
54+
}
55+
56+
fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid {
57+
self.root_var(var)
58+
}
59+
60+
fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid {
61+
self.root_const_var(var)
62+
}
63+
64+
fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty<'tcx> {
65+
match self.probe_ty_var(vid) {
66+
Ok(ty) => ty,
67+
Err(_) => Ty::new_var(self.tcx, self.root_var(vid)),
68+
}
69+
}
70+
71+
fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {
72+
self.opportunistic_resolve_int_var(vid)
73+
}
74+
75+
fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> {
76+
self.opportunistic_resolve_float_var(vid)
77+
}
78+
79+
fn opportunistic_resolve_ct_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> {
80+
match self.probe_const_var(vid) {
81+
Ok(ct) => ct,
82+
Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)),
83+
}
84+
}
85+
86+
fn opportunistic_resolve_effect_var(&self, vid: ty::EffectVid) -> ty::Const<'tcx> {
87+
match self.probe_effect_var(vid) {
88+
Some(ct) => ct,
89+
None => {
90+
ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(self.root_effect_var(vid)))
91+
}
92+
}
93+
}
94+
95+
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
96+
self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid)
97+
}
98+
99+
fn defining_opaque_types(&self) -> &'tcx ty::List<LocalDefId> {
100+
self.defining_opaque_types()
101+
}
102+
103+
fn next_ty_infer(&self) -> Ty<'tcx> {
104+
self.next_ty_var(DUMMY_SP)
105+
}
106+
107+
fn next_const_infer(&self) -> ty::Const<'tcx> {
108+
self.next_const_var(DUMMY_SP)
109+
}
110+
111+
fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
112+
self.fresh_args_for_item(DUMMY_SP, def_id)
113+
}
114+
115+
fn instantiate_binder_with_infer<T: TypeFoldable<TyCtxt<'tcx>> + Copy>(
116+
&self,
117+
value: ty::Binder<'tcx, T>,
118+
) -> T {
119+
self.instantiate_binder_with_fresh_vars(
120+
DUMMY_SP,
121+
BoundRegionConversionTime::HigherRankedType,
122+
value,
123+
)
124+
}
125+
126+
fn enter_forall<T: TypeFoldable<TyCtxt<'tcx>> + Copy, U>(
127+
&self,
128+
value: ty::Binder<'tcx, T>,
129+
f: impl FnOnce(T) -> U,
130+
) -> U {
131+
self.enter_forall(value, f)
132+
}
133+
134+
fn relate<T: Relate<TyCtxt<'tcx>>>(
135+
&self,
136+
param_env: ty::ParamEnv<'tcx>,
137+
lhs: T,
138+
variance: ty::Variance,
139+
rhs: T,
140+
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
141+
self.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs)
142+
}
143+
144+
fn eq_structurally_relating_aliases<T: Relate<TyCtxt<'tcx>>>(
145+
&self,
146+
param_env: ty::ParamEnv<'tcx>,
147+
lhs: T,
148+
rhs: T,
149+
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
150+
self.at(&ObligationCause::dummy(), param_env)
151+
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
152+
}
153+
154+
fn resolve_vars_if_possible<T>(&self, value: T) -> T
155+
where
156+
T: TypeFoldable<TyCtxt<'tcx>>,
157+
{
158+
self.resolve_vars_if_possible(value)
159+
}
160+
161+
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T {
162+
self.probe(|_| probe())
163+
}
164+
165+
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
166+
self.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP), sub, sup)
167+
}
168+
169+
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {
170+
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy());
171+
}
172+
}

compiler/rustc_infer/src/infer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use type_variable::TypeVariableOrigin;
5353

5454
pub mod at;
5555
pub mod canonical;
56+
mod context;
5657
pub mod error_reporting;
5758
pub mod free_regions;
5859
mod freshen;

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
44
use rustc_type_ir::inherent::*;
55
use rustc_type_ir::visit::TypeVisitableExt;
66
use rustc_type_ir::{
7-
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Interner,
7+
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, InferCtxtLike,
8+
Interner,
89
};
910

1011
use crate::delegate::SolverDelegate;

compiler/rustc_next_trait_solver/src/delegate.rs

+8-88
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
use std::fmt::Debug;
2+
use std::ops::Deref;
23

34
use rustc_type_ir::fold::TypeFoldable;
4-
use rustc_type_ir::relate::Relate;
55
use rustc_type_ir::solve::{Certainty, Goal, NoSolution, SolverMode};
6-
use rustc_type_ir::{self as ty, Interner};
6+
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
77

8-
pub trait SolverDelegate: Sized {
8+
pub trait SolverDelegate:
9+
Deref<Target: InferCtxtLike<Interner = <Self as SolverDelegate>::Interner>> + Sized
10+
{
911
type Interner: Interner;
10-
fn cx(&self) -> Self::Interner;
12+
fn cx(&self) -> Self::Interner {
13+
(**self).cx()
14+
}
1115

1216
type Span: Copy;
1317

14-
fn solver_mode(&self) -> SolverMode;
15-
1618
fn build_with_canonical<V>(
1719
cx: Self::Interner,
1820
solver_mode: SolverMode,
@@ -21,82 +23,12 @@ pub trait SolverDelegate: Sized {
2123
where
2224
V: TypeFoldable<Self::Interner>;
2325

24-
fn universe(&self) -> ty::UniverseIndex;
25-
fn create_next_universe(&self) -> ty::UniverseIndex;
26-
27-
fn universe_of_ty(&self, ty: ty::TyVid) -> Option<ty::UniverseIndex>;
28-
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex>;
29-
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex>;
30-
31-
fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid;
32-
fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid;
33-
34-
fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> <Self::Interner as Interner>::Ty;
35-
fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> <Self::Interner as Interner>::Ty;
36-
fn opportunistic_resolve_float_var(
37-
&self,
38-
vid: ty::FloatVid,
39-
) -> <Self::Interner as Interner>::Ty;
40-
fn opportunistic_resolve_ct_var(
41-
&self,
42-
vid: ty::ConstVid,
43-
) -> <Self::Interner as Interner>::Const;
44-
fn opportunistic_resolve_effect_var(
45-
&self,
46-
vid: ty::EffectVid,
47-
) -> <Self::Interner as Interner>::Const;
48-
fn opportunistic_resolve_lt_var(
49-
&self,
50-
vid: ty::RegionVid,
51-
) -> <Self::Interner as Interner>::Region;
52-
53-
fn defining_opaque_types(&self) -> <Self::Interner as Interner>::DefiningOpaqueTypes;
54-
55-
fn next_ty_infer(&self) -> <Self::Interner as Interner>::Ty;
56-
fn next_const_infer(&self) -> <Self::Interner as Interner>::Const;
57-
fn fresh_args_for_item(
58-
&self,
59-
def_id: <Self::Interner as Interner>::DefId,
60-
) -> <Self::Interner as Interner>::GenericArgs;
61-
6226
fn fresh_var_for_kind_with_span(
6327
&self,
6428
arg: <Self::Interner as Interner>::GenericArg,
6529
span: Self::Span,
6630
) -> <Self::Interner as Interner>::GenericArg;
6731

68-
fn instantiate_binder_with_infer<T: TypeFoldable<Self::Interner> + Copy>(
69-
&self,
70-
value: ty::Binder<Self::Interner, T>,
71-
) -> T;
72-
73-
fn enter_forall<T: TypeFoldable<Self::Interner> + Copy, U>(
74-
&self,
75-
value: ty::Binder<Self::Interner, T>,
76-
f: impl FnOnce(T) -> U,
77-
) -> U;
78-
79-
fn relate<T: Relate<Self::Interner>>(
80-
&self,
81-
param_env: <Self::Interner as Interner>::ParamEnv,
82-
lhs: T,
83-
variance: ty::Variance,
84-
rhs: T,
85-
) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>;
86-
87-
fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>(
88-
&self,
89-
param_env: <Self::Interner as Interner>::ParamEnv,
90-
lhs: T,
91-
rhs: T,
92-
) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>;
93-
94-
fn resolve_vars_if_possible<T>(&self, value: T) -> T
95-
where
96-
T: TypeFoldable<Self::Interner>;
97-
98-
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T;
99-
10032
// FIXME: Uplift the leak check into this crate.
10133
fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>;
10234

@@ -112,18 +44,6 @@ pub trait SolverDelegate: Sized {
11244
unevaluated: ty::UnevaluatedConst<Self::Interner>,
11345
) -> Option<<Self::Interner as Interner>::Const>;
11446

115-
fn sub_regions(
116-
&self,
117-
sub: <Self::Interner as Interner>::Region,
118-
sup: <Self::Interner as Interner>::Region,
119-
);
120-
121-
fn register_ty_outlives(
122-
&self,
123-
ty: <Self::Interner as Interner>::Ty,
124-
r: <Self::Interner as Interner>::Region,
125-
);
126-
12747
// FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`!
12848
fn well_formed_goals(
12949
&self,

compiler/rustc_next_trait_solver/src/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::delegate::SolverDelegate;
22
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
33
use rustc_type_ir::inherent::*;
44
use rustc_type_ir::visit::TypeVisitableExt;
5-
use rustc_type_ir::{self as ty, Interner};
5+
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
66

77
///////////////////////////////////////////////////////////////////////////
88
// EAGER RESOLUTION

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +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::{self as ty, Canonical, CanonicalVarValues, Interner};
17+
use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, InferCtxtLike, Interner};
1818
use tracing::{instrument, trace};
1919

2020
use crate::canonicalizer::{CanonicalizeMode, Canonicalizer};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
77
use rustc_type_ir::inherent::*;
88
use rustc_type_ir::relate::Relate;
99
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
10-
use rustc_type_ir::{self as ty, CanonicalVarValues, Interner};
10+
use rustc_type_ir::{self as ty, CanonicalVarValues, InferCtxtLike, Interner};
1111
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
1212
use tracing::{instrument, trace};
1313

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

3-
use rustc_type_ir::Interner;
3+
use rustc_type_ir::{InferCtxtLike, Interner};
44
use tracing::instrument;
55

66
use crate::delegate::SolverDelegate;

0 commit comments

Comments
 (0)