Skip to content

Commit 04c9649

Browse files
committed
Move almost all methods on Interner to RustIr
1 parent 9fe96eb commit 04c9649

32 files changed

+930
-708
lines changed

Diff for: compiler/rustc_middle/src/ty/adt.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1818
use rustc_query_system::ich::StableHashingContext;
1919
use rustc_session::DataTypeKind;
2020
use rustc_span::symbol::sym;
21-
use rustc_type_ir::RustIr;
2221
use rustc_type_ir::solve::AdtDestructorKind;
2322
use tracing::{debug, info, trace};
2423

@@ -220,7 +219,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
220219

221220
impl<'tcx> rustc_type_ir::inherent::IrAdtDef<TyCtxt<'tcx>, TyCtxt<'tcx>> for AdtDef<'tcx> {
222221
fn struct_tail_ty(self, cx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
223-
Some(cx.interner().type_of(self.non_enum_variant().tail_opt()?.did))
222+
Some(cx.type_of(self.non_enum_variant().tail_opt()?.did))
224223
}
225224

226225
fn all_field_tys(

Diff for: compiler/rustc_middle/src/ty/context.rs

+55-41
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
120120
self.mk_external_constraints(data)
121121
}
122122
type DepNodeIndex = DepNodeIndex;
123-
fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
124-
self.dep_graph.with_anon_task(self, crate::dep_graph::dep_kinds::TraitSelect, task)
125-
}
123+
126124
type Ty = Ty<'tcx>;
127125
type Tys = &'tcx List<Ty<'tcx>>;
128126

@@ -158,15 +156,53 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
158156
type Clause = Clause<'tcx>;
159157
type Clauses = ty::Clauses<'tcx>;
160158

159+
type Features = &'tcx rustc_feature::Features;
160+
161161
type Tracked<T: fmt::Debug + Clone> = WithDepNode<T>;
162+
163+
type GenericsOf = &'tcx ty::Generics;
164+
165+
type VariancesOf = &'tcx [ty::Variance];
166+
167+
type AdtDef = ty::AdtDef<'tcx>;
168+
169+
type UnsizingParams = &'tcx rustc_index::bit_set::BitSet<u32>;
170+
171+
fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {
172+
self.mk_args(args)
173+
}
174+
175+
fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
176+
where
177+
I: Iterator<Item = T>,
178+
T: CollectAndApply<Self::GenericArg, ty::GenericArgsRef<'tcx>>,
179+
{
180+
self.mk_args_from_iter(args)
181+
}
182+
}
183+
184+
impl<'tcx> RustIr for TyCtxt<'tcx> {
185+
type Interner = Self;
186+
187+
fn interner(self) -> Self::Interner {
188+
self
189+
}
190+
191+
fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
192+
self.dep_graph.with_anon_task(self, crate::dep_graph::dep_kinds::TraitSelect, task)
193+
}
194+
162195
fn mk_tracked<T: fmt::Debug + Clone>(
163196
self,
164197
data: T,
165198
dep_node: DepNodeIndex,
166-
) -> Self::Tracked<T> {
199+
) -> <Self::Interner as Interner>::Tracked<T> {
167200
WithDepNode::new(dep_node, data)
168201
}
169-
fn get_tracked<T: fmt::Debug + Clone>(self, tracked: &Self::Tracked<T>) -> T {
202+
fn get_tracked<T: fmt::Debug + Clone>(
203+
self,
204+
tracked: &<Self::Interner as Interner>::Tracked<T>,
205+
) -> T {
170206
tracked.get(self)
171207
}
172208

@@ -182,24 +218,19 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
182218
self.expand_abstract_consts(t)
183219
}
184220

185-
type GenericsOf = &'tcx ty::Generics;
186-
187221
fn generics_of(self, def_id: DefId) -> &'tcx ty::Generics {
188222
self.generics_of(def_id)
189223
}
190224

191-
type VariancesOf = &'tcx [ty::Variance];
192-
193-
fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
225+
fn variances_of(self, def_id: DefId) -> <Self::Interner as Interner>::VariancesOf {
194226
self.variances_of(def_id)
195227
}
196228

197229
fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
198230
self.type_of(def_id)
199231
}
200232

201-
type AdtDef = ty::AdtDef<'tcx>;
202-
fn adt_def(self, adt_def_id: DefId) -> Self::AdtDef {
233+
fn adt_def(self, adt_def_id: DefId) -> <Self::Interner as Interner>::AdtDef {
203234
self.adt_def(adt_def_id)
204235
}
205236

@@ -254,18 +285,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
254285
)
255286
}
256287

257-
fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {
258-
self.mk_args(args)
259-
}
260-
261-
fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
262-
where
263-
I: Iterator<Item = T>,
264-
T: CollectAndApply<Self::GenericArg, ty::GenericArgsRef<'tcx>>,
265-
{
266-
self.mk_args_from_iter(args)
267-
}
268-
269288
fn check_args_compatible(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) -> bool {
270289
self.check_args_compatible(def_id, args)
271290
}
@@ -279,8 +298,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
279298
/// a dummy self type and forward to `debug_assert_args_compatible`.
280299
fn debug_assert_existential_args_compatible(
281300
self,
282-
def_id: Self::DefId,
283-
args: Self::GenericArgs,
301+
def_id: <Self::Interner as Interner>::DefId,
302+
args: <Self::Interner as Interner>::GenericArgs,
284303
) {
285304
// FIXME: We could perhaps add a `skip: usize` to `debug_assert_args_compatible`
286305
// to avoid needing to reintern the set of args...
@@ -310,9 +329,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
310329
self.recursion_limit().0
311330
}
312331

313-
type Features = &'tcx rustc_feature::Features;
314-
315-
fn features(self) -> Self::Features {
332+
fn features(self) -> <Self::Interner as Interner>::Features {
316333
self.features()
317334
}
318335

@@ -611,15 +628,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
611628
self.coroutine_is_async_gen(coroutine_def_id)
612629
}
613630

614-
type UnsizingParams = &'tcx rustc_index::bit_set::BitSet<u32>;
615-
fn unsizing_params_for_adt(self, adt_def_id: DefId) -> Self::UnsizingParams {
631+
fn unsizing_params_for_adt(
632+
self,
633+
adt_def_id: DefId,
634+
) -> <Self::Interner as Interner>::UnsizingParams {
616635
self.unsizing_params_for_adt(adt_def_id)
617636
}
618637

619638
fn find_const_ty_from_env(
620639
self,
621640
param_env: &ty::ParamEnv<'tcx>,
622-
placeholder: Self::PlaceholderConst,
641+
placeholder: <Self::Interner as Interner>::PlaceholderConst,
623642
) -> Ty<'tcx> {
624643
placeholder.find_const_ty_from_env(param_env)
625644
}
@@ -631,19 +650,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
631650
self.anonymize_bound_vars(binder)
632651
}
633652

634-
fn opaque_types_defined_by(self, defining_anchor: LocalDefId) -> Self::DefiningOpaqueTypes {
653+
fn opaque_types_defined_by(
654+
self,
655+
defining_anchor: LocalDefId,
656+
) -> <Self::Interner as Interner>::DefiningOpaqueTypes {
635657
self.opaque_types_defined_by(defining_anchor)
636658
}
637659
}
638660

639-
impl<'tcx> RustIr for TyCtxt<'tcx> {
640-
type Interner = Self;
641-
642-
fn interner(self) -> Self::Interner {
643-
self
644-
}
645-
}
646-
647661
macro_rules! bidirectional_lang_item_map {
648662
($($name:ident),+ $(,)?) => {
649663
fn trait_lang_item_to_lang_item(lang_item: TraitSolverLangItem) -> LangItem {

Diff for: compiler/rustc_middle/src/ty/generic_args.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
4747
Default::default()
4848
}
4949

50-
fn rebase_onto(
51-
self,
52-
tcx: TyCtxt<'tcx>,
53-
source_ancestor: DefId,
54-
target_args: GenericArgsRef<'tcx>,
55-
) -> GenericArgsRef<'tcx> {
56-
self.rebase_onto(tcx, source_ancestor, target_args)
57-
}
58-
5950
fn type_at(self, i: usize) -> Ty<'tcx> {
6051
self.type_at(i)
6152
}
@@ -68,18 +59,6 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
6859
self.const_at(i)
6960
}
7061

71-
fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
72-
GenericArgs::identity_for_item(tcx, def_id)
73-
}
74-
75-
fn extend_with_error(
76-
tcx: TyCtxt<'tcx>,
77-
def_id: DefId,
78-
original_args: &[ty::GenericArg<'tcx>],
79-
) -> ty::GenericArgsRef<'tcx> {
80-
ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
81-
}
82-
8362
fn split_closure_args(self) -> ty::ClosureArgsParts<TyCtxt<'tcx>> {
8463
match self[..] {
8564
[ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
@@ -139,6 +118,31 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
139118
}
140119
}
141120

121+
impl<'tcx> rustc_type_ir::inherent::IrGenericArgs<TyCtxt<'tcx>, TyCtxt<'tcx>>
122+
for ty::GenericArgsRef<'tcx>
123+
{
124+
fn rebase_onto(
125+
self,
126+
tcx: TyCtxt<'tcx>,
127+
source_ancestor: DefId,
128+
target_args: GenericArgsRef<'tcx>,
129+
) -> GenericArgsRef<'tcx> {
130+
self.rebase_onto(tcx, source_ancestor, target_args)
131+
}
132+
133+
fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
134+
GenericArgs::identity_for_item(tcx, def_id)
135+
}
136+
137+
fn extend_with_error(
138+
tcx: TyCtxt<'tcx>,
139+
def_id: DefId,
140+
original_args: &[ty::GenericArg<'tcx>],
141+
) -> ty::GenericArgsRef<'tcx> {
142+
ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
143+
}
144+
}
145+
142146
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
143147
type Kind = GenericArgKind<'tcx>;
144148

Diff for: compiler/rustc_next_trait_solver/src/coherence.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
return Ok(Err(Conflict::Downstream));
6161
}
6262

63-
if trait_ref_is_local_or_fundamental(infcx.cx().interner(), trait_ref.clone()) {
63+
if trait_ref_is_local_or_fundamental(infcx.cx(), trait_ref.clone()) {
6464
// This is a local or fundamental trait, so future-compatibility
6565
// is no concern. We know that downstream/cousin crates are not
6666
// allowed to implement a generic parameter of this trait ref,
@@ -91,7 +91,10 @@ where
9191
}
9292
}
9393

94-
pub fn trait_ref_is_local_or_fundamental<I: Interner>(tcx: I, trait_ref: ty::TraitRef<I>) -> bool {
94+
pub fn trait_ref_is_local_or_fundamental<Ir: RustIr<Interner = I>, I: Interner>(
95+
tcx: Ir,
96+
trait_ref: ty::TraitRef<I>,
97+
) -> bool {
9598
trait_ref.def_id.is_local() || tcx.trait_is_fundamental(trait_ref.def_id)
9699
}
97100

Diff for: compiler/rustc_next_trait_solver/src/delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
1515
type Span: Copy;
1616

1717
fn build_with_canonical<V>(
18-
cx: Self::Interner,
18+
cx: Self::Ir,
1919
canonical: &ty::CanonicalQueryInput<Self::Interner, V>,
2020
) -> (Self, V, ty::CanonicalVarValues<Self::Interner>)
2121
where

Diff for: compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ where
2727
D: SolverDelegate<Interner = I>,
2828
I: Interner,
2929
<I as Interner>::AdtDef: IrAdtDef<I, D::Ir>,
30+
<I as Interner>::GenericArgs: IrGenericArgs<I, D::Ir>,
3031
{
3132
#[instrument(level = "trace", skip(self), ret)]
3233
pub(super) fn compute_alias_relate_goal(

0 commit comments

Comments
 (0)