From 27588d1de346b50831c62e78f43bf2b81afbf073 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 5 Jul 2024 16:39:24 -0400 Subject: [PATCH] Split SolverDelegate back out from InferCtxtLike --- Cargo.lock | 1 + compiler/rustc_infer/Cargo.toml | 1 + compiler/rustc_infer/src/infer/context.rs | 172 ++++++++++++++++++ compiler/rustc_infer/src/infer/mod.rs | 1 + .../src/canonicalizer.rs | 3 +- .../rustc_next_trait_solver/src/delegate.rs | 96 +--------- .../rustc_next_trait_solver/src/resolve.rs | 2 +- .../src/solve/eval_ctxt/canonical.rs | 2 +- .../src/solve/eval_ctxt/mod.rs | 2 +- .../src/solve/eval_ctxt/probe.rs | 2 +- .../src/solve/delegate.rs | 171 +---------------- compiler/rustc_type_ir/src/infer_ctxt.rs | 93 ++++++++++ compiler/rustc_type_ir/src/lib.rs | 2 + 13 files changed, 286 insertions(+), 262 deletions(-) create mode 100644 compiler/rustc_infer/src/infer/context.rs create mode 100644 compiler/rustc_type_ir/src/infer_ctxt.rs diff --git a/Cargo.lock b/Cargo.lock index fbe1abf2a3317..d1889fb6861ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4170,6 +4170,7 @@ dependencies = [ "rustc_middle", "rustc_span", "rustc_target", + "rustc_type_ir", "smallvec", "tracing", ] diff --git a/compiler/rustc_infer/Cargo.toml b/compiler/rustc_infer/Cargo.toml index c1565a7d40fd5..5136ab79a0f84 100644 --- a/compiler/rustc_infer/Cargo.toml +++ b/compiler/rustc_infer/Cargo.toml @@ -18,6 +18,7 @@ rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } +rustc_type_ir = { path = "../rustc_type_ir" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_infer/src/infer/context.rs b/compiler/rustc_infer/src/infer/context.rs new file mode 100644 index 0000000000000..209996b12e2ed --- /dev/null +++ b/compiler/rustc_infer/src/infer/context.rs @@ -0,0 +1,172 @@ +///! Definition of `InferCtxtLike` from the librarified type layer. +use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_middle::traits::solve::{Goal, NoSolution, SolverMode}; +use rustc_middle::traits::ObligationCause; +use rustc_middle::ty::fold::TypeFoldable; +use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_span::DUMMY_SP; +use rustc_type_ir::relate::Relate; +use rustc_type_ir::InferCtxtLike; + +use super::{BoundRegionConversionTime, InferCtxt, SubregionOrigin}; + +impl<'tcx> InferCtxtLike for InferCtxt<'tcx> { + type Interner = TyCtxt<'tcx>; + + fn cx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn solver_mode(&self) -> ty::solve::SolverMode { + match self.intercrate { + true => SolverMode::Coherence, + false => SolverMode::Normal, + } + } + + fn universe(&self) -> ty::UniverseIndex { + self.universe() + } + + fn create_next_universe(&self) -> ty::UniverseIndex { + self.create_next_universe() + } + + fn universe_of_ty(&self, vid: ty::TyVid) -> Option { + match self.probe_ty_var(vid) { + Err(universe) => Some(universe), + Ok(_) => None, + } + } + + fn universe_of_lt(&self, lt: ty::RegionVid) -> Option { + match self.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) { + Err(universe) => Some(universe), + Ok(_) => None, + } + } + + fn universe_of_ct(&self, ct: ty::ConstVid) -> Option { + match self.probe_const_var(ct) { + Err(universe) => Some(universe), + Ok(_) => None, + } + } + + fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid { + self.root_var(var) + } + + fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid { + self.root_const_var(var) + } + + fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty<'tcx> { + match self.probe_ty_var(vid) { + Ok(ty) => ty, + Err(_) => Ty::new_var(self.tcx, self.root_var(vid)), + } + } + + fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> { + self.opportunistic_resolve_int_var(vid) + } + + fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> { + self.opportunistic_resolve_float_var(vid) + } + + fn opportunistic_resolve_ct_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> { + match self.probe_const_var(vid) { + Ok(ct) => ct, + Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)), + } + } + + fn opportunistic_resolve_effect_var(&self, vid: ty::EffectVid) -> ty::Const<'tcx> { + match self.probe_effect_var(vid) { + Some(ct) => ct, + None => { + ty::Const::new_infer(self.tcx, ty::InferConst::EffectVar(self.root_effect_var(vid))) + } + } + } + + fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> { + self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid) + } + + fn defining_opaque_types(&self) -> &'tcx ty::List { + self.defining_opaque_types() + } + + fn next_ty_infer(&self) -> Ty<'tcx> { + self.next_ty_var(DUMMY_SP) + } + + fn next_const_infer(&self) -> ty::Const<'tcx> { + self.next_const_var(DUMMY_SP) + } + + fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> { + self.fresh_args_for_item(DUMMY_SP, def_id) + } + + fn instantiate_binder_with_infer> + Copy>( + &self, + value: ty::Binder<'tcx, T>, + ) -> T { + self.instantiate_binder_with_fresh_vars( + DUMMY_SP, + BoundRegionConversionTime::HigherRankedType, + value, + ) + } + + fn enter_forall> + Copy, U>( + &self, + value: ty::Binder<'tcx, T>, + f: impl FnOnce(T) -> U, + ) -> U { + self.enter_forall(value, f) + } + + fn relate>>( + &self, + param_env: ty::ParamEnv<'tcx>, + lhs: T, + variance: ty::Variance, + rhs: T, + ) -> Result>>, NoSolution> { + self.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs) + } + + fn eq_structurally_relating_aliases>>( + &self, + param_env: ty::ParamEnv<'tcx>, + lhs: T, + rhs: T, + ) -> Result>>, NoSolution> { + self.at(&ObligationCause::dummy(), param_env) + .eq_structurally_relating_aliases_no_trace(lhs, rhs) + } + + fn resolve_vars_if_possible(&self, value: T) -> T + where + T: TypeFoldable>, + { + self.resolve_vars_if_possible(value) + } + + fn probe(&self, probe: impl FnOnce() -> T) -> T { + self.probe(|_| probe()) + } + + fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) { + self.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP), sub, sup) + } + + fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) { + self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy()); + } +} diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index ff593d7ffb7df..edbb741036f07 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -53,6 +53,7 @@ use type_variable::TypeVariableOrigin; pub mod at; pub mod canonical; +mod context; pub mod error_reporting; pub mod free_regions; mod freshen; diff --git a/compiler/rustc_next_trait_solver/src/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonicalizer.rs index 695d02705abd2..82488088e30e6 100644 --- a/compiler/rustc_next_trait_solver/src/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonicalizer.rs @@ -4,7 +4,8 @@ use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_type_ir::inherent::*; use rustc_type_ir::visit::TypeVisitableExt; use rustc_type_ir::{ - self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, Interner, + self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, InferCtxtLike, + Interner, }; use crate::delegate::SolverDelegate; diff --git a/compiler/rustc_next_trait_solver/src/delegate.rs b/compiler/rustc_next_trait_solver/src/delegate.rs index 6626acfe9639e..31032dc679ac3 100644 --- a/compiler/rustc_next_trait_solver/src/delegate.rs +++ b/compiler/rustc_next_trait_solver/src/delegate.rs @@ -1,18 +1,20 @@ use std::fmt::Debug; +use std::ops::Deref; use rustc_type_ir::fold::TypeFoldable; -use rustc_type_ir::relate::Relate; use rustc_type_ir::solve::{Certainty, Goal, NoSolution, SolverMode}; -use rustc_type_ir::{self as ty, Interner}; +use rustc_type_ir::{self as ty, InferCtxtLike, Interner}; -pub trait SolverDelegate: Sized { +pub trait SolverDelegate: + Deref::Interner>> + Sized +{ type Interner: Interner; - fn cx(&self) -> Self::Interner; + fn cx(&self) -> Self::Interner { + (**self).cx() + } type Span: Copy; - fn solver_mode(&self) -> SolverMode; - fn build_with_canonical( cx: Self::Interner, solver_mode: SolverMode, @@ -21,82 +23,12 @@ pub trait SolverDelegate: Sized { where V: TypeFoldable; - fn universe(&self) -> ty::UniverseIndex; - fn create_next_universe(&self) -> ty::UniverseIndex; - - fn universe_of_ty(&self, ty: ty::TyVid) -> Option; - fn universe_of_lt(&self, lt: ty::RegionVid) -> Option; - fn universe_of_ct(&self, ct: ty::ConstVid) -> Option; - - fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid; - fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid; - - fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> ::Ty; - fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> ::Ty; - fn opportunistic_resolve_float_var( - &self, - vid: ty::FloatVid, - ) -> ::Ty; - fn opportunistic_resolve_ct_var( - &self, - vid: ty::ConstVid, - ) -> ::Const; - fn opportunistic_resolve_effect_var( - &self, - vid: ty::EffectVid, - ) -> ::Const; - fn opportunistic_resolve_lt_var( - &self, - vid: ty::RegionVid, - ) -> ::Region; - - fn defining_opaque_types(&self) -> ::DefiningOpaqueTypes; - - fn next_ty_infer(&self) -> ::Ty; - fn next_const_infer(&self) -> ::Const; - fn fresh_args_for_item( - &self, - def_id: ::DefId, - ) -> ::GenericArgs; - fn fresh_var_for_kind_with_span( &self, arg: ::GenericArg, span: Self::Span, ) -> ::GenericArg; - fn instantiate_binder_with_infer + Copy>( - &self, - value: ty::Binder, - ) -> T; - - fn enter_forall + Copy, U>( - &self, - value: ty::Binder, - f: impl FnOnce(T) -> U, - ) -> U; - - fn relate>( - &self, - param_env: ::ParamEnv, - lhs: T, - variance: ty::Variance, - rhs: T, - ) -> Result::Predicate>>, NoSolution>; - - fn eq_structurally_relating_aliases>( - &self, - param_env: ::ParamEnv, - lhs: T, - rhs: T, - ) -> Result::Predicate>>, NoSolution>; - - fn resolve_vars_if_possible(&self, value: T) -> T - where - T: TypeFoldable; - - fn probe(&self, probe: impl FnOnce() -> T) -> T; - // FIXME: Uplift the leak check into this crate. fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>; @@ -112,18 +44,6 @@ pub trait SolverDelegate: Sized { unevaluated: ty::UnevaluatedConst, ) -> Option<::Const>; - fn sub_regions( - &self, - sub: ::Region, - sup: ::Region, - ); - - fn register_ty_outlives( - &self, - ty: ::Ty, - r: ::Region, - ); - // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`! fn well_formed_goals( &self, diff --git a/compiler/rustc_next_trait_solver/src/resolve.rs b/compiler/rustc_next_trait_solver/src/resolve.rs index 6ed58d0e4fb66..254ee514f8bde 100644 --- a/compiler/rustc_next_trait_solver/src/resolve.rs +++ b/compiler/rustc_next_trait_solver/src/resolve.rs @@ -2,7 +2,7 @@ use crate::delegate::SolverDelegate; use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_type_ir::inherent::*; use rustc_type_ir::visit::TypeVisitableExt; -use rustc_type_ir::{self as ty, Interner}; +use rustc_type_ir::{self as ty, InferCtxtLike, Interner}; /////////////////////////////////////////////////////////////////////////// // EAGER RESOLUTION diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs index 0a313c6a95133..9474d501d6ff0 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs @@ -14,7 +14,7 @@ use std::iter; use rustc_index::IndexVec; use rustc_type_ir::fold::TypeFoldable; use rustc_type_ir::inherent::*; -use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, Interner}; +use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, InferCtxtLike, Interner}; use tracing::{instrument, trace}; use crate::canonicalizer::{CanonicalizeMode, Canonicalizer}; diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 87342eefb33e5..d8a3acc655a45 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -7,7 +7,7 @@ use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_type_ir::inherent::*; use rustc_type_ir::relate::Relate; use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use rustc_type_ir::{self as ty, CanonicalVarValues, Interner}; +use rustc_type_ir::{self as ty, CanonicalVarValues, InferCtxtLike, Interner}; use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic}; use tracing::{instrument, trace}; diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs index e9516c60c70f9..4258dd9263a4e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use rustc_type_ir::Interner; +use rustc_type_ir::{InferCtxtLike, Interner}; use tracing::instrument; use crate::delegate::SolverDelegate; diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index 643d5f804808a..f98744e906f05 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -1,21 +1,18 @@ use std::ops::Deref; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::def_id::DefId; use rustc_infer::infer::canonical::query_response::make_query_region_constraints; use rustc_infer::infer::canonical::{ Canonical, CanonicalExt as _, CanonicalVarInfo, CanonicalVarValues, }; -use rustc_infer::infer::{ - BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt, -}; +use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, TyCtxtInferExt}; use rustc_infer::traits::solve::Goal; use rustc_infer::traits::util::supertraits; use rustc_infer::traits::{ObligationCause, Reveal}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _}; use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; -use rustc_type_ir::relate::Relate; use rustc_type_ir::solve::{Certainty, NoSolution, SolverMode}; use crate::traits::coherence::trait_ref_is_knowable; @@ -48,13 +45,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< type Span = Span; - fn solver_mode(&self) -> ty::solve::SolverMode { - match self.intercrate { - true => SolverMode::Coherence, - false => SolverMode::Normal, - } - } - fn build_with_canonical( interner: TyCtxt<'tcx>, solver_mode: SolverMode, @@ -74,104 +64,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< (SolverDelegate(infcx), value, vars) } - fn universe(&self) -> ty::UniverseIndex { - self.0.universe() - } - - fn create_next_universe(&self) -> ty::UniverseIndex { - self.0.create_next_universe() - } - - fn universe_of_ty(&self, vid: ty::TyVid) -> Option { - // FIXME(BoxyUwU): this is kind of jank and means that printing unresolved - // ty infers will give you the universe of the var it resolved to not the universe - // it actually had. It also means that if you have a `?0.1` and infer it to `u8` then - // try to print out `?0.1` it will just print `?0`. - match self.0.probe_ty_var(vid) { - Err(universe) => Some(universe), - Ok(_) => None, - } - } - - fn universe_of_lt(&self, lt: ty::RegionVid) -> Option { - match self.0.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) { - Err(universe) => Some(universe), - Ok(_) => None, - } - } - - fn universe_of_ct(&self, ct: ty::ConstVid) -> Option { - // Same issue as with `universe_of_ty` - match self.0.probe_const_var(ct) { - Err(universe) => Some(universe), - Ok(_) => None, - } - } - - fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid { - self.0.root_var(var) - } - - fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid { - self.0.root_const_var(var) - } - - fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty<'tcx> { - match self.0.probe_ty_var(vid) { - Ok(ty) => ty, - Err(_) => Ty::new_var(self.0.tcx, self.0.root_var(vid)), - } - } - - fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> { - self.0.opportunistic_resolve_int_var(vid) - } - - fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> { - self.0.opportunistic_resolve_float_var(vid) - } - - fn opportunistic_resolve_ct_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> { - match self.0.probe_const_var(vid) { - Ok(ct) => ct, - Err(_) => ty::Const::new_var(self.0.tcx, self.0.root_const_var(vid)), - } - } - - fn opportunistic_resolve_effect_var(&self, vid: ty::EffectVid) -> ty::Const<'tcx> { - match self.0.probe_effect_var(vid) { - Some(ct) => ct, - None => ty::Const::new_infer( - self.0.tcx, - ty::InferConst::EffectVar(self.0.root_effect_var(vid)), - ), - } - } - - fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> { - self.0 - .inner - .borrow_mut() - .unwrap_region_constraints() - .opportunistic_resolve_var(self.0.tcx, vid) - } - - fn defining_opaque_types(&self) -> &'tcx ty::List { - self.0.defining_opaque_types() - } - - fn next_ty_infer(&self) -> Ty<'tcx> { - self.0.next_ty_var(DUMMY_SP) - } - - fn next_const_infer(&self) -> ty::Const<'tcx> { - self.0.next_const_var(DUMMY_SP) - } - - fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> { - self.0.fresh_args_for_item(DUMMY_SP, def_id) - } - fn fresh_var_for_kind_with_span( &self, arg: ty::GenericArg<'tcx>, @@ -186,57 +78,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< } } - fn instantiate_binder_with_infer> + Copy>( - &self, - value: ty::Binder<'tcx, T>, - ) -> T { - self.0.instantiate_binder_with_fresh_vars( - DUMMY_SP, - BoundRegionConversionTime::HigherRankedType, - value, - ) - } - - fn enter_forall> + Copy, U>( - &self, - value: ty::Binder<'tcx, T>, - f: impl FnOnce(T) -> U, - ) -> U { - self.0.enter_forall(value, f) - } - - fn relate>>( - &self, - param_env: ty::ParamEnv<'tcx>, - lhs: T, - variance: ty::Variance, - rhs: T, - ) -> Result>>, NoSolution> { - self.0.at(&ObligationCause::dummy(), param_env).relate_no_trace(lhs, variance, rhs) - } - - fn eq_structurally_relating_aliases>>( - &self, - param_env: ty::ParamEnv<'tcx>, - lhs: T, - rhs: T, - ) -> Result>>, NoSolution> { - self.0 - .at(&ObligationCause::dummy(), param_env) - .eq_structurally_relating_aliases_no_trace(lhs, rhs) - } - - fn resolve_vars_if_possible(&self, value: T) -> T - where - T: TypeFoldable>, - { - self.0.resolve_vars_if_possible(value) - } - - fn probe(&self, probe: impl FnOnce() -> T) -> T { - self.0.probe(|_| probe()) - } - fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution> { self.0.leak_check(max_input_universe, None).map_err(|_| NoSolution) } @@ -265,14 +106,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< } } - fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) { - self.0.sub_regions(SubregionOrigin::RelateRegionParamBound(DUMMY_SP), sub, sup) - } - - fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) { - self.0.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy()); - } - fn well_formed_goals( &self, param_env: ty::ParamEnv<'tcx>, diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs new file mode 100644 index 0000000000000..2c80ee0a73d4a --- /dev/null +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -0,0 +1,93 @@ +use crate::fold::TypeFoldable; +use crate::relate::Relate; +use crate::solve::{Goal, NoSolution, SolverMode}; +use crate::{self as ty, Interner}; + +pub trait InferCtxtLike { + type Interner: Interner; + fn cx(&self) -> Self::Interner; + + fn solver_mode(&self) -> SolverMode; + + fn universe(&self) -> ty::UniverseIndex; + fn create_next_universe(&self) -> ty::UniverseIndex; + + fn universe_of_ty(&self, ty: ty::TyVid) -> Option; + fn universe_of_lt(&self, lt: ty::RegionVid) -> Option; + fn universe_of_ct(&self, ct: ty::ConstVid) -> Option; + + fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid; + fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid; + + fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> ::Ty; + fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> ::Ty; + fn opportunistic_resolve_float_var( + &self, + vid: ty::FloatVid, + ) -> ::Ty; + fn opportunistic_resolve_ct_var( + &self, + vid: ty::ConstVid, + ) -> ::Const; + fn opportunistic_resolve_effect_var( + &self, + vid: ty::EffectVid, + ) -> ::Const; + fn opportunistic_resolve_lt_var( + &self, + vid: ty::RegionVid, + ) -> ::Region; + + fn defining_opaque_types(&self) -> ::DefiningOpaqueTypes; + + fn next_ty_infer(&self) -> ::Ty; + fn next_const_infer(&self) -> ::Const; + fn fresh_args_for_item( + &self, + def_id: ::DefId, + ) -> ::GenericArgs; + + fn instantiate_binder_with_infer + Copy>( + &self, + value: ty::Binder, + ) -> T; + + fn enter_forall + Copy, U>( + &self, + value: ty::Binder, + f: impl FnOnce(T) -> U, + ) -> U; + + fn relate>( + &self, + param_env: ::ParamEnv, + lhs: T, + variance: ty::Variance, + rhs: T, + ) -> Result::Predicate>>, NoSolution>; + + fn eq_structurally_relating_aliases>( + &self, + param_env: ::ParamEnv, + lhs: T, + rhs: T, + ) -> Result::Predicate>>, NoSolution>; + + fn resolve_vars_if_possible(&self, value: T) -> T + where + T: TypeFoldable; + + fn probe(&self, probe: impl FnOnce() -> T) -> T; + + fn sub_regions( + &self, + sub: ::Region, + sup: ::Region, + ); + + fn register_ty_outlives( + &self, + ty: ::Ty, + r: ::Region, + ); +} diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index fedc8959cf715..c57ac74cdfdc7 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -39,6 +39,7 @@ mod const_kind; mod effects; mod flags; mod generic_arg; +mod infer_ctxt; mod interner; mod opaque_ty; mod predicate; @@ -56,6 +57,7 @@ pub use const_kind::*; pub use effects::*; pub use flags::*; pub use generic_arg::*; +pub use infer_ctxt::*; pub use interner::*; pub use opaque_ty::*; pub use predicate::*;