Skip to content

Commit f0969a9

Browse files
committed
Start moving over implementation details of Ty to rustc_type_ir,
remove `trait Ty`
1 parent 0623432 commit f0969a9

47 files changed

Lines changed: 933 additions & 936 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_middle/src/query/keys.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::tokenstream::TokenStream;
66
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId};
77
use rustc_hir::hir_id::OwnerId;
88
use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol};
9+
use rustc_type_ir::inherent::IntoKind;
910

1011
use crate::dep_graph::DepNodeIndex;
1112
use crate::infer::canonical::CanonicalQueryInput;
@@ -262,7 +263,7 @@ impl<'tcx> Key for Ty<'tcx> {
262263
}
263264

264265
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
265-
match *self.kind() {
266+
match self.kind() {
266267
ty::Adt(adt, _) => Some(adt.did()),
267268
ty::Coroutine(def_id, ..) => Some(def_id),
268269
_ => None,

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
224224
self.is_manually_drop()
225225
}
226226

227+
fn has_unsafe_fields(self) -> bool {
228+
self.all_fields().any(|field| field.safety.is_unsafe())
229+
}
230+
227231
fn all_field_tys(
228232
self,
229233
tcx: TyCtxt<'tcx>,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'tcx> CtxtInterners<'tcx> {
210210
#[allow(rustc::usage_of_ty_tykind)]
211211
#[inline(never)]
212212
fn intern_ty(&self, kind: TyKind<'tcx>, sess: &Session, untracked: &Untracked) -> Ty<'tcx> {
213-
Ty(Interned::new_unchecked(
213+
Ty::from_interned(Interned::new_unchecked(
214214
self.type_
215215
.intern(kind, |kind| {
216216
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_kind(&kind);

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'tcx> GenericArg<'tcx> {
229229
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked(
230230
ptr.cast::<ty::RegionKind<'tcx>>().as_ref(),
231231
))),
232-
TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
232+
TYPE_TAG => GenericArgKind::Type(Ty::from_interned(Interned::new_unchecked(
233233
ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
234234
))),
235235
CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked(

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub use rustc_type_ir::fast_reject::DeepRejectCtxt;
6060
rustc::non_glob_import_of_type_ir_inherent
6161
)]
6262
use rustc_type_ir::inherent;
63+
use rustc_type_ir::inherent::IntoKind;
6364
pub use rustc_type_ir::relate::VarianceDiagInfo;
6465
pub use rustc_type_ir::solve::{CandidatePreferenceMode, SizedTraitKind};
6566
pub use rustc_type_ir::*;
@@ -104,7 +105,7 @@ pub use self::sty::{
104105
AliasTy, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind,
105106
BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder, FnSig, InlineConstArgs,
106107
InlineConstArgsParts, ParamConst, ParamTy, PlaceholderConst, PlaceholderRegion,
107-
PlaceholderType, PolyFnSig, TyKind, TypeAndMut, TypingMode, UpvarArgs,
108+
PlaceholderType, PolyFnSig, Ty, TyKind, TypeAndMut, TypingMode, UpvarArgs,
108109
};
109110
pub use self::trait_def::TraitDef;
110111
pub use self::typeck_results::{
@@ -457,24 +458,6 @@ pub struct CReaderCacheKey {
457458
//#[rustc_pass_by_value]
458459
//pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
459460

460-
impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
461-
type Kind = TyKind<'tcx>;
462-
463-
fn kind(self) -> TyKind<'tcx> {
464-
*self.kind()
465-
}
466-
}
467-
468-
impl<'tcx> rustc_type_ir::Flags for Ty<'tcx> {
469-
fn flags(&self) -> TypeFlags {
470-
self.0.flags
471-
}
472-
473-
fn outer_exclusive_binder(&self) -> DebruijnIndex {
474-
self.0.outer_exclusive_binder
475-
}
476-
}
477-
478461
/// The crate outlives map is computed during typeck and contains the
479462
/// outlives of every item in the local crate. You should not use it
480463
/// directly, because to do so will make your pass dependent on the
@@ -594,7 +577,7 @@ impl<'tcx> Term<'tcx> {
594577
// and this is just going in the other direction.
595578
unsafe {
596579
match self.ptr.addr().get() & TAG_MASK {
597-
TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked(
580+
TYPE_TAG => TermKind::Ty(Ty::from_interned(Interned::new_unchecked(
598581
ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
599582
))),
600583
CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked(
@@ -630,7 +613,7 @@ impl<'tcx> Term<'tcx> {
630613

631614
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
632615
match self.kind() {
633-
TermKind::Ty(ty) => match *ty.kind() {
616+
TermKind::Ty(ty) => match ty.kind() {
634617
ty::Alias(_kind, alias_ty) => Some(alias_ty.into()),
635618
_ => None,
636619
},
@@ -2368,7 +2351,7 @@ fn typetree_from_ty_impl_inner<'tcx>(
23682351
if ty.is_slice() {
23692352
if let ty::Slice(element_ty) = ty.kind() {
23702353
let element_tree =
2371-
typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
2354+
typetree_from_ty_impl_inner(tcx, element_ty, depth + 1, visited, false);
23722355
return element_tree;
23732356
}
23742357
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::limit::Limit;
1717
use rustc_macros::{Lift, extension};
1818
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
1919
use rustc_span::{Ident, RemapPathScopeComponents, Symbol, kw, sym};
20+
use rustc_type_ir::inherent::{GenericArgs as _, IntoKind as _};
2021
use rustc_type_ir::{Upcast as _, elaborate};
2122
use smallvec::SmallVec;
2223

@@ -1156,7 +1157,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11561157

11571158
write!(p, ")")?;
11581159
if let Some(ty) = return_ty.skip_binder().as_type() {
1159-
if !ty.is_unit() {
1160+
if !matches!(ty.kind(), ty::Tuple(tys) if tys.is_empty()) {
11601161
write!(p, " -> ")?;
11611162
return_ty.print(p)?;
11621163
}
@@ -1175,7 +1176,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11751176
trait_ref: ty::TraitRef::new(
11761177
tcx,
11771178
trait_def_id,
1178-
[self_ty, Ty::new_tup(tcx, args)],
1179+
[self_ty, ty::Ty::new_tup(tcx, args)],
11791180
),
11801181
}),
11811182
FxIndexMap::default(),
@@ -1520,7 +1521,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15201521
write!(self, "...")?;
15211522
}
15221523
write!(self, ")")?;
1523-
if !output.is_unit() {
1524+
if !matches!(output.kind(), ty::Tuple(tys) if tys.is_empty()) {
15241525
write!(self, " -> ")?;
15251526
output.print(self)?;
15261527
}
@@ -2029,7 +2030,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
20292030
}
20302031
write!(p, ")")?;
20312032

2032-
if !sig.output().is_unit() {
2033+
if !matches!(sig.output().kind(), ty::Tuple(tys) if tys.is_empty()) {
20332034
write!(p, " -> ")?;
20342035
sig.output().print(p)?;
20352036
}

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@ use std::iter;
33
pub use rustc_type_ir::relate::*;
44

55
use crate::ty::error::{ExpectedFound, TypeError};
6-
use crate::ty::{self as ty, Ty, TyCtxt};
6+
use crate::ty::{self as ty, TyCtxt};
77

88
pub type RelateResult<'tcx, T> = rustc_type_ir::relate::RelateResult<TyCtxt<'tcx>, T>;
99

10-
impl<'tcx> Relate<TyCtxt<'tcx>> for Ty<'tcx> {
11-
#[inline]
12-
fn relate<R: TypeRelation<TyCtxt<'tcx>>>(
13-
relation: &mut R,
14-
a: Ty<'tcx>,
15-
b: Ty<'tcx>,
16-
) -> RelateResult<'tcx, Ty<'tcx>> {
17-
relation.tys(a, b)
18-
}
19-
}
20-
2110
impl<'tcx> Relate<TyCtxt<'tcx>> for ty::Pattern<'tcx> {
2211
#[inline]
2312
fn relate<R: TypeRelation<TyCtxt<'tcx>>>(

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -327,165 +327,6 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Pattern<'tcx> {
327327
}
328328
}
329329

330-
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
331-
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
332-
self,
333-
folder: &mut F,
334-
) -> Result<Self, F::Error> {
335-
folder.try_fold_ty(self)
336-
}
337-
338-
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
339-
folder.fold_ty(self)
340-
}
341-
}
342-
343-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
344-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
345-
visitor.visit_ty(*self)
346-
}
347-
}
348-
349-
impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
350-
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
351-
self,
352-
folder: &mut F,
353-
) -> Result<Self, F::Error> {
354-
let kind = match *self.kind() {
355-
ty::RawPtr(ty, mutbl) => ty::RawPtr(ty.try_fold_with(folder)?, mutbl),
356-
ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?),
357-
ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?),
358-
ty::Adt(tid, args) => ty::Adt(tid, args.try_fold_with(folder)?),
359-
ty::Dynamic(trait_ty, region) => {
360-
ty::Dynamic(trait_ty.try_fold_with(folder)?, region.try_fold_with(folder)?)
361-
}
362-
ty::Tuple(ts) => ty::Tuple(ts.try_fold_with(folder)?),
363-
ty::FnDef(def_id, args) => ty::FnDef(def_id, args.try_fold_with(folder)?),
364-
ty::FnPtr(sig_tys, hdr) => ty::FnPtr(sig_tys.try_fold_with(folder)?, hdr),
365-
ty::UnsafeBinder(f) => ty::UnsafeBinder(f.try_fold_with(folder)?),
366-
ty::Ref(r, ty, mutbl) => {
367-
ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl)
368-
}
369-
ty::Coroutine(did, args) => ty::Coroutine(did, args.try_fold_with(folder)?),
370-
ty::CoroutineWitness(did, args) => {
371-
ty::CoroutineWitness(did, args.try_fold_with(folder)?)
372-
}
373-
ty::Closure(did, args) => ty::Closure(did, args.try_fold_with(folder)?),
374-
ty::CoroutineClosure(did, args) => {
375-
ty::CoroutineClosure(did, args.try_fold_with(folder)?)
376-
}
377-
ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?),
378-
ty::Pat(ty, pat) => ty::Pat(ty.try_fold_with(folder)?, pat.try_fold_with(folder)?),
379-
380-
ty::Bool
381-
| ty::Char
382-
| ty::Str
383-
| ty::Int(_)
384-
| ty::Uint(_)
385-
| ty::Float(_)
386-
| ty::Error(_)
387-
| ty::Infer(_)
388-
| ty::Param(..)
389-
| ty::Bound(..)
390-
| ty::Placeholder(..)
391-
| ty::Never
392-
| ty::Foreign(..) => return Ok(self),
393-
};
394-
395-
Ok(if *self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) })
396-
}
397-
398-
fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
399-
let kind = match *self.kind() {
400-
ty::RawPtr(ty, mutbl) => ty::RawPtr(ty.fold_with(folder), mutbl),
401-
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
402-
ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
403-
ty::Adt(tid, args) => ty::Adt(tid, args.fold_with(folder)),
404-
ty::Dynamic(trait_ty, region) => {
405-
ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
406-
}
407-
ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
408-
ty::FnDef(def_id, args) => ty::FnDef(def_id, args.fold_with(folder)),
409-
ty::FnPtr(sig_tys, hdr) => ty::FnPtr(sig_tys.fold_with(folder), hdr),
410-
ty::UnsafeBinder(f) => ty::UnsafeBinder(f.fold_with(folder)),
411-
ty::Ref(r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
412-
ty::Coroutine(did, args) => ty::Coroutine(did, args.fold_with(folder)),
413-
ty::CoroutineWitness(did, args) => ty::CoroutineWitness(did, args.fold_with(folder)),
414-
ty::Closure(did, args) => ty::Closure(did, args.fold_with(folder)),
415-
ty::CoroutineClosure(did, args) => ty::CoroutineClosure(did, args.fold_with(folder)),
416-
ty::Alias(kind, data) => ty::Alias(kind, data.fold_with(folder)),
417-
ty::Pat(ty, pat) => ty::Pat(ty.fold_with(folder), pat.fold_with(folder)),
418-
419-
ty::Bool
420-
| ty::Char
421-
| ty::Str
422-
| ty::Int(_)
423-
| ty::Uint(_)
424-
| ty::Float(_)
425-
| ty::Error(_)
426-
| ty::Infer(_)
427-
| ty::Param(..)
428-
| ty::Bound(..)
429-
| ty::Placeholder(..)
430-
| ty::Never
431-
| ty::Foreign(..) => return self,
432-
};
433-
434-
if *self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) }
435-
}
436-
}
437-
438-
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
439-
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
440-
match self.kind() {
441-
ty::RawPtr(ty, _mutbl) => ty.visit_with(visitor),
442-
ty::Array(typ, sz) => {
443-
try_visit!(typ.visit_with(visitor));
444-
sz.visit_with(visitor)
445-
}
446-
ty::Slice(typ) => typ.visit_with(visitor),
447-
ty::Adt(_, args) => args.visit_with(visitor),
448-
ty::Dynamic(trait_ty, reg) => {
449-
try_visit!(trait_ty.visit_with(visitor));
450-
reg.visit_with(visitor)
451-
}
452-
ty::Tuple(ts) => ts.visit_with(visitor),
453-
ty::FnDef(_, args) => args.visit_with(visitor),
454-
ty::FnPtr(sig_tys, _) => sig_tys.visit_with(visitor),
455-
ty::UnsafeBinder(f) => f.visit_with(visitor),
456-
ty::Ref(r, ty, _) => {
457-
try_visit!(r.visit_with(visitor));
458-
ty.visit_with(visitor)
459-
}
460-
ty::Coroutine(_did, args) => args.visit_with(visitor),
461-
ty::CoroutineWitness(_did, args) => args.visit_with(visitor),
462-
ty::Closure(_did, args) => args.visit_with(visitor),
463-
ty::CoroutineClosure(_did, args) => args.visit_with(visitor),
464-
ty::Alias(_, data) => data.visit_with(visitor),
465-
466-
ty::Pat(ty, pat) => {
467-
try_visit!(ty.visit_with(visitor));
468-
pat.visit_with(visitor)
469-
}
470-
471-
ty::Error(guar) => guar.visit_with(visitor),
472-
473-
ty::Bool
474-
| ty::Char
475-
| ty::Str
476-
| ty::Int(_)
477-
| ty::Uint(_)
478-
| ty::Float(_)
479-
| ty::Infer(_)
480-
| ty::Bound(..)
481-
| ty::Placeholder(..)
482-
| ty::Param(..)
483-
| ty::Never
484-
| ty::Foreign(..) => V::Result::output(),
485-
}
486-
}
487-
}
488-
489330
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Region<'tcx> {
490331
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
491332
self,

0 commit comments

Comments
 (0)