Skip to content

Commit b7aaeae

Browse files
Uplift TypeRelating relation to SolverRelating, simplify its implementation
1 parent 60d1465 commit b7aaeae

File tree

9 files changed

+592
-22
lines changed

9 files changed

+592
-22
lines changed

compiler/rustc_infer/src/infer/context.rs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
///! Definition of `InferCtxtLike` from the librarified type layer.
22
use rustc_hir::def_id::{DefId, LocalDefId};
3+
use rustc_middle::infer::unify_key::EffectVarValue;
34
use rustc_middle::traits::solve::{Goal, NoSolution, SolverMode};
45
use rustc_middle::traits::ObligationCause;
56
use rustc_middle::ty::fold::TypeFoldable;
67
use rustc_middle::ty::{self, Ty, TyCtxt};
7-
use rustc_span::DUMMY_SP;
8+
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
9+
use rustc_type_ir::relate::combine::PredicateEmittingRelation;
810
use rustc_type_ir::relate::Relate;
911
use rustc_type_ir::InferCtxtLike;
1012

1113
use super::{BoundRegionConversionTime, InferCtxt, SubregionOrigin};
14+
use crate::infer::RelateResult;
1215

1316
impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
1417
type Interner = TyCtxt<'tcx>;
@@ -155,6 +158,10 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
155158
self.shallow_resolve(ty)
156159
}
157160

161+
fn shallow_resolve_const(&self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
162+
self.shallow_resolve_const(ct)
163+
}
164+
158165
fn resolve_vars_if_possible<T>(&self, value: T) -> T
159166
where
160167
T: TypeFoldable<TyCtxt<'tcx>>,
@@ -167,10 +174,96 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
167174
}
168175

169176
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
170-
self.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP), sub, sup)
177+
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(
178+
SubregionOrigin::RelateRegionParamBound(DUMMY_SP),
179+
sub,
180+
sup,
181+
);
182+
}
183+
184+
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>) {
185+
self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
186+
SubregionOrigin::RelateRegionParamBound(DUMMY_SP),
187+
a,
188+
b,
189+
);
171190
}
172191

173192
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {
174193
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy());
175194
}
195+
196+
fn equate_ty_vids_raw(&self, a: rustc_type_ir::TyVid, b: rustc_type_ir::TyVid) {
197+
self.inner.borrow_mut().type_variables().equate(a, b);
198+
}
199+
200+
fn equate_int_vids_raw(&self, a: rustc_type_ir::IntVid, b: rustc_type_ir::IntVid) {
201+
self.inner.borrow_mut().int_unification_table().union(a, b);
202+
}
203+
204+
fn equate_float_vids_raw(&self, a: rustc_type_ir::FloatVid, b: rustc_type_ir::FloatVid) {
205+
self.inner.borrow_mut().float_unification_table().union(a, b);
206+
}
207+
208+
fn equate_const_vids_raw(&self, a: rustc_type_ir::ConstVid, b: rustc_type_ir::ConstVid) {
209+
self.inner.borrow_mut().const_unification_table().union(a, b);
210+
}
211+
212+
fn equate_effect_vids_raw(&self, a: rustc_type_ir::EffectVid, b: rustc_type_ir::EffectVid) {
213+
self.inner.borrow_mut().effect_unification_table().union(a, b);
214+
}
215+
216+
fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
217+
&self,
218+
relation: &mut R,
219+
target_is_expected: bool,
220+
target_vid: rustc_type_ir::TyVid,
221+
instantiation_variance: rustc_type_ir::Variance,
222+
source_ty: Ty<'tcx>,
223+
) -> RelateResult<'tcx, ()> {
224+
self.instantiate_ty_var(
225+
relation,
226+
target_is_expected,
227+
target_vid,
228+
instantiation_variance,
229+
source_ty,
230+
)
231+
}
232+
233+
fn instantiate_int_var_raw(
234+
&self,
235+
vid: rustc_type_ir::IntVid,
236+
value: rustc_type_ir::IntVarValue,
237+
) {
238+
self.inner.borrow_mut().int_unification_table().union_value(vid, value);
239+
}
240+
241+
fn instantiate_float_var_raw(
242+
&self,
243+
vid: rustc_type_ir::FloatVid,
244+
value: rustc_type_ir::FloatVarValue,
245+
) {
246+
self.inner.borrow_mut().float_unification_table().union_value(vid, value);
247+
}
248+
249+
fn instantiate_effect_var_raw(&self, vid: rustc_type_ir::EffectVid, value: ty::Const<'tcx>) {
250+
self.inner
251+
.borrow_mut()
252+
.effect_unification_table()
253+
.union_value(vid, EffectVarValue::Known(value));
254+
}
255+
256+
fn instantiate_const_var_raw<R: PredicateEmittingRelation<Self>>(
257+
&self,
258+
relation: &mut R,
259+
target_is_expected: bool,
260+
target_vid: rustc_type_ir::ConstVid,
261+
source_ct: ty::Const<'tcx>,
262+
) -> RelateResult<'tcx, ()> {
263+
self.instantiate_const_var(relation, target_is_expected, target_vid, source_ct)
264+
}
265+
266+
fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {
267+
self.set_tainted_by_errors(e)
268+
}
176269
}

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'tcx> InferCtxt<'tcx> {
180180
///
181181
/// See `tests/ui/const-generics/occurs-check/` for more examples where this is relevant.
182182
#[instrument(level = "debug", skip(self, relation))]
183-
pub(super) fn instantiate_const_var<R: PredicateEmittingRelation<InferCtxt<'tcx>>>(
183+
pub(crate) fn instantiate_const_var<R: PredicateEmittingRelation<InferCtxt<'tcx>>>(
184184
&self,
185185
relation: &mut R,
186186
target_is_expected: bool,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
703703
}
704704
}
705705

706+
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
707+
fn dummy() -> Self {
708+
DUMMY_SP
709+
}
710+
}
711+
706712
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
707713

708714
pub struct CtxtInterners<'tcx> {

0 commit comments

Comments
 (0)