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.
This commit is contained in:
parent
8abff35b41
commit
edff4fe2cc
5 changed files with 14 additions and 136 deletions
|
@ -214,54 +214,6 @@ impl ExternAbi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct AbiData {
|
|
||||||
pub abi: Abi,
|
|
||||||
|
|
||||||
/// Name of this ABI as we like it called.
|
|
||||||
pub name: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const AbiDatas: &[AbiData] = &[
|
|
||||||
AbiData { abi: Abi::Rust, name: "Rust" },
|
|
||||||
AbiData { abi: Abi::C { unwind: false }, name: "C" },
|
|
||||||
AbiData { abi: Abi::C { unwind: true }, name: "C-unwind" },
|
|
||||||
AbiData { abi: Abi::Cdecl { unwind: false }, name: "cdecl" },
|
|
||||||
AbiData { abi: Abi::Cdecl { unwind: true }, name: "cdecl-unwind" },
|
|
||||||
AbiData { abi: Abi::Stdcall { unwind: false }, name: "stdcall" },
|
|
||||||
AbiData { abi: Abi::Stdcall { unwind: true }, name: "stdcall-unwind" },
|
|
||||||
AbiData { abi: Abi::Fastcall { unwind: false }, name: "fastcall" },
|
|
||||||
AbiData { abi: Abi::Fastcall { unwind: true }, name: "fastcall-unwind" },
|
|
||||||
AbiData { abi: Abi::Vectorcall { unwind: false }, name: "vectorcall" },
|
|
||||||
AbiData { abi: Abi::Vectorcall { unwind: true }, name: "vectorcall-unwind" },
|
|
||||||
AbiData { abi: Abi::Thiscall { unwind: false }, name: "thiscall" },
|
|
||||||
AbiData { abi: Abi::Thiscall { unwind: true }, name: "thiscall-unwind" },
|
|
||||||
AbiData { abi: Abi::Aapcs { unwind: false }, name: "aapcs" },
|
|
||||||
AbiData { abi: Abi::Aapcs { unwind: true }, name: "aapcs-unwind" },
|
|
||||||
AbiData { abi: Abi::Win64 { unwind: false }, name: "win64" },
|
|
||||||
AbiData { abi: Abi::Win64 { unwind: true }, name: "win64-unwind" },
|
|
||||||
AbiData { abi: Abi::SysV64 { unwind: false }, name: "sysv64" },
|
|
||||||
AbiData { abi: Abi::SysV64 { unwind: true }, name: "sysv64-unwind" },
|
|
||||||
AbiData { abi: Abi::PtxKernel, name: "ptx-kernel" },
|
|
||||||
AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt" },
|
|
||||||
AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt" },
|
|
||||||
AbiData { abi: Abi::GpuKernel, name: "gpu-kernel" },
|
|
||||||
AbiData { abi: Abi::EfiApi, name: "efiapi" },
|
|
||||||
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
|
|
||||||
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
|
|
||||||
AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call" },
|
|
||||||
AbiData { abi: Abi::CCmseNonSecureEntry, name: "C-cmse-nonsecure-entry" },
|
|
||||||
AbiData { abi: Abi::System { unwind: false }, name: "system" },
|
|
||||||
AbiData { abi: Abi::System { unwind: true }, name: "system-unwind" },
|
|
||||||
AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
|
|
||||||
AbiData { abi: Abi::RustCall, name: "rust-call" },
|
|
||||||
AbiData { abi: Abi::Unadjusted, name: "unadjusted" },
|
|
||||||
AbiData { abi: Abi::RustCold, name: "rust-cold" },
|
|
||||||
AbiData { abi: Abi::RiscvInterruptM, name: "riscv-interrupt-m" },
|
|
||||||
AbiData { abi: Abi::RiscvInterruptS, name: "riscv-interrupt-s" },
|
|
||||||
];
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct AbiUnsupported {}
|
pub struct AbiUnsupported {}
|
||||||
/// Returns the ABI with the given name (if any).
|
/// Returns the ABI with the given name (if any).
|
||||||
|
@ -273,76 +225,12 @@ pub fn all_names() -> Vec<&'static str> {
|
||||||
ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
|
ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Abi {
|
impl ExternAbi {
|
||||||
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
|
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
|
||||||
pub const FALLBACK: Abi = Abi::C { unwind: false };
|
pub const FALLBACK: Abi = Abi::C { unwind: false };
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn index(self) -> usize {
|
|
||||||
// N.B., this ordering MUST match the AbiDatas array above.
|
|
||||||
// (This is ensured by the test indices_are_correct().)
|
|
||||||
use Abi::*;
|
|
||||||
let i = match self {
|
|
||||||
// Cross-platform ABIs
|
|
||||||
Rust => 0,
|
|
||||||
C { unwind: false } => 1,
|
|
||||||
C { unwind: true } => 2,
|
|
||||||
// Platform-specific ABIs
|
|
||||||
Cdecl { unwind: false } => 3,
|
|
||||||
Cdecl { unwind: true } => 4,
|
|
||||||
Stdcall { unwind: false } => 5,
|
|
||||||
Stdcall { unwind: true } => 6,
|
|
||||||
Fastcall { unwind: false } => 7,
|
|
||||||
Fastcall { unwind: true } => 8,
|
|
||||||
Vectorcall { unwind: false } => 9,
|
|
||||||
Vectorcall { unwind: true } => 10,
|
|
||||||
Thiscall { unwind: false } => 11,
|
|
||||||
Thiscall { unwind: true } => 12,
|
|
||||||
Aapcs { unwind: false } => 13,
|
|
||||||
Aapcs { unwind: true } => 14,
|
|
||||||
Win64 { unwind: false } => 15,
|
|
||||||
Win64 { unwind: true } => 16,
|
|
||||||
SysV64 { unwind: false } => 17,
|
|
||||||
SysV64 { unwind: true } => 18,
|
|
||||||
PtxKernel => 19,
|
|
||||||
Msp430Interrupt => 20,
|
|
||||||
X86Interrupt => 21,
|
|
||||||
GpuKernel => 22,
|
|
||||||
EfiApi => 23,
|
|
||||||
AvrInterrupt => 24,
|
|
||||||
AvrNonBlockingInterrupt => 25,
|
|
||||||
CCmseNonSecureCall => 26,
|
|
||||||
CCmseNonSecureEntry => 27,
|
|
||||||
// Cross-platform ABIs
|
|
||||||
System { unwind: false } => 28,
|
|
||||||
System { unwind: true } => 29,
|
|
||||||
RustIntrinsic => 30,
|
|
||||||
RustCall => 31,
|
|
||||||
Unadjusted => 32,
|
|
||||||
RustCold => 33,
|
|
||||||
RiscvInterruptM => 34,
|
|
||||||
RiscvInterruptS => 35,
|
|
||||||
};
|
|
||||||
debug_assert!(
|
|
||||||
AbiDatas
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.find(|(_, AbiData { abi, .. })| *abi == self)
|
|
||||||
.map(|(index, _)| index)
|
|
||||||
.expect("abi variant has associated data")
|
|
||||||
== i,
|
|
||||||
"Abi index did not match `AbiDatas` ordering"
|
|
||||||
);
|
|
||||||
i
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn data(self) -> &'static AbiData {
|
|
||||||
&AbiDatas[self.index()]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn name(self) -> &'static str {
|
pub fn name(self) -> &'static str {
|
||||||
self.data().name
|
self.as_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@ use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn lookup_Rust() {
|
fn lookup_Rust() {
|
||||||
let abi = lookup("Rust");
|
let abi = lookup("Rust");
|
||||||
assert!(abi.is_ok() && abi.unwrap().data().name == "Rust");
|
assert!(abi.is_ok() && abi.unwrap().as_str() == "Rust");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lookup_cdecl() {
|
fn lookup_cdecl() {
|
||||||
let abi = lookup("cdecl");
|
let abi = lookup("cdecl");
|
||||||
assert!(abi.is_ok() && abi.unwrap().data().name == "cdecl");
|
assert!(abi.is_ok() && abi.unwrap().as_str() == "cdecl");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,13 +21,6 @@ fn lookup_baz() {
|
||||||
assert_matches!(abi, Err(AbiUnsupported {}));
|
assert_matches!(abi, Err(AbiUnsupported {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn indices_are_correct() {
|
|
||||||
for (i, abi_data) in AbiDatas.iter().enumerate() {
|
|
||||||
assert_eq!(i, abi_data.abi.index());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn guarantee_lexicographic_ordering() {
|
fn guarantee_lexicographic_ordering() {
|
||||||
let abis = ExternAbi::ALL_VARIANTS;
|
let abis = ExternAbi::ALL_VARIANTS;
|
||||||
|
|
|
@ -62,7 +62,7 @@ mod tests;
|
||||||
mod extern_abi;
|
mod extern_abi;
|
||||||
|
|
||||||
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
|
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
|
||||||
pub use extern_abi::{AbiDatas, AbiUnsupported, ExternAbi, all_names, lookup};
|
pub use extern_abi::{AbiUnsupported, ExternAbi, all_names, lookup};
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
|
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
|
||||||
pub use layout::{LayoutCalculator, LayoutCalculatorError};
|
pub use layout::{LayoutCalculator, LayoutCalculatorError};
|
||||||
|
@ -1178,13 +1178,10 @@ impl Scalar {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_bool(&self) -> bool {
|
pub fn is_bool(&self) -> bool {
|
||||||
use Integer::*;
|
use Integer::*;
|
||||||
matches!(
|
matches!(self, Scalar::Initialized {
|
||||||
self,
|
value: Primitive::Int(I8, false),
|
||||||
Scalar::Initialized {
|
valid_range: WrappingRange { start: 0, end: 1 }
|
||||||
value: Primitive::Int(I8, false),
|
})
|
||||||
valid_range: WrappingRange { start: 0, end: 1 }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the primitive representation of this type, ignoring the valid range and whether the
|
/// Get the primitive representation of this type, ignoring the valid range and whether the
|
||||||
|
|
|
@ -8,10 +8,10 @@ use rustc_span::symbol::sym;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
pub(crate) fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> {
|
pub(crate) fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> {
|
||||||
rustc_abi::AbiDatas
|
ExternAbi::ALL_VARIANTS
|
||||||
.iter()
|
.into_iter()
|
||||||
.filter(|data| extern_abi_enabled(features, span, data.abi).is_ok())
|
.filter(|abi| extern_abi_enabled(features, span, **abi).is_ok())
|
||||||
.map(|d| d.name)
|
.map(|abi| abi.as_str())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -480,7 +480,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
||||||
ExternAbi::C { unwind: false } => cx.push("KC"),
|
ExternAbi::C { unwind: false } => cx.push("KC"),
|
||||||
abi => {
|
abi => {
|
||||||
cx.push("K");
|
cx.push("K");
|
||||||
let name = abi.name();
|
let name = abi.as_str();
|
||||||
if name.contains('-') {
|
if name.contains('-') {
|
||||||
cx.push_ident(&name.replace('-', "_"));
|
cx.push_ident(&name.replace('-', "_"));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue