Skip to content

Commit edff4fe

Browse files
compiler: remove AbiDatas
These were a way to ensure hashes were stable over time for ExternAbi, but simply hashing the strings is more stable in the face of changes. As a result, we can do away with them.
1 parent 8abff35 commit edff4fe

File tree

5 files changed

+14
-136
lines changed

5 files changed

+14
-136
lines changed

compiler/rustc_abi/src/extern_abi.rs

+2-114
Original file line numberDiff line numberDiff line change
@@ -214,54 +214,6 @@ impl ExternAbi {
214214
}
215215
}
216216

217-
#[derive(Copy, Clone)]
218-
pub struct AbiData {
219-
pub abi: Abi,
220-
221-
/// Name of this ABI as we like it called.
222-
pub name: &'static str,
223-
}
224-
225-
#[allow(non_upper_case_globals)]
226-
pub const AbiDatas: &[AbiData] = &[
227-
AbiData { abi: Abi::Rust, name: "Rust" },
228-
AbiData { abi: Abi::C { unwind: false }, name: "C" },
229-
AbiData { abi: Abi::C { unwind: true }, name: "C-unwind" },
230-
AbiData { abi: Abi::Cdecl { unwind: false }, name: "cdecl" },
231-
AbiData { abi: Abi::Cdecl { unwind: true }, name: "cdecl-unwind" },
232-
AbiData { abi: Abi::Stdcall { unwind: false }, name: "stdcall" },
233-
AbiData { abi: Abi::Stdcall { unwind: true }, name: "stdcall-unwind" },
234-
AbiData { abi: Abi::Fastcall { unwind: false }, name: "fastcall" },
235-
AbiData { abi: Abi::Fastcall { unwind: true }, name: "fastcall-unwind" },
236-
AbiData { abi: Abi::Vectorcall { unwind: false }, name: "vectorcall" },
237-
AbiData { abi: Abi::Vectorcall { unwind: true }, name: "vectorcall-unwind" },
238-
AbiData { abi: Abi::Thiscall { unwind: false }, name: "thiscall" },
239-
AbiData { abi: Abi::Thiscall { unwind: true }, name: "thiscall-unwind" },
240-
AbiData { abi: Abi::Aapcs { unwind: false }, name: "aapcs" },
241-
AbiData { abi: Abi::Aapcs { unwind: true }, name: "aapcs-unwind" },
242-
AbiData { abi: Abi::Win64 { unwind: false }, name: "win64" },
243-
AbiData { abi: Abi::Win64 { unwind: true }, name: "win64-unwind" },
244-
AbiData { abi: Abi::SysV64 { unwind: false }, name: "sysv64" },
245-
AbiData { abi: Abi::SysV64 { unwind: true }, name: "sysv64-unwind" },
246-
AbiData { abi: Abi::PtxKernel, name: "ptx-kernel" },
247-
AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt" },
248-
AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt" },
249-
AbiData { abi: Abi::GpuKernel, name: "gpu-kernel" },
250-
AbiData { abi: Abi::EfiApi, name: "efiapi" },
251-
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
252-
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
253-
AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call" },
254-
AbiData { abi: Abi::CCmseNonSecureEntry, name: "C-cmse-nonsecure-entry" },
255-
AbiData { abi: Abi::System { unwind: false }, name: "system" },
256-
AbiData { abi: Abi::System { unwind: true }, name: "system-unwind" },
257-
AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
258-
AbiData { abi: Abi::RustCall, name: "rust-call" },
259-
AbiData { abi: Abi::Unadjusted, name: "unadjusted" },
260-
AbiData { abi: Abi::RustCold, name: "rust-cold" },
261-
AbiData { abi: Abi::RiscvInterruptM, name: "riscv-interrupt-m" },
262-
AbiData { abi: Abi::RiscvInterruptS, name: "riscv-interrupt-s" },
263-
];
264-
265217
#[derive(Copy, Clone, Debug)]
266218
pub struct AbiUnsupported {}
267219
/// Returns the ABI with the given name (if any).
@@ -273,76 +225,12 @@ pub fn all_names() -> Vec<&'static str> {
273225
ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
274226
}
275227

276-
impl Abi {
228+
impl ExternAbi {
277229
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
278230
pub const FALLBACK: Abi = Abi::C { unwind: false };
279231

280-
#[inline]
281-
pub fn index(self) -> usize {
282-
// N.B., this ordering MUST match the AbiDatas array above.
283-
// (This is ensured by the test indices_are_correct().)
284-
use Abi::*;
285-
let i = match self {
286-
// Cross-platform ABIs
287-
Rust => 0,
288-
C { unwind: false } => 1,
289-
C { unwind: true } => 2,
290-
// Platform-specific ABIs
291-
Cdecl { unwind: false } => 3,
292-
Cdecl { unwind: true } => 4,
293-
Stdcall { unwind: false } => 5,
294-
Stdcall { unwind: true } => 6,
295-
Fastcall { unwind: false } => 7,
296-
Fastcall { unwind: true } => 8,
297-
Vectorcall { unwind: false } => 9,
298-
Vectorcall { unwind: true } => 10,
299-
Thiscall { unwind: false } => 11,
300-
Thiscall { unwind: true } => 12,
301-
Aapcs { unwind: false } => 13,
302-
Aapcs { unwind: true } => 14,
303-
Win64 { unwind: false } => 15,
304-
Win64 { unwind: true } => 16,
305-
SysV64 { unwind: false } => 17,
306-
SysV64 { unwind: true } => 18,
307-
PtxKernel => 19,
308-
Msp430Interrupt => 20,
309-
X86Interrupt => 21,
310-
GpuKernel => 22,
311-
EfiApi => 23,
312-
AvrInterrupt => 24,
313-
AvrNonBlockingInterrupt => 25,
314-
CCmseNonSecureCall => 26,
315-
CCmseNonSecureEntry => 27,
316-
// Cross-platform ABIs
317-
System { unwind: false } => 28,
318-
System { unwind: true } => 29,
319-
RustIntrinsic => 30,
320-
RustCall => 31,
321-
Unadjusted => 32,
322-
RustCold => 33,
323-
RiscvInterruptM => 34,
324-
RiscvInterruptS => 35,
325-
};
326-
debug_assert!(
327-
AbiDatas
328-
.iter()
329-
.enumerate()
330-
.find(|(_, AbiData { abi, .. })| *abi == self)
331-
.map(|(index, _)| index)
332-
.expect("abi variant has associated data")
333-
== i,
334-
"Abi index did not match `AbiDatas` ordering"
335-
);
336-
i
337-
}
338-
339-
#[inline]
340-
pub fn data(self) -> &'static AbiData {
341-
&AbiDatas[self.index()]
342-
}
343-
344232
pub fn name(self) -> &'static str {
345-
self.data().name
233+
self.as_str()
346234
}
347235
}
348236

compiler/rustc_abi/src/extern_abi/tests.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use super::*;
66
#[test]
77
fn lookup_Rust() {
88
let abi = lookup("Rust");
9-
assert!(abi.is_ok() && abi.unwrap().data().name == "Rust");
9+
assert!(abi.is_ok() && abi.unwrap().as_str() == "Rust");
1010
}
1111

1212
#[test]
1313
fn lookup_cdecl() {
1414
let abi = lookup("cdecl");
15-
assert!(abi.is_ok() && abi.unwrap().data().name == "cdecl");
15+
assert!(abi.is_ok() && abi.unwrap().as_str() == "cdecl");
1616
}
1717

1818
#[test]
@@ -21,13 +21,6 @@ fn lookup_baz() {
2121
assert_matches!(abi, Err(AbiUnsupported {}));
2222
}
2323

24-
#[test]
25-
fn indices_are_correct() {
26-
for (i, abi_data) in AbiDatas.iter().enumerate() {
27-
assert_eq!(i, abi_data.abi.index());
28-
}
29-
}
30-
3124
#[test]
3225
fn guarantee_lexicographic_ordering() {
3326
let abis = ExternAbi::ALL_VARIANTS;

compiler/rustc_abi/src/lib.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod tests;
6262
mod extern_abi;
6363

6464
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
65-
pub use extern_abi::{AbiDatas, AbiUnsupported, ExternAbi, all_names, lookup};
65+
pub use extern_abi::{AbiUnsupported, ExternAbi, all_names, lookup};
6666
#[cfg(feature = "nightly")]
6767
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
6868
pub use layout::{LayoutCalculator, LayoutCalculatorError};
@@ -1178,13 +1178,10 @@ impl Scalar {
11781178
#[inline]
11791179
pub fn is_bool(&self) -> bool {
11801180
use Integer::*;
1181-
matches!(
1182-
self,
1183-
Scalar::Initialized {
1184-
value: Primitive::Int(I8, false),
1185-
valid_range: WrappingRange { start: 0, end: 1 }
1186-
}
1187-
)
1181+
matches!(self, Scalar::Initialized {
1182+
value: Primitive::Int(I8, false),
1183+
valid_range: WrappingRange { start: 0, end: 1 }
1184+
})
11881185
}
11891186

11901187
/// Get the primitive representation of this type, ignoring the valid range and whether the

compiler/rustc_ast_lowering/src/stability.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use rustc_span::symbol::sym;
88
use rustc_span::{Span, Symbol};
99

1010
pub(crate) fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> {
11-
rustc_abi::AbiDatas
12-
.iter()
13-
.filter(|data| extern_abi_enabled(features, span, data.abi).is_ok())
14-
.map(|d| d.name)
11+
ExternAbi::ALL_VARIANTS
12+
.into_iter()
13+
.filter(|abi| extern_abi_enabled(features, span, **abi).is_ok())
14+
.map(|abi| abi.as_str())
1515
.collect()
1616
}
1717

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
480480
ExternAbi::C { unwind: false } => cx.push("KC"),
481481
abi => {
482482
cx.push("K");
483-
let name = abi.name();
483+
let name = abi.as_str();
484484
if name.contains('-') {
485485
cx.push_ident(&name.replace('-', "_"));
486486
} else {

0 commit comments

Comments
 (0)