Skip to content

Commit aa95b96

Browse files
committedMar 15, 2025
Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr
Use `rustc_type_ir` directly less in the codebase cc #138449 This is a somewhat opinionated bundle of changes that will make working on #138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely: 1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer. 2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`. 3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` :tada:. 4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler. [^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`. I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot. r? lcnr
2 parents adea7cb + b88f85a commit aa95b96

File tree

160 files changed

+748
-695
lines changed

Some content is hidden

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

160 files changed

+748
-695
lines changed
 

‎Cargo.lock

-8
Original file line numberDiff line numberDiff line change
@@ -3440,7 +3440,6 @@ dependencies = [
34403440
"rustc_symbol_mangling",
34413441
"rustc_target",
34423442
"rustc_trait_selection",
3443-
"rustc_type_ir",
34443443
"serde_json",
34453444
"smallvec",
34463445
"tempfile",
@@ -3473,7 +3472,6 @@ dependencies = [
34733472
"rustc_span",
34743473
"rustc_target",
34753474
"rustc_trait_selection",
3476-
"rustc_type_ir",
34773475
"tracing",
34783476
]
34793477

@@ -3736,7 +3734,6 @@ dependencies = [
37363734
"rustc_span",
37373735
"rustc_target",
37383736
"rustc_trait_selection",
3739-
"rustc_type_ir",
37403737
"smallvec",
37413738
"tracing",
37423739
]
@@ -3775,7 +3772,6 @@ dependencies = [
37753772
"rustc_session",
37763773
"rustc_span",
37773774
"rustc_trait_selection",
3778-
"rustc_type_ir",
37793775
"smallvec",
37803776
"tracing",
37813777
]
@@ -3922,7 +3918,6 @@ dependencies = [
39223918
"rustc_span",
39233919
"rustc_target",
39243920
"rustc_trait_selection",
3925-
"rustc_type_ir",
39263921
"smallvec",
39273922
"tracing",
39283923
"unicode-security",
@@ -3998,7 +3993,6 @@ dependencies = [
39983993
"rustc_session",
39993994
"rustc_span",
40003995
"rustc_target",
4001-
"rustc_type_ir",
40023996
"tempfile",
40033997
"tracing",
40043998
]
@@ -4114,7 +4108,6 @@ dependencies = [
41144108
"rustc_span",
41154109
"rustc_target",
41164110
"rustc_trait_selection",
4117-
"rustc_type_ir",
41184111
"smallvec",
41194112
"tracing",
41204113
]
@@ -4538,7 +4531,6 @@ dependencies = [
45384531
"rustc_span",
45394532
"rustc_target",
45404533
"rustc_trait_selection",
4541-
"rustc_type_ir",
45424534
"tracing",
45434535
]
45444536

‎compiler/rustc_abi/src/lib.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_data_structures::stable_hasher::StableOrd;
5252
use rustc_hashes::Hash64;
5353
use rustc_index::{Idx, IndexSlice, IndexVec};
5454
#[cfg(feature = "nightly")]
55-
use rustc_macros::{Decodable_Generic, Encodable_Generic, HashStable_Generic};
55+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
5656

5757
mod callconv;
5858
mod layout;
@@ -74,7 +74,10 @@ pub use layout::{LayoutCalculator, LayoutCalculatorError};
7474
pub trait HashStableContext {}
7575

7676
#[derive(Clone, Copy, PartialEq, Eq, Default)]
77-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
77+
#[cfg_attr(
78+
feature = "nightly",
79+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
80+
)]
7881
pub struct ReprFlags(u8);
7982

8083
bitflags! {
@@ -106,7 +109,10 @@ impl std::fmt::Debug for ReprFlags {
106109
}
107110

108111
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
109-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
112+
#[cfg_attr(
113+
feature = "nightly",
114+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
115+
)]
110116
pub enum IntegerType {
111117
/// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g.
112118
/// `Pointer(true)` means `isize`.
@@ -127,7 +133,10 @@ impl IntegerType {
127133

128134
/// Represents the repr options provided by the user.
129135
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
130-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
136+
#[cfg_attr(
137+
feature = "nightly",
138+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
139+
)]
131140
pub struct ReprOptions {
132141
pub int: Option<IntegerType>,
133142
pub align: Option<Align>,
@@ -487,7 +496,10 @@ impl FromStr for Endian {
487496

488497
/// Size of a type in bytes.
489498
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
490-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
499+
#[cfg_attr(
500+
feature = "nightly",
501+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
502+
)]
491503
pub struct Size {
492504
raw: u64,
493505
}
@@ -713,7 +725,10 @@ impl Step for Size {
713725

714726
/// Alignment of a type in bytes (always a power of two).
715727
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
716-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
728+
#[cfg_attr(
729+
feature = "nightly",
730+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
731+
)]
717732
pub struct Align {
718733
pow2: u8,
719734
}
@@ -872,7 +887,10 @@ impl AbiAndPrefAlign {
872887

873888
/// Integers, also used for enum discriminants.
874889
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
875-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
890+
#[cfg_attr(
891+
feature = "nightly",
892+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
893+
)]
876894
pub enum Integer {
877895
I8,
878896
I16,

0 commit comments

Comments
 (0)