Skip to content

Commit baf94bd

Browse files
SolverDelegate
1 parent e7d2d95 commit baf94bd

File tree

24 files changed

+363
-310
lines changed

24 files changed

+363
-310
lines changed

compiler/rustc_infer/src/infer/mod.rs

+6-145
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use BoundRegionConversionTime::*;
1010
pub use RegionVariableOrigin::*;
1111
pub use SubregionOrigin::*;
1212

13-
use crate::infer::relate::{Relate, RelateResult};
13+
use crate::infer::relate::RelateResult;
1414
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
1515
use error_reporting::TypeErrCtxt;
1616
use free_regions::RegionRelations;
@@ -44,7 +44,7 @@ use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
4444
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
4545
use rustc_middle::{bug, span_bug};
4646
use rustc_span::symbol::Symbol;
47-
use rustc_span::{Span, DUMMY_SP};
47+
use rustc_span::Span;
4848
use snapshot::undo_log::InferCtxtUndoLogs;
4949
use std::cell::{Cell, RefCell};
5050
use std::fmt;
@@ -334,149 +334,6 @@ pub struct InferCtxt<'tcx> {
334334
pub obligation_inspector: Cell<Option<ObligationInspector<'tcx>>>,
335335
}
336336

337-
impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
338-
type Interner = TyCtxt<'tcx>;
339-
340-
fn interner(&self) -> TyCtxt<'tcx> {
341-
self.tcx
342-
}
343-
344-
fn universe_of_ty(&self, vid: TyVid) -> Option<ty::UniverseIndex> {
345-
// FIXME(BoxyUwU): this is kind of jank and means that printing unresolved
346-
// ty infers will give you the universe of the var it resolved to not the universe
347-
// it actually had. It also means that if you have a `?0.1` and infer it to `u8` then
348-
// try to print out `?0.1` it will just print `?0`.
349-
match self.probe_ty_var(vid) {
350-
Err(universe) => Some(universe),
351-
Ok(_) => None,
352-
}
353-
}
354-
355-
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
356-
match self.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) {
357-
Err(universe) => Some(universe),
358-
Ok(_) => None,
359-
}
360-
}
361-
362-
fn universe_of_ct(&self, ct: ConstVid) -> Option<ty::UniverseIndex> {
363-
// Same issue as with `universe_of_ty`
364-
match self.probe_const_var(ct) {
365-
Err(universe) => Some(universe),
366-
Ok(_) => None,
367-
}
368-
}
369-
370-
fn root_ty_var(&self, var: TyVid) -> TyVid {
371-
self.root_var(var)
372-
}
373-
374-
fn root_const_var(&self, var: ConstVid) -> ConstVid {
375-
self.root_const_var(var)
376-
}
377-
378-
fn opportunistic_resolve_ty_var(&self, vid: TyVid) -> Ty<'tcx> {
379-
match self.probe_ty_var(vid) {
380-
Ok(ty) => ty,
381-
Err(_) => Ty::new_var(self.tcx, self.root_var(vid)),
382-
}
383-
}
384-
385-
fn opportunistic_resolve_int_var(&self, vid: IntVid) -> Ty<'tcx> {
386-
self.opportunistic_resolve_int_var(vid)
387-
}
388-
389-
fn opportunistic_resolve_float_var(&self, vid: FloatVid) -> Ty<'tcx> {
390-
self.opportunistic_resolve_float_var(vid)
391-
}
392-
393-
fn opportunistic_resolve_ct_var(&self, vid: ConstVid) -> ty::Const<'tcx> {
394-
match self.probe_const_var(vid) {
395-
Ok(ct) => ct,
396-
Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)),
397-
}
398-
}
399-
400-
fn opportunistic_resolve_effect_var(&self, vid: EffectVid) -> ty::Const<'tcx> {
401-
match self.probe_effect_var(vid) {
402-
Some(ct) => ct,
403-
None => {
404-
ty::Const::new_infer(self.tcx, InferConst::EffectVar(self.root_effect_var(vid)))
405-
}
406-
}
407-
}
408-
409-
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
410-
self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid)
411-
}
412-
413-
fn defining_opaque_types(&self) -> &'tcx ty::List<LocalDefId> {
414-
self.defining_opaque_types
415-
}
416-
417-
fn next_ty_infer(&self) -> Ty<'tcx> {
418-
self.next_ty_var(DUMMY_SP)
419-
}
420-
421-
fn next_const_infer(&self) -> ty::Const<'tcx> {
422-
self.next_const_var(DUMMY_SP)
423-
}
424-
425-
fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
426-
self.fresh_args_for_item(DUMMY_SP, def_id)
427-
}
428-
429-
fn instantiate_binder_with_infer<T: TypeFoldable<Self::Interner> + Copy>(
430-
&self,
431-
value: ty::Binder<'tcx, T>,
432-
) -> T {
433-
self.instantiate_binder_with_fresh_vars(
434-
DUMMY_SP,
435-
BoundRegionConversionTime::HigherRankedType,
436-
value,
437-
)
438-
}
439-
440-
fn enter_forall<T: TypeFoldable<TyCtxt<'tcx>> + Copy, U>(
441-
&self,
442-
value: ty::Binder<'tcx, T>,
443-
f: impl FnOnce(T) -> U,
444-
) -> U {
445-
self.enter_forall(value, f)
446-
}
447-
448-
fn relate<T: Relate<TyCtxt<'tcx>>>(
449-
&self,
450-
param_env: ty::ParamEnv<'tcx>,
451-
lhs: T,
452-
variance: ty::Variance,
453-
rhs: T,
454-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
455-
self.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs)
456-
}
457-
458-
fn eq_structurally_relating_aliases<T: Relate<TyCtxt<'tcx>>>(
459-
&self,
460-
param_env: ty::ParamEnv<'tcx>,
461-
lhs: T,
462-
rhs: T,
463-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
464-
self.at(&ObligationCause::dummy(), param_env)
465-
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
466-
}
467-
468-
fn resolve_vars_if_possible<T>(&self, value: T) -> T
469-
where
470-
T: TypeFoldable<TyCtxt<'tcx>>,
471-
{
472-
self.resolve_vars_if_possible(value)
473-
}
474-
475-
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T {
476-
self.probe(|_| probe())
477-
}
478-
}
479-
480337
/// See the `error_reporting` module for more details.
481338
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)]
482339
pub enum ValuePairs<'tcx> {
@@ -830,6 +687,10 @@ impl<'tcx> InferCtxt<'tcx> {
830687
self.tcx.dcx()
831688
}
832689

690+
pub fn defining_opaque_types(&self) -> &'tcx ty::List<LocalDefId> {
691+
self.defining_opaque_types
692+
}
693+
833694
pub fn next_trait_solver(&self) -> bool {
834695
self.next_trait_solver
835696
}

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ 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, InferCtxtLike,
8-
Interner,
7+
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Interner,
98
};
109

10+
use crate::infcx::SolverDelegate;
11+
1112
/// Whether we're canonicalizing a query input or the query response.
1213
///
1314
/// When canonicalizing an input we're in the context of the caller
@@ -37,7 +38,7 @@ pub enum CanonicalizeMode {
3738
},
3839
}
3940

40-
pub struct Canonicalizer<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> {
41+
pub struct Canonicalizer<'a, Infcx: SolverDelegate<Interner = I>, I: Interner> {
4142
infcx: &'a Infcx,
4243
canonicalize_mode: CanonicalizeMode,
4344

@@ -46,7 +47,7 @@ pub struct Canonicalizer<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> {
4647
binder_index: ty::DebruijnIndex,
4748
}
4849

49-
impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> Canonicalizer<'a, Infcx, I> {
50+
impl<'a, Infcx: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, Infcx, I> {
5051
pub fn canonicalize<T: TypeFoldable<I>>(
5152
infcx: &'a Infcx,
5253
canonicalize_mode: CanonicalizeMode,
@@ -210,7 +211,7 @@ impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> Canonicalizer<'a, Infc
210211
}
211212
}
212213

213-
impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
214+
impl<Infcx: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I>
214215
for Canonicalizer<'_, Infcx, I>
215216
{
216217
fn interner(&self) -> I {

compiler/rustc_type_ir/src/infcx.rs renamed to compiler/rustc_next_trait_solver/src/infcx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::fold::TypeFoldable;
2-
use crate::relate::Relate;
3-
use crate::solve::{Goal, NoSolution};
4-
use crate::{self as ty, Interner};
1+
use rustc_type_ir::fold::TypeFoldable;
2+
use rustc_type_ir::relate::Relate;
3+
use rustc_type_ir::solve::{Goal, NoSolution};
4+
use rustc_type_ir::{self as ty, Interner};
55

6-
pub trait InferCtxtLike: Sized {
6+
pub trait SolverDelegate: Sized {
77
type Interner: Interner;
88

99
fn interner(&self) -> Self::Interner;

compiler/rustc_next_trait_solver/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
//! So if you got to this crate from the old solver, it's totally normal.
66
77
pub mod canonicalizer;
8+
pub mod infcx;
89
pub mod resolve;
910
pub mod solve;

compiler/rustc_next_trait_solver/src/resolve.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
use crate::infcx::SolverDelegate;
12
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
23
use rustc_type_ir::inherent::*;
34
use rustc_type_ir::visit::TypeVisitableExt;
4-
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
5+
use rustc_type_ir::{self as ty, Interner};
56

67
///////////////////////////////////////////////////////////////////////////
78
// EAGER RESOLUTION
89

910
/// Resolves ty, region, and const vars to their inferred values or their root vars.
10-
pub struct EagerResolver<'a, Infcx, I = <Infcx as InferCtxtLike>::Interner>
11+
pub struct EagerResolver<'a, Infcx, I = <Infcx as SolverDelegate>::Interner>
1112
where
12-
Infcx: InferCtxtLike<Interner = I>,
13+
Infcx: SolverDelegate<Interner = I>,
1314
I: Interner,
1415
{
1516
infcx: &'a Infcx,
1617
}
1718

18-
impl<'a, Infcx: InferCtxtLike> EagerResolver<'a, Infcx> {
19+
impl<'a, Infcx: SolverDelegate> EagerResolver<'a, Infcx> {
1920
pub fn new(infcx: &'a Infcx) -> Self {
2021
EagerResolver { infcx }
2122
}
2223
}
2324

24-
impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, Infcx> {
25+
impl<Infcx: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, Infcx> {
2526
fn interner(&self) -> I {
2627
self.infcx.interner()
2728
}

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
//! (3.) Otherwise, if we end with two rigid (non-projection) or infer types,
1616
//! relate them structurally.
1717
18+
use super::infcx::SolverDelegate;
1819
use super::EvalCtxt;
19-
use rustc_infer::infer::InferCtxt;
2020
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
2121
use rustc_middle::ty;
2222

23-
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
23+
impl<'tcx> EvalCtxt<'_, SolverDelegate<'tcx>> {
2424
#[instrument(level = "trace", skip(self), ret)]
2525
pub(super) fn compute_alias_relate_goal(
2626
&mut self,

0 commit comments

Comments
 (0)