|
9 | 9 | //! |
10 | 10 | //! ["The `ty` module: representing types"]: https://rustc-dev-guide.rust-lang.org/ty.html |
11 | 11 |
|
| 12 | +#![allow(rustc::usage_of_ty_tykind)] |
| 13 | + |
12 | 14 | pub use self::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; |
13 | 15 | pub use self::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}; |
14 | 16 | pub use self::AssocItemContainer::*; |
@@ -446,89 +448,24 @@ pub struct CReaderCacheKey { |
446 | 448 | pub pos: usize, |
447 | 449 | } |
448 | 450 |
|
449 | | -/// Represents a type. |
450 | | -/// |
451 | | -/// IMPORTANT: |
452 | | -/// - This is a very "dumb" struct (with no derives and no `impls`). |
453 | | -/// - Values of this type are always interned and thus unique, and are stored |
454 | | -/// as an `Interned<TyS>`. |
455 | | -/// - `Ty` (which contains a reference to a `Interned<TyS>`) or `Interned<TyS>` |
456 | | -/// should be used everywhere instead of `TyS`. In particular, `Ty` has most |
457 | | -/// of the relevant methods. |
458 | | -#[derive(PartialEq, Eq, PartialOrd, Ord)] |
459 | | -#[allow(rustc::usage_of_ty_tykind)] |
460 | | -pub(crate) struct TyS<'tcx> { |
461 | | - /// This field shouldn't be used directly and may be removed in the future. |
462 | | - /// Use `Ty::kind()` instead. |
463 | | - kind: TyKind<'tcx>, |
464 | | - |
465 | | - /// This field provides fast access to information that is also contained |
466 | | - /// in `kind`. |
467 | | - /// |
468 | | - /// This field shouldn't be used directly and may be removed in the future. |
469 | | - /// Use `Ty::flags()` instead. |
470 | | - flags: TypeFlags, |
471 | | - |
472 | | - /// This field provides fast access to information that is also contained |
473 | | - /// in `kind`. |
474 | | - /// |
475 | | - /// This is a kind of confusing thing: it stores the smallest |
476 | | - /// binder such that |
477 | | - /// |
478 | | - /// (a) the binder itself captures nothing but |
479 | | - /// (b) all the late-bound things within the type are captured |
480 | | - /// by some sub-binder. |
481 | | - /// |
482 | | - /// So, for a type without any late-bound things, like `u32`, this |
483 | | - /// will be *innermost*, because that is the innermost binder that |
484 | | - /// captures nothing. But for a type `&'D u32`, where `'D` is a |
485 | | - /// late-bound region with De Bruijn index `D`, this would be `D + 1` |
486 | | - /// -- the binder itself does not capture `D`, but `D` is captured |
487 | | - /// by an inner binder. |
488 | | - /// |
489 | | - /// We call this concept an "exclusive" binder `D` because all |
490 | | - /// De Bruijn indices within the type are contained within `0..D` |
491 | | - /// (exclusive). |
492 | | - outer_exclusive_binder: ty::DebruijnIndex, |
493 | | -} |
494 | | - |
495 | 451 | /// Use this rather than `TyS`, whenever possible. |
496 | 452 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] |
497 | 453 | #[rustc_diagnostic_item = "Ty"] |
498 | 454 | #[rustc_pass_by_value] |
499 | | -pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyS<'tcx>>>); |
| 455 | +pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>); |
500 | 456 |
|
501 | 457 | impl<'tcx> TyCtxt<'tcx> { |
502 | 458 | /// A "bool" type used in rustc_mir_transform unit tests when we |
503 | 459 | /// have not spun up a TyCtxt. |
504 | 460 | pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> = |
505 | 461 | Ty(Interned::new_unchecked(&WithCachedTypeInfo { |
506 | | - internee: TyS { |
507 | | - kind: ty::Bool, |
508 | | - flags: TypeFlags::empty(), |
509 | | - outer_exclusive_binder: DebruijnIndex::from_usize(0), |
510 | | - }, |
| 462 | + internee: ty::Bool, |
511 | 463 | stable_hash: Fingerprint::ZERO, |
| 464 | + flags: TypeFlags::empty(), |
| 465 | + outer_exclusive_binder: DebruijnIndex::from_usize(0), |
512 | 466 | })); |
513 | 467 | } |
514 | 468 |
|
515 | | -impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> { |
516 | | - #[inline] |
517 | | - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { |
518 | | - let TyS { |
519 | | - kind, |
520 | | - |
521 | | - // The other fields just provide fast access to information that is |
522 | | - // also contained in `kind`, so no need to hash them. |
523 | | - flags: _, |
524 | | - |
525 | | - outer_exclusive_binder: _, |
526 | | - } = self; |
527 | | - |
528 | | - kind.hash_stable(hcx, hasher) |
529 | | - } |
530 | | -} |
531 | | - |
532 | 469 | impl ty::EarlyBoundRegion { |
533 | 470 | /// Does this early bound region have a name? Early bound regions normally |
534 | 471 | /// always have names except when using anonymous lifetimes (`'_`). |
@@ -1030,7 +967,7 @@ impl<'tcx> Term<'tcx> { |
1030 | 967 | unsafe { |
1031 | 968 | match ptr & TAG_MASK { |
1032 | 969 | TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked( |
1033 | | - &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyS<'tcx>>), |
| 970 | + &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyKind<'tcx>>), |
1034 | 971 | ))), |
1035 | 972 | CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked( |
1036 | 973 | &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), |
@@ -1074,7 +1011,7 @@ impl<'tcx> TermKind<'tcx> { |
1074 | 1011 | TermKind::Ty(ty) => { |
1075 | 1012 | // Ensure we can use the tag bits. |
1076 | 1013 | assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0); |
1077 | | - (TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyS<'tcx>> as usize) |
| 1014 | + (TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyKind<'tcx>> as usize) |
1078 | 1015 | } |
1079 | 1016 | TermKind::Const(ct) => { |
1080 | 1017 | // Ensure we can use the tag bits. |
@@ -2695,7 +2632,6 @@ mod size_asserts { |
2695 | 2632 | use rustc_data_structures::static_assert_size; |
2696 | 2633 | // tidy-alphabetical-start |
2697 | 2634 | static_assert_size!(PredicateS<'_>, 48); |
2698 | | - static_assert_size!(TyS<'_>, 40); |
2699 | | - static_assert_size!(WithCachedTypeInfo<TyS<'_>>, 56); |
| 2635 | + static_assert_size!(WithCachedTypeInfo<TyKind<'_>>, 56); |
2700 | 2636 | // tidy-alphabetical-end |
2701 | 2637 | } |
0 commit comments