Skip to content

Commit 0c5d075

Browse files
committed
Create Ty type alias in rustc_type_ir
1 parent 9df8317 commit 0c5d075

33 files changed

Lines changed: 391 additions & 357 deletions

compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use rustc_type_ir::data_structures::{HashMap, ensure_sufficient_stack};
2+
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
3+
use rustc_type_ir::inherent::Ty as _;
24
use rustc_type_ir::inherent::*;
35
use rustc_type_ir::solve::{Goal, QueryInput};
46
use rustc_type_ir::{
57
self as ty, Canonical, CanonicalParamEnvCacheEntry, CanonicalVarKind, Flags, InferCtxtLike,
6-
Interner, PlaceholderConst, PlaceholderType, TypeFlags, TypeFoldable, TypeFolder,
8+
Interner, PlaceholderConst, PlaceholderType, Ty, TypeFlags, TypeFoldable, TypeFolder,
79
TypeSuperFoldable, TypeVisitableExt,
810
};
911

@@ -78,7 +80,7 @@ pub(super) struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner
7880

7981
/// We can simply cache based on the ty itself, because we use
8082
/// `ty::BoundVarIndexKind::Canonical`.
81-
cache: HashMap<I::Ty, I::Ty>,
83+
cache: HashMap<Ty<I>, Ty<I>>,
8284
}
8385

8486
impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
@@ -316,7 +318,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
316318
(max_universe, self.variables, var_kinds)
317319
}
318320

319-
fn inner_fold_ty(&mut self, t: I::Ty) -> I::Ty {
321+
fn inner_fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
320322
let kind = match t.kind() {
321323
ty::Infer(i) => match i {
322324
ty::TyVar(vid) => {
@@ -400,7 +402,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
400402

401403
let var = self.get_or_insert_bound_var(t, kind);
402404

403-
Ty::new_canonical_bound(self.cx(), var)
405+
I::Ty::new_canonical_bound(self.cx(), var)
404406
}
405407
}
406408

@@ -475,7 +477,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
475477
Region::new_canonical_bound(self.cx(), var)
476478
}
477479

478-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
480+
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
479481
if !t.flags().intersects(NEEDS_CANONICAL) {
480482
t
481483
} else if let Some(&ty) = self.cache.get(&t) {

compiler/rustc_next_trait_solver/src/canonical/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::IndexVec;
1616
use rustc_type_ir::inherent::*;
1717
use rustc_type_ir::relate::solver_relating::RelateExt;
1818
use rustc_type_ir::{
19-
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner,
19+
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, Ty,
2020
TypeFoldable,
2121
};
2222
use tracing::instrument;
@@ -53,7 +53,7 @@ impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
5353
pub(super) fn canonicalize_goal<D, I>(
5454
delegate: &D,
5555
goal: Goal<I, I::Predicate>,
56-
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
56+
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
5757
) -> (Vec<I::GenericArg>, CanonicalInput<I, I::Predicate>)
5858
where
5959
D: SolverDelegate<Interner = I>,
@@ -264,7 +264,7 @@ fn register_region_constraints<D, I>(
264264

265265
fn register_new_opaque_types<D, I>(
266266
delegate: &D,
267-
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
267+
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
268268
span: I::Span,
269269
) where
270270
D: SolverDelegate<Interner = I>,

compiler/rustc_next_trait_solver/src/coherence.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use std::fmt::Debug;
22
use std::ops::ControlFlow;
33

44
use derive_where::derive_where;
5+
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
6+
use rustc_type_ir::inherent::Ty as _;
57
use rustc_type_ir::inherent::*;
68
use rustc_type_ir::{
7-
self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, TypeVisitable,
9+
self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, Ty, TypeVisitable,
810
TypeVisitableExt, TypeVisitor,
911
};
1012
use tracing::instrument;
@@ -47,7 +49,7 @@ pub enum Conflict {
4749
pub fn trait_ref_is_knowable<Infcx, I, E>(
4850
infcx: &Infcx,
4951
trait_ref: ty::TraitRef<I>,
50-
mut lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
52+
mut lazily_normalize_ty: impl FnMut(Ty<I>) -> Result<Ty<I>, E>,
5153
) -> Result<Result<(), Conflict>, E>
5254
where
5355
Infcx: InferCtxtLike<Interner = I>,
@@ -115,14 +117,14 @@ impl From<bool> for IsFirstInputType {
115117

116118
#[derive_where(Debug; I: Interner, T: Debug)]
117119
pub enum OrphanCheckErr<I: Interner, T> {
118-
NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>),
120+
NonLocalInputType(Vec<(Ty<I>, IsFirstInputType)>),
119121
UncoveredTyParams(UncoveredTyParams<I, T>),
120122
}
121123

122124
#[derive_where(Debug; I: Interner, T: Debug)]
123125
pub struct UncoveredTyParams<I: Interner, T> {
124126
pub uncovered: T,
125-
pub local_ty: Option<I::Ty>,
127+
pub local_ty: Option<Ty<I>>,
126128
}
127129

128130
/// Checks whether a trait-ref is potentially implementable by a crate.
@@ -222,8 +224,8 @@ pub fn orphan_check_trait_ref<Infcx, I, E: Debug>(
222224
infcx: &Infcx,
223225
trait_ref: ty::TraitRef<I>,
224226
in_crate: InCrate,
225-
lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
226-
) -> Result<Result<(), OrphanCheckErr<I, I::Ty>>, E>
227+
lazily_normalize_ty: impl FnMut(Ty<I>) -> Result<Ty<I>, E>,
228+
) -> Result<Result<(), OrphanCheckErr<I, Ty<I>>>, E>
227229
where
228230
Infcx: InferCtxtLike<Interner = I>,
229231
I: Interner,
@@ -262,14 +264,14 @@ struct OrphanChecker<'a, Infcx, I: Interner, F> {
262264
lazily_normalize_ty: F,
263265
/// Ignore orphan check failures and exclusively search for the first local type.
264266
search_first_local_ty: bool,
265-
non_local_tys: Vec<(I::Ty, IsFirstInputType)>,
267+
non_local_tys: Vec<(Ty<I>, IsFirstInputType)>,
266268
}
267269

268270
impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F>
269271
where
270272
Infcx: InferCtxtLike<Interner = I>,
271273
I: Interner,
272-
F: FnOnce(I::Ty) -> Result<I::Ty, E>,
274+
F: FnOnce(Ty<I>) -> Result<Ty<I>, E>,
273275
{
274276
fn new(infcx: &'a Infcx, in_crate: InCrate, lazily_normalize_ty: F) -> Self {
275277
OrphanChecker {
@@ -282,12 +284,12 @@ where
282284
}
283285
}
284286

285-
fn found_non_local_ty(&mut self, t: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
287+
fn found_non_local_ty(&mut self, t: Ty<I>) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
286288
self.non_local_tys.push((t, self.in_self_ty.into()));
287289
ControlFlow::Continue(())
288290
}
289291

290-
fn found_uncovered_ty_param(&mut self, ty: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
292+
fn found_uncovered_ty_param(&mut self, ty: Ty<I>) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
291293
if self.search_first_local_ty {
292294
return ControlFlow::Continue(());
293295
}
@@ -305,23 +307,23 @@ where
305307

306308
enum OrphanCheckEarlyExit<I: Interner, E> {
307309
NormalizationFailure(E),
308-
UncoveredTyParam(I::Ty),
309-
LocalTy(I::Ty),
310+
UncoveredTyParam(Ty<I>),
311+
LocalTy(Ty<I>),
310312
}
311313

312314
impl<'a, Infcx, I, F, E> TypeVisitor<I> for OrphanChecker<'a, Infcx, I, F>
313315
where
314316
Infcx: InferCtxtLike<Interner = I>,
315317
I: Interner,
316-
F: FnMut(I::Ty) -> Result<I::Ty, E>,
318+
F: FnMut(Ty<I>) -> Result<Ty<I>, E>,
317319
{
318320
type Result = ControlFlow<OrphanCheckEarlyExit<I, E>>;
319321

320322
fn visit_region(&mut self, _r: I::Region) -> Self::Result {
321323
ControlFlow::Continue(())
322324
}
323325

324-
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
326+
fn visit_ty(&mut self, ty: Ty<I>) -> Self::Result {
325327
let ty = self.infcx.shallow_resolve(ty);
326328
let ty = match (self.lazily_normalize_ty)(ty) {
327329
Ok(norm_ty) if norm_ty.is_ty_var() => ty,

compiler/rustc_next_trait_solver/src/delegate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ops::Deref;
22

33
use rustc_type_ir::solve::{Certainty, Goal, NoSolution};
4-
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, TypeFoldable};
4+
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, Ty, TypeFoldable};
55

66
pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
77
type Infcx: InferCtxtLike<Interner = Self::Interner>;
@@ -70,7 +70,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
7070
def_id: <Self::Interner as Interner>::DefId,
7171
args: <Self::Interner as Interner>::GenericArgs,
7272
param_env: <Self::Interner as Interner>::ParamEnv,
73-
hidden_ty: <Self::Interner as Interner>::Ty,
73+
hidden_ty: Ty<Self::Interner>,
7474
goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
7575
);
7676

@@ -86,8 +86,8 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
8686

8787
fn is_transmutable(
8888
&self,
89-
src: <Self::Interner as Interner>::Ty,
90-
dst: <Self::Interner as Interner>::Ty,
89+
src: Ty<Self::Interner>,
90+
dst: Ty<Self::Interner>,
9191
assume: <Self::Interner as Interner>::Const,
9292
) -> Result<Certainty, NoSolution>;
9393
}

compiler/rustc_next_trait_solver/src/placeholder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use core::panic;
22

33
use rustc_type_ir::data_structures::IndexMap;
4+
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
5+
use rustc_type_ir::inherent::Ty as _;
46
use rustc_type_ir::inherent::*;
57
use rustc_type_ir::{
6-
self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType,
8+
self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, Ty,
79
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
810
};
911

@@ -113,7 +115,7 @@ where
113115
}
114116
}
115117

116-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
118+
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
117119
match t.kind() {
118120
ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), _)
119121
if debruijn.as_usize() + 1
@@ -130,7 +132,7 @@ where
130132
let universe = self.universe_for(debruijn);
131133
let p = PlaceholderType::new(universe, bound_ty);
132134
self.mapped_types.insert(p, bound_ty);
133-
Ty::new_placeholder(self.cx(), p)
135+
I::Ty::new_placeholder(self.cx(), p)
134136
}
135137
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
136138
_ => t,

compiler/rustc_next_trait_solver/src/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_type_ir::data_structures::DelayedMap;
22
use rustc_type_ir::inherent::*;
33
use rustc_type_ir::{
4-
self as ty, InferCtxtLike, Interner, TypeFoldable, TypeFolder, TypeSuperFoldable,
4+
self as ty, InferCtxtLike, Interner, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable,
55
TypeVisitableExt,
66
};
77

@@ -19,7 +19,7 @@ where
1919
delegate: &'a D,
2020
/// We're able to use a cache here as the folder does not have any
2121
/// mutable state.
22-
cache: DelayedMap<I::Ty, I::Ty>,
22+
cache: DelayedMap<Ty<I>, Ty<I>>,
2323
}
2424

2525
pub fn eager_resolve_vars<D: SolverDelegate, T: TypeFoldable<D::Interner>>(
@@ -45,7 +45,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolv
4545
self.delegate.cx()
4646
}
4747

48-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
48+
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
4949
match t.kind() {
5050
ty::Infer(ty::TyVar(vid)) => {
5151
let resolved = self.delegate.opportunistic_resolve_ty_var(vid);

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use std::cell::Cell;
66
use std::ops::ControlFlow;
77

88
use derive_where::derive_where;
9+
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
10+
use rustc_type_ir::inherent::Ty as _;
911
use rustc_type_ir::inherent::*;
1012
use rustc_type_ir::lang_items::SolverTraitLangItem;
1113
use rustc_type_ir::search_graph::CandidateHeadUsages;
1214
use rustc_type_ir::solve::Certainty::Maybe;
1315
use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind};
1416
use rustc_type_ir::{
15-
self as ty, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
17+
self as ty, Interner, Ty, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
1618
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
1719
elaborate,
1820
};
@@ -46,11 +48,11 @@ where
4648
D: SolverDelegate<Interner = I>,
4749
I: Interner,
4850
{
49-
fn self_ty(self) -> I::Ty;
51+
fn self_ty(self) -> Ty<I>;
5052

5153
fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
5254

53-
fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
55+
fn with_replaced_self_ty(self, cx: I, self_ty: Ty<I>) -> Self;
5456

5557
fn trait_def_id(self, cx: I) -> I::TraitId;
5658

@@ -683,7 +685,7 @@ where
683685
// hitting another overflow error something. Add a depth parameter needed later.
684686
fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
685687
&mut self,
686-
self_ty: I::Ty,
688+
self_ty: Ty<I>,
687689
goal: Goal<I, G>,
688690
candidates: &mut Vec<Candidate<I>>,
689691
consider_self_bounds: AliasBoundKind,
@@ -1017,13 +1019,13 @@ where
10171019
struct ReplaceOpaque<I: Interner> {
10181020
cx: I,
10191021
alias_ty: ty::AliasTy<I>,
1020-
self_ty: I::Ty,
1022+
self_ty: Ty<I>,
10211023
}
10221024
impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
10231025
fn cx(&self) -> I {
10241026
self.cx
10251027
}
1026-
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1028+
fn fold_ty(&mut self, ty: Ty<I>) -> Ty<I> {
10271029
if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() {
10281030
if alias_ty == self.alias_ty {
10291031
return self.self_ty;
@@ -1280,7 +1282,7 @@ where
12801282
ControlFlow::Continue(())
12811283
}
12821284

1283-
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1285+
fn visit_ty(&mut self, ty: Ty<I>) -> Self::Result {
12841286
let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
12851287
let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
12861288
return ControlFlow::Break(Err(NoSolution));

0 commit comments

Comments
 (0)