Skip to content

Commit f05d87e

Browse files
authored
Unrolled build for #144712
Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease Deduplicate `IntTy`/`UintTy`/`FloatTy`. There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed. r? `@fmease`
2 parents 3fb1b53 + 704f2ca commit f05d87e

File tree

30 files changed

+312
-403
lines changed

30 files changed

+312
-403
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,7 @@ dependencies = [
34173417
"rustc_data_structures",
34183418
"rustc_macros",
34193419
"rustc_serialize",
3420+
"rustc_span",
34203421
]
34213422

34223423
[[package]]

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{cmp, fmt};
2323

2424
pub use GenericArgs::*;
2525
pub use UnsafeSource::*;
26-
pub use rustc_ast_ir::{Movability, Mutability, Pinnedness};
26+
pub use rustc_ast_ir::{FloatTy, IntTy, Movability, Mutability, Pinnedness, UintTy};
2727
use rustc_data_structures::packed::Pu128;
2828
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2929
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -2285,105 +2285,6 @@ pub struct FnSig {
22852285
pub span: Span,
22862286
}
22872287

2288-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
2289-
#[derive(Encodable, Decodable, HashStable_Generic)]
2290-
pub enum FloatTy {
2291-
F16,
2292-
F32,
2293-
F64,
2294-
F128,
2295-
}
2296-
2297-
impl FloatTy {
2298-
pub fn name_str(self) -> &'static str {
2299-
match self {
2300-
FloatTy::F16 => "f16",
2301-
FloatTy::F32 => "f32",
2302-
FloatTy::F64 => "f64",
2303-
FloatTy::F128 => "f128",
2304-
}
2305-
}
2306-
2307-
pub fn name(self) -> Symbol {
2308-
match self {
2309-
FloatTy::F16 => sym::f16,
2310-
FloatTy::F32 => sym::f32,
2311-
FloatTy::F64 => sym::f64,
2312-
FloatTy::F128 => sym::f128,
2313-
}
2314-
}
2315-
}
2316-
2317-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
2318-
#[derive(Encodable, Decodable, HashStable_Generic)]
2319-
pub enum IntTy {
2320-
Isize,
2321-
I8,
2322-
I16,
2323-
I32,
2324-
I64,
2325-
I128,
2326-
}
2327-
2328-
impl IntTy {
2329-
pub fn name_str(&self) -> &'static str {
2330-
match *self {
2331-
IntTy::Isize => "isize",
2332-
IntTy::I8 => "i8",
2333-
IntTy::I16 => "i16",
2334-
IntTy::I32 => "i32",
2335-
IntTy::I64 => "i64",
2336-
IntTy::I128 => "i128",
2337-
}
2338-
}
2339-
2340-
pub fn name(&self) -> Symbol {
2341-
match *self {
2342-
IntTy::Isize => sym::isize,
2343-
IntTy::I8 => sym::i8,
2344-
IntTy::I16 => sym::i16,
2345-
IntTy::I32 => sym::i32,
2346-
IntTy::I64 => sym::i64,
2347-
IntTy::I128 => sym::i128,
2348-
}
2349-
}
2350-
}
2351-
2352-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
2353-
#[derive(Encodable, Decodable, HashStable_Generic)]
2354-
pub enum UintTy {
2355-
Usize,
2356-
U8,
2357-
U16,
2358-
U32,
2359-
U64,
2360-
U128,
2361-
}
2362-
2363-
impl UintTy {
2364-
pub fn name_str(&self) -> &'static str {
2365-
match *self {
2366-
UintTy::Usize => "usize",
2367-
UintTy::U8 => "u8",
2368-
UintTy::U16 => "u16",
2369-
UintTy::U32 => "u32",
2370-
UintTy::U64 => "u64",
2371-
UintTy::U128 => "u128",
2372-
}
2373-
}
2374-
2375-
pub fn name(&self) -> Symbol {
2376-
match *self {
2377-
UintTy::Usize => sym::usize,
2378-
UintTy::U8 => sym::u8,
2379-
UintTy::U16 => sym::u16,
2380-
UintTy::U32 => sym::u32,
2381-
UintTy::U64 => sym::u64,
2382-
UintTy::U128 => sym::u128,
2383-
}
2384-
}
2385-
}
2386-
23872288
/// A constraint on an associated item.
23882289
///
23892290
/// ### Examples

compiler/rustc_ast/src/util/literal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ impl fmt::Display for LitKind {
190190
LitKind::Int(n, ty) => {
191191
write!(f, "{n}")?;
192192
match ty {
193-
ast::LitIntType::Unsigned(ty) => write!(f, "{}", ty.name())?,
194-
ast::LitIntType::Signed(ty) => write!(f, "{}", ty.name())?,
193+
ast::LitIntType::Unsigned(ty) => write!(f, "{}", ty.name_str())?,
194+
ast::LitIntType::Signed(ty) => write!(f, "{}", ty.name_str())?,
195195
ast::LitIntType::Unsuffixed => {}
196196
}
197197
}
198198
LitKind::Float(symbol, ty) => {
199199
write!(f, "{symbol}")?;
200200
match ty {
201-
ast::LitFloatType::Suffixed(ty) => write!(f, "{}", ty.name())?,
201+
ast::LitFloatType::Suffixed(ty) => write!(f, "{}", ty.name_str())?,
202202
ast::LitFloatType::Unsuffixed => {}
203203
}
204204
}

compiler/rustc_ast_ir/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ edition = "2024"
88
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
99
rustc_macros = { path = "../rustc_macros", optional = true }
1010
rustc_serialize = { path = "../rustc_serialize", optional = true }
11+
rustc_span = { path = "../rustc_span", optional = true }
1112
# tidy-alphabetical-end
1213

1314
[features]
15+
# tidy-alphabetical-start
1416
default = ["nightly"]
1517
nightly = [
16-
"dep:rustc_serialize",
1718
"dep:rustc_data_structures",
1819
"dep:rustc_macros",
20+
"dep:rustc_serialize",
21+
"dep:rustc_span",
1922
]
23+
# tidy-alphabetical-end

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,221 @@
1111
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
1212
// tidy-alphabetical-end
1313

14+
use std::fmt;
15+
1416
#[cfg(feature = "nightly")]
1517
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
18+
#[cfg(feature = "nightly")]
19+
use rustc_span::{Symbol, sym};
1620

1721
pub mod visit;
1822

23+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
24+
#[cfg_attr(
25+
feature = "nightly",
26+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
27+
)]
28+
pub enum IntTy {
29+
Isize,
30+
I8,
31+
I16,
32+
I32,
33+
I64,
34+
I128,
35+
}
36+
37+
impl IntTy {
38+
pub fn name_str(&self) -> &'static str {
39+
match *self {
40+
IntTy::Isize => "isize",
41+
IntTy::I8 => "i8",
42+
IntTy::I16 => "i16",
43+
IntTy::I32 => "i32",
44+
IntTy::I64 => "i64",
45+
IntTy::I128 => "i128",
46+
}
47+
}
48+
49+
#[cfg(feature = "nightly")]
50+
pub fn name(self) -> Symbol {
51+
match self {
52+
IntTy::Isize => sym::isize,
53+
IntTy::I8 => sym::i8,
54+
IntTy::I16 => sym::i16,
55+
IntTy::I32 => sym::i32,
56+
IntTy::I64 => sym::i64,
57+
IntTy::I128 => sym::i128,
58+
}
59+
}
60+
61+
pub fn bit_width(&self) -> Option<u64> {
62+
Some(match *self {
63+
IntTy::Isize => return None,
64+
IntTy::I8 => 8,
65+
IntTy::I16 => 16,
66+
IntTy::I32 => 32,
67+
IntTy::I64 => 64,
68+
IntTy::I128 => 128,
69+
})
70+
}
71+
72+
pub fn normalize(&self, target_width: u32) -> Self {
73+
match self {
74+
IntTy::Isize => match target_width {
75+
16 => IntTy::I16,
76+
32 => IntTy::I32,
77+
64 => IntTy::I64,
78+
_ => unreachable!(),
79+
},
80+
_ => *self,
81+
}
82+
}
83+
84+
pub fn to_unsigned(self) -> UintTy {
85+
match self {
86+
IntTy::Isize => UintTy::Usize,
87+
IntTy::I8 => UintTy::U8,
88+
IntTy::I16 => UintTy::U16,
89+
IntTy::I32 => UintTy::U32,
90+
IntTy::I64 => UintTy::U64,
91+
IntTy::I128 => UintTy::U128,
92+
}
93+
}
94+
}
95+
96+
impl fmt::Debug for IntTy {
97+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98+
write!(f, "{}", self.name_str())
99+
}
100+
}
101+
102+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
103+
#[cfg_attr(
104+
feature = "nightly",
105+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
106+
)]
107+
pub enum UintTy {
108+
Usize,
109+
U8,
110+
U16,
111+
U32,
112+
U64,
113+
U128,
114+
}
115+
116+
impl UintTy {
117+
pub fn name_str(&self) -> &'static str {
118+
match *self {
119+
UintTy::Usize => "usize",
120+
UintTy::U8 => "u8",
121+
UintTy::U16 => "u16",
122+
UintTy::U32 => "u32",
123+
UintTy::U64 => "u64",
124+
UintTy::U128 => "u128",
125+
}
126+
}
127+
128+
#[cfg(feature = "nightly")]
129+
pub fn name(self) -> Symbol {
130+
match self {
131+
UintTy::Usize => sym::usize,
132+
UintTy::U8 => sym::u8,
133+
UintTy::U16 => sym::u16,
134+
UintTy::U32 => sym::u32,
135+
UintTy::U64 => sym::u64,
136+
UintTy::U128 => sym::u128,
137+
}
138+
}
139+
140+
pub fn bit_width(&self) -> Option<u64> {
141+
Some(match *self {
142+
UintTy::Usize => return None,
143+
UintTy::U8 => 8,
144+
UintTy::U16 => 16,
145+
UintTy::U32 => 32,
146+
UintTy::U64 => 64,
147+
UintTy::U128 => 128,
148+
})
149+
}
150+
151+
pub fn normalize(&self, target_width: u32) -> Self {
152+
match self {
153+
UintTy::Usize => match target_width {
154+
16 => UintTy::U16,
155+
32 => UintTy::U32,
156+
64 => UintTy::U64,
157+
_ => unreachable!(),
158+
},
159+
_ => *self,
160+
}
161+
}
162+
163+
pub fn to_signed(self) -> IntTy {
164+
match self {
165+
UintTy::Usize => IntTy::Isize,
166+
UintTy::U8 => IntTy::I8,
167+
UintTy::U16 => IntTy::I16,
168+
UintTy::U32 => IntTy::I32,
169+
UintTy::U64 => IntTy::I64,
170+
UintTy::U128 => IntTy::I128,
171+
}
172+
}
173+
}
174+
175+
impl fmt::Debug for UintTy {
176+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
177+
write!(f, "{}", self.name_str())
178+
}
179+
}
180+
181+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
182+
#[cfg_attr(
183+
feature = "nightly",
184+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
185+
)]
186+
pub enum FloatTy {
187+
F16,
188+
F32,
189+
F64,
190+
F128,
191+
}
192+
193+
impl FloatTy {
194+
pub fn name_str(self) -> &'static str {
195+
match self {
196+
FloatTy::F16 => "f16",
197+
FloatTy::F32 => "f32",
198+
FloatTy::F64 => "f64",
199+
FloatTy::F128 => "f128",
200+
}
201+
}
202+
203+
#[cfg(feature = "nightly")]
204+
pub fn name(self) -> Symbol {
205+
match self {
206+
FloatTy::F16 => sym::f16,
207+
FloatTy::F32 => sym::f32,
208+
FloatTy::F64 => sym::f64,
209+
FloatTy::F128 => sym::f128,
210+
}
211+
}
212+
213+
pub fn bit_width(self) -> u64 {
214+
match self {
215+
FloatTy::F16 => 16,
216+
FloatTy::F32 => 32,
217+
FloatTy::F64 => 64,
218+
FloatTy::F128 => 128,
219+
}
220+
}
221+
}
222+
223+
impl fmt::Debug for FloatTy {
224+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
225+
write!(f, "{}", self.name_str())
226+
}
227+
}
228+
19229
/// The movability of a coroutine / closure literal:
20230
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
21231
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ tracing = "0.1"
4545
# tidy-alphabetical-end
4646

4747
[features]
48+
# tidy-alphabetical-start
4849
check_only = ["rustc_llvm/check_only"]
50+
# tidy-alphabetical-end
51+

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version = "0.0.0"
44
edition = "2024"
55

66
[dependencies]
7-
jiff = { version = "0.2.5", default-features = false, features = ["std"] }
87
# tidy-alphabetical-start
8+
jiff = { version = "0.2.5", default-features = false, features = ["std"] }
99
rustc_abi = { path = "../rustc_abi" }
1010
rustc_ast = { path = "../rustc_ast" }
1111
rustc_ast_lowering = { path = "../rustc_ast_lowering" }

0 commit comments

Comments
 (0)