Skip to content

Commit 745010b

Browse files
Introduce SolverRelating
1 parent d82e8cc commit 745010b

File tree

7 files changed

+358
-2
lines changed

7 files changed

+358
-2
lines changed

compiler/rustc_infer/src/infer/context.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
136136
self.enter_forall(value, f)
137137
}
138138

139+
fn equate_ty_vids_raw(&self, a: rustc_type_ir::TyVid, b: rustc_type_ir::TyVid) {
140+
self.inner.borrow_mut().type_variables().equate(a, b);
141+
}
142+
139143
fn equate_int_vids_raw(&self, a: rustc_type_ir::IntVid, b: rustc_type_ir::IntVid) {
140144
self.inner.borrow_mut().int_unification_table().union(a, b);
141145
}
@@ -152,6 +156,23 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
152156
self.inner.borrow_mut().effect_unification_table().union(a, b);
153157
}
154158

159+
fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
160+
&self,
161+
relation: &mut R,
162+
target_is_expected: bool,
163+
target_vid: rustc_type_ir::TyVid,
164+
instantiation_variance: rustc_type_ir::Variance,
165+
source_ty: Ty<'tcx>,
166+
) -> RelateResult<'tcx, ()> {
167+
self.instantiate_ty_var(
168+
relation,
169+
target_is_expected,
170+
target_vid,
171+
instantiation_variance,
172+
source_ty,
173+
)
174+
}
175+
155176
fn instantiate_int_var_raw(
156177
&self,
157178
vid: rustc_type_ir::IntVid,
@@ -228,7 +249,19 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
228249
}
229250

230251
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
231-
self.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None), sub, sup)
252+
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(
253+
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
254+
sub,
255+
sup,
256+
);
257+
}
258+
259+
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>) {
260+
self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
261+
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
262+
a,
263+
b,
264+
);
232265
}
233266

234267
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {

compiler/rustc_middle/src/ty/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
698698
}
699699
}
700700

701+
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
702+
fn dummy() -> Self {
703+
DUMMY_SP
704+
}
705+
}
706+
701707
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
702708

703709
pub struct CtxtInterners<'tcx> {

compiler/rustc_type_ir/src/infer_ctxt.rs

+15
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,20 @@ pub trait InferCtxtLike: Sized {
6767
f: impl FnOnce(T) -> U,
6868
) -> U;
6969

70+
fn equate_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid);
7071
fn equate_int_vids_raw(&self, a: ty::IntVid, b: ty::IntVid);
7172
fn equate_float_vids_raw(&self, a: ty::FloatVid, b: ty::FloatVid);
7273
fn equate_const_vids_raw(&self, a: ty::ConstVid, b: ty::ConstVid);
7374
fn equate_effect_vids_raw(&self, a: ty::EffectVid, b: ty::EffectVid);
7475

76+
fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
77+
&self,
78+
relation: &mut R,
79+
target_is_expected: bool,
80+
target_vid: ty::TyVid,
81+
instantiation_variance: ty::Variance,
82+
source_ty: <Self::Interner as Interner>::Ty,
83+
) -> RelateResult<Self::Interner, ()>;
7584
fn instantiate_int_var_raw(&self, vid: ty::IntVid, value: ty::IntVarValue);
7685
fn instantiate_float_var_raw(&self, vid: ty::FloatVid, value: ty::FloatVarValue);
7786
fn instantiate_effect_var_raw(
@@ -125,6 +134,12 @@ pub trait InferCtxtLike: Sized {
125134
sup: <Self::Interner as Interner>::Region,
126135
);
127136

137+
fn equate_regions(
138+
&self,
139+
a: <Self::Interner as Interner>::Region,
140+
b: <Self::Interner as Interner>::Region,
141+
);
142+
128143
fn register_ty_outlives(
129144
&self,
130145
ty: <Self::Interner as Interner>::Ty,

compiler/rustc_type_ir/src/inherent.rs

+4
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ pub trait BoundExistentialPredicates<I: Interner>:
563563
) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
564564
}
565565

566+
pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
567+
fn dummy() -> Self;
568+
}
569+
566570
pub trait SliceLike: Sized + Copy {
567571
type Item: Copy;
568572
type IntoIter: Iterator<Item = Self::Item>;

compiler/rustc_type_ir/src/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait Interner:
3636
{
3737
type DefId: DefId<Self>;
3838
type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
39-
type Span: Copy + Debug + Hash + Eq + TypeFoldable<Self>;
39+
type Span: Span<Self>;
4040

4141
type GenericArgs: GenericArgs<Self>;
4242
type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;

compiler/rustc_type_ir/src/relate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::inherent::*;
1010
use crate::{self as ty, Interner};
1111

1212
pub mod combine;
13+
pub mod solver_relating;
1314

1415
pub type RelateResult<I, T> = Result<T, TypeError<I>>;
1516

0 commit comments

Comments
 (0)