Skip to content

Commit 16ba4b7

Browse files
authoredJul 6, 2024
Rollup merge of #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 865518d + 27588d1 commit 16ba4b7

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;

‎compiler/rustc_trait_selection/src/solve/delegate.rs

+2-169
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
use std::ops::Deref;
22

33
use rustc_data_structures::fx::FxHashSet;
4-
use rustc_hir::def_id::{DefId, LocalDefId};
4+
use rustc_hir::def_id::DefId;
55
use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
66
use rustc_infer::infer::canonical::{
77
Canonical, CanonicalExt as _, CanonicalVarInfo, CanonicalVarValues,
88
};
9-
use rustc_infer::infer::{
10-
BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt,
11-
};
9+
use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, TyCtxtInferExt};
1210
use rustc_infer::traits::solve::Goal;
1311
use rustc_infer::traits::util::supertraits;
1412
use rustc_infer::traits::{ObligationCause, Reveal};
1513
use rustc_middle::ty::fold::TypeFoldable;
1614
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _};
1715
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
18-
use rustc_type_ir::relate::Relate;
1916
use rustc_type_ir::solve::{Certainty, NoSolution, SolverMode};
2017

2118
use crate::traits::coherence::trait_ref_is_knowable;
@@ -48,13 +45,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
4845

4946
type Span = Span;
5047

51-
fn solver_mode(&self) -> ty::solve::SolverMode {
52-
match self.intercrate {
53-
true => SolverMode::Coherence,
54-
false => SolverMode::Normal,
55-
}
56-
}
57-
5848
fn build_with_canonical<V>(
5949
interner: TyCtxt<'tcx>,
6050
solver_mode: SolverMode,
@@ -74,104 +64,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
7464
(SolverDelegate(infcx), value, vars)
7565
}
7666

77-
fn universe(&self) -> ty::UniverseIndex {
78-
self.0.universe()
79-
}
80-
81-
fn create_next_universe(&self) -> ty::UniverseIndex {
82-
self.0.create_next_universe()
83-
}
84-
85-
fn universe_of_ty(&self, vid: ty::TyVid) -> Option<ty::UniverseIndex> {
86-
// FIXME(BoxyUwU): this is kind of jank and means that printing unresolved
87-
// ty infers will give you the universe of the var it resolved to not the universe
88-
// it actually had. It also means that if you have a `?0.1` and infer it to `u8` then
89-
// try to print out `?0.1` it will just print `?0`.
90-
match self.0.probe_ty_var(vid) {
91-
Err(universe) => Some(universe),
92-
Ok(_) => None,
93-
}
94-
}
95-
96-
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
97-
match self.0.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) {
98-
Err(universe) => Some(universe),
99-
Ok(_) => None,
100-
}
101-
}
102-
103-
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex> {
104-
// Same issue as with `universe_of_ty`
105-
match self.0.probe_const_var(ct) {
106-
Err(universe) => Some(universe),
107-
Ok(_) => None,
108-
}
109-
}
110-
111-
fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid {
112-
self.0.root_var(var)
113-
}
114-
115-
fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid {
116-
self.0.root_const_var(var)
117-
}
118-
119-
fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty<'tcx> {
120-
match self.0.probe_ty_var(vid) {
121-
Ok(ty) => ty,
122-
Err(_) => Ty::new_var(self.0.tcx, self.0.root_var(vid)),
123-
}
124-
}
125-
126-
fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {
127-
self.0.opportunistic_resolve_int_var(vid)
128-
}
129-
130-
fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> {
131-
self.0.opportunistic_resolve_float_var(vid)
132-
}
133-
134-
fn opportunistic_resolve_ct_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> {
135-
match self.0.probe_const_var(vid) {
136-
Ok(ct) => ct,
137-
Err(_) => ty::Const::new_var(self.0.tcx, self.0.root_const_var(vid)),
138-
}
139-
}
140-
141-
fn opportunistic_resolve_effect_var(&self, vid: ty::EffectVid) -> ty::Const<'tcx> {
142-
match self.0.probe_effect_var(vid) {
143-
Some(ct) => ct,
144-
None => ty::Const::new_infer(
145-
self.0.tcx,
146-
ty::InferConst::EffectVar(self.0.root_effect_var(vid)),
147-
),
148-
}
149-
}
150-
151-
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
152-
self.0
153-
.inner
154-
.borrow_mut()
155-
.unwrap_region_constraints()
156-
.opportunistic_resolve_var(self.0.tcx, vid)
157-
}
158-
159-
fn defining_opaque_types(&self) -> &'tcx ty::List<LocalDefId> {
160-
self.0.defining_opaque_types()
161-
}
162-
163-
fn next_ty_infer(&self) -> Ty<'tcx> {
164-
self.0.next_ty_var(DUMMY_SP)
165-
}
166-
167-
fn next_const_infer(&self) -> ty::Const<'tcx> {
168-
self.0.next_const_var(DUMMY_SP)
169-
}
170-
171-
fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
172-
self.0.fresh_args_for_item(DUMMY_SP, def_id)
173-
}
174-
17567
fn fresh_var_for_kind_with_span(
17668
&self,
17769
arg: ty::GenericArg<'tcx>,
@@ -186,57 +78,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
18678
}
18779
}
18880

189-
fn instantiate_binder_with_infer<T: TypeFoldable<TyCtxt<'tcx>> + Copy>(
190-
&self,
191-
value: ty::Binder<'tcx, T>,
192-
) -> T {
193-
self.0.instantiate_binder_with_fresh_vars(
194-
DUMMY_SP,
195-
BoundRegionConversionTime::HigherRankedType,
196-
value,
197-
)
198-
}
199-
200-
fn enter_forall<T: TypeFoldable<TyCtxt<'tcx>> + Copy, U>(
201-
&self,
202-
value: ty::Binder<'tcx, T>,
203-
f: impl FnOnce(T) -> U,
204-
) -> U {
205-
self.0.enter_forall(value, f)
206-
}
207-
208-
fn relate<T: Relate<TyCtxt<'tcx>>>(
209-
&self,
210-
param_env: ty::ParamEnv<'tcx>,
211-
lhs: T,
212-
variance: ty::Variance,
213-
rhs: T,
214-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
215-
self.0.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs)
216-
}
217-
218-
fn eq_structurally_relating_aliases<T: Relate<TyCtxt<'tcx>>>(
219-
&self,
220-
param_env: ty::ParamEnv<'tcx>,
221-
lhs: T,
222-
rhs: T,
223-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
224-
self.0
225-
.at(&ObligationCause::dummy(), param_env)
226-
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
227-
}
228-
229-
fn resolve_vars_if_possible<T>(&self, value: T) -> T
230-
where
231-
T: TypeFoldable<TyCtxt<'tcx>>,
232-
{
233-
self.0.resolve_vars_if_possible(value)
234-
}
235-
236-
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T {
237-
self.0.probe(|_| probe())
238-
}
239-
24081
fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution> {
24182
self.0.leak_check(max_input_universe, None).map_err(|_| NoSolution)
24283
}
@@ -265,14 +106,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
265106
}
266107
}
267108

268-
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
269-
self.0.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP), sub, sup)
270-
}
271-
272-
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {
273-
self.0.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy());
274-
}
275-
276109
fn well_formed_goals(
277110
&self,
278111
param_env: ty::ParamEnv<'tcx>,
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use crate::fold::TypeFoldable;
2+
use crate::relate::Relate;
3+
use crate::solve::{Goal, NoSolution, SolverMode};
4+
use crate::{self as ty, Interner};
5+
6+
pub trait InferCtxtLike {
7+
type Interner: Interner;
8+
fn cx(&self) -> Self::Interner;
9+
10+
fn solver_mode(&self) -> SolverMode;
11+
12+
fn universe(&self) -> ty::UniverseIndex;
13+
fn create_next_universe(&self) -> ty::UniverseIndex;
14+
15+
fn universe_of_ty(&self, ty: ty::TyVid) -> Option<ty::UniverseIndex>;
16+
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex>;
17+
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex>;
18+
19+
fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid;
20+
fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid;
21+
22+
fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> <Self::Interner as Interner>::Ty;
23+
fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> <Self::Interner as Interner>::Ty;
24+
fn opportunistic_resolve_float_var(
25+
&self,
26+
vid: ty::FloatVid,
27+
) -> <Self::Interner as Interner>::Ty;
28+
fn opportunistic_resolve_ct_var(
29+
&self,
30+
vid: ty::ConstVid,
31+
) -> <Self::Interner as Interner>::Const;
32+
fn opportunistic_resolve_effect_var(
33+
&self,
34+
vid: ty::EffectVid,
35+
) -> <Self::Interner as Interner>::Const;
36+
fn opportunistic_resolve_lt_var(
37+
&self,
38+
vid: ty::RegionVid,
39+
) -> <Self::Interner as Interner>::Region;
40+
41+
fn defining_opaque_types(&self) -> <Self::Interner as Interner>::DefiningOpaqueTypes;
42+
43+
fn next_ty_infer(&self) -> <Self::Interner as Interner>::Ty;
44+
fn next_const_infer(&self) -> <Self::Interner as Interner>::Const;
45+
fn fresh_args_for_item(
46+
&self,
47+
def_id: <Self::Interner as Interner>::DefId,
48+
) -> <Self::Interner as Interner>::GenericArgs;
49+
50+
fn instantiate_binder_with_infer<T: TypeFoldable<Self::Interner> + Copy>(
51+
&self,
52+
value: ty::Binder<Self::Interner, T>,
53+
) -> T;
54+
55+
fn enter_forall<T: TypeFoldable<Self::Interner> + Copy, U>(
56+
&self,
57+
value: ty::Binder<Self::Interner, T>,
58+
f: impl FnOnce(T) -> U,
59+
) -> U;
60+
61+
fn relate<T: Relate<Self::Interner>>(
62+
&self,
63+
param_env: <Self::Interner as Interner>::ParamEnv,
64+
lhs: T,
65+
variance: ty::Variance,
66+
rhs: T,
67+
) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>;
68+
69+
fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>(
70+
&self,
71+
param_env: <Self::Interner as Interner>::ParamEnv,
72+
lhs: T,
73+
rhs: T,
74+
) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>;
75+
76+
fn resolve_vars_if_possible<T>(&self, value: T) -> T
77+
where
78+
T: TypeFoldable<Self::Interner>;
79+
80+
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T;
81+
82+
fn sub_regions(
83+
&self,
84+
sub: <Self::Interner as Interner>::Region,
85+
sup: <Self::Interner as Interner>::Region,
86+
);
87+
88+
fn register_ty_outlives(
89+
&self,
90+
ty: <Self::Interner as Interner>::Ty,
91+
r: <Self::Interner as Interner>::Region,
92+
);
93+
}

‎compiler/rustc_type_ir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mod const_kind;
3939
mod effects;
4040
mod flags;
4141
mod generic_arg;
42+
mod infer_ctxt;
4243
mod interner;
4344
mod opaque_ty;
4445
mod predicate;
@@ -56,6 +57,7 @@ pub use const_kind::*;
5657
pub use effects::*;
5758
pub use flags::*;
5859
pub use generic_arg::*;
60+
pub use infer_ctxt::*;
5961
pub use interner::*;
6062
pub use opaque_ty::*;
6163
pub use predicate::*;

0 commit comments

Comments
 (0)
Please sign in to comment.