Skip to content

Rollup of 10 pull requests #136943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5932b2f
tests/assembly: make windows ABI test cross-compile
workingjubilee Feb 9, 2025
b3464fa
tests/assembly: make typed-swap test much less fragile
workingjubilee Feb 9, 2025
ee111b2
tests/assembly: use -Copt-level=3 instead of -O
workingjubilee Feb 9, 2025
833f070
tests/assembly: cross-compile x86-return-float
workingjubilee Feb 9, 2025
3580698
tests: issue-122805 -> dont-shuffle-bswaps
workingjubilee Feb 10, 2025
95357c7
Check whole Unsize predicate for escaping bound vars
compiler-errors Feb 10, 2025
8a0a4df
Add docs to bootstrap:src:utils:cache
Shourya742 Feb 11, 2025
24150eb
add unit test to bootstrap:util:cache:tests
Shourya742 Feb 11, 2025
7972aa2
dev-guide: Link to t-lang procedures for new features
madsmtm Feb 11, 2025
4c17270
tests: simplify dont-shuffle-bswaps test
workingjubilee Feb 10, 2025
3c0c9b6
tests/codegen: use -Copt-level=3 instead of -O
workingjubilee Feb 9, 2025
d9c7abb
compiler: narrow scope of nightly cfg in rustc_abi
workingjubilee Feb 10, 2025
038c183
compiler: remove rustc_target reexport of rustc_abi::HashStableContext
workingjubilee Feb 10, 2025
8abff35
compiler: compare and hash ExternAbi like its string
workingjubilee Feb 10, 2025
edff4fe
compiler: remove AbiDatas
workingjubilee Feb 11, 2025
f8570e8
compiler: remove rustc_abi::lookup and AbiUnsupported
workingjubilee Feb 11, 2025
7564f3c
compiler: Make middle errors `pub(crate)` and bury some dead code
workingjubilee Feb 12, 2025
8a70219
use cc archiver as default in `cc2ar`
onur-ozkan Feb 12, 2025
d99d8c2
Nuke `Buffer` abstraction from `librustdoc` 💣
yotamofek Feb 9, 2025
21bb8cb
Change swap_nonoverlapping from lang to library UB
saethlin Feb 11, 2025
a3f76ad
Rollup merge of #136758 - workingjubilee:specify-opt-level-for-tests,…
GuillaumeGomez Feb 12, 2025
f0af030
Rollup merge of #136761 - workingjubilee:specify-opt-level-for-codege…
GuillaumeGomez Feb 12, 2025
10b5596
Rollup merge of #136784 - yotamofek:pr/rustdoc-remove-buffer-take2, r…
GuillaumeGomez Feb 12, 2025
993eb34
Rollup merge of #136838 - compiler-errors:escaping-unsize, r=fmease
GuillaumeGomez Feb 12, 2025
2494905
Rollup merge of #136848 - Shourya742:2025-02-11-add-docs-and-ut-for-u…
GuillaumeGomez Feb 12, 2025
428baf5
Rollup merge of #136871 - madsmtm:link-to-lang-procedures, r=scottmcm
GuillaumeGomez Feb 12, 2025
269d784
Rollup merge of #136890 - saethlin:swap_nonoverlapping, r=RalfJung
GuillaumeGomez Feb 12, 2025
27dc222
Rollup merge of #136901 - workingjubilee:stabilize-externabi-hashing-…
GuillaumeGomez Feb 12, 2025
54b4b1c
Rollup merge of #136907 - workingjubilee:middle-errors-cleanup, r=com…
GuillaumeGomez Feb 12, 2025
8567fbb
Rollup merge of #136916 - onur-ozkan:fix-cc2ar, r=jieyouxu
GuillaumeGomez Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compiler: compare and hash ExternAbi like its string
Directly map each ExternAbi variant to its string and back again.
This has a few advantages:
- By making the ABIs compare equal to their strings, we can easily
  lexicographically sort them and use that sorted slice at runtime.
- We no longer need a workaround to make sure the hashes remain stable,
  as they already naturally are (by being the hashes of unique strings).
- The compiler can carry around less &str wide pointers
  • Loading branch information
workingjubilee committed Feb 12, 2025
commit 8abff35b41b8de89da35ab851f931d6a582f7670
141 changes: 129 additions & 12 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use std::cmp::Ordering;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::str::FromStr;

#[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable};

#[cfg(test)]
mod tests;

use ExternAbi as Abi;

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic, Encodable, Decodable))]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable))]
pub enum ExternAbi {
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
// hashing tests. These are used in many places, so giving them stable values reduces test
Expand Down Expand Up @@ -69,7 +74,123 @@ pub enum ExternAbi {
RiscvInterruptS,
}

impl Abi {
macro_rules! abi_impls {
($e_name:ident = {
$($variant:ident $({ unwind: $uw:literal })? =><= $tok:literal,)*
}) => {
impl $e_name {
pub const ALL_VARIANTS: &[Self] = &[
$($e_name::$variant $({ unwind: $uw })*,)*
];
pub const fn as_str(&self) -> &'static str {
match self {
$($e_name::$variant $( { unwind: $uw } )* => $tok,)*
}
}
}

impl ::core::str::FromStr for $e_name {
type Err = AbiFromStrErr;
fn from_str(s: &str) -> Result<$e_name, Self::Err> {
match s {
$($tok => Ok($e_name::$variant $({ unwind: $uw })*),)*
_ => Err(AbiFromStrErr::Unknown),
}
}
}
}
}

pub enum AbiFromStrErr {
Unknown,
}

abi_impls! {
ExternAbi = {
C { unwind: false } =><= "C",
CCmseNonSecureCall =><= "C-cmse-nonsecure-call",
CCmseNonSecureEntry =><= "C-cmse-nonsecure-entry",
C { unwind: true } =><= "C-unwind",
Rust =><= "Rust",
Aapcs { unwind: false } =><= "aapcs",
Aapcs { unwind: true } =><= "aapcs-unwind",
AvrInterrupt =><= "avr-interrupt",
AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
Cdecl { unwind: false } =><= "cdecl",
Cdecl { unwind: true } =><= "cdecl-unwind",
EfiApi =><= "efiapi",
Fastcall { unwind: false } =><= "fastcall",
Fastcall { unwind: true } =><= "fastcall-unwind",
GpuKernel =><= "gpu-kernel",
Msp430Interrupt =><= "msp430-interrupt",
PtxKernel =><= "ptx-kernel",
RiscvInterruptM =><= "riscv-interrupt-m",
RiscvInterruptS =><= "riscv-interrupt-s",
RustCall =><= "rust-call",
RustCold =><= "rust-cold",
RustIntrinsic =><= "rust-intrinsic",
Stdcall { unwind: false } =><= "stdcall",
Stdcall { unwind: true } =><= "stdcall-unwind",
System { unwind: false } =><= "system",
System { unwind: true } =><= "system-unwind",
SysV64 { unwind: false } =><= "sysv64",
SysV64 { unwind: true } =><= "sysv64-unwind",
Thiscall { unwind: false } =><= "thiscall",
Thiscall { unwind: true } =><= "thiscall-unwind",
Unadjusted =><= "unadjusted",
Vectorcall { unwind: false } =><= "vectorcall",
Vectorcall { unwind: true } =><= "vectorcall-unwind",
Win64 { unwind: false } =><= "win64",
Win64 { unwind: true } =><= "win64-unwind",
X86Interrupt =><= "x86-interrupt",
}
}

impl Ord for ExternAbi {
fn cmp(&self, rhs: &Self) -> Ordering {
self.as_str().cmp(rhs.as_str())
}
}

impl PartialOrd for ExternAbi {
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
Some(self.cmp(rhs))
}
}

impl PartialEq for ExternAbi {
fn eq(&self, rhs: &Self) -> bool {
self.cmp(rhs) == Ordering::Equal
}
}

impl Eq for ExternAbi {}

impl Hash for ExternAbi {
fn hash<H: Hasher>(&self, state: &mut H) {
self.as_str().hash(state);
// double-assurance of a prefix breaker
u32::from_be_bytes(*b"ABI\0").hash(state);
}
}

#[cfg(feature = "nightly")]
impl<C> HashStable<C> for ExternAbi {
#[inline]
fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) {
Hash::hash(self, hasher);
}
}

#[cfg(feature = "nightly")]
impl StableOrd for ExternAbi {
const CAN_USE_UNSTABLE_SORT: bool = true;

// because each ABI is hashed like a string, there is no possible instability
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl ExternAbi {
pub fn supports_varargs(self) -> bool {
// * C and Cdecl obviously support varargs.
// * C can be based on Aapcs, SysV64 or Win64, so they must support varargs.
Expand Down Expand Up @@ -145,15 +266,11 @@ pub const AbiDatas: &[AbiData] = &[
pub struct AbiUnsupported {}
/// Returns the ABI with the given name (if any).
pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
AbiDatas
.iter()
.find(|abi_data| name == abi_data.name)
.map(|&x| x.abi)
.ok_or_else(|| AbiUnsupported {})
ExternAbi::from_str(name).map_err(|_| AbiUnsupported {})
}

pub fn all_names() -> Vec<&'static str> {
AbiDatas.iter().map(|d| d.name).collect()
ExternAbi::ALL_VARIANTS.iter().map(|abi| abi.as_str()).collect()
}

impl Abi {
Expand Down Expand Up @@ -229,8 +346,8 @@ impl Abi {
}
}

impl fmt::Display for Abi {
impl fmt::Display for ExternAbi {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\"{}\"", self.name())
write!(f, "\"{}\"", self.as_str())
}
}
8 changes: 8 additions & 0 deletions compiler/rustc_abi/src/extern_abi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ fn indices_are_correct() {
assert_eq!(i, abi_data.abi.index());
}
}

#[test]
fn guarantee_lexicographic_ordering() {
let abis = ExternAbi::ALL_VARIANTS;
let mut sorted_abis = abis.to_vec();
sorted_abis.sort_unstable();
assert_eq!(abis, sorted_abis);
}
9 changes: 2 additions & 7 deletions compiler/rustc_ast_lowering/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,12 @@ enum GateReason {
impl fmt::Display for UnstableAbi {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { abi, .. } = self;
let name = abi.to_string();
let name = name.trim_matches('"');
match self.explain {
GateReason::Experimental => {
write!(f, r#"the extern "{name}" ABI is experimental and subject to change"#)
write!(f, "the extern {abi} ABI is experimental and subject to change")
}
GateReason::ImplDetail => {
write!(
f,
r#"the extern "{name}" ABI is an implementation detail and perma-unstable"#
)
write!(f, "the extern {abi} ABI is an implementation detail and perma-unstable")
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ fn print_crate_info(
}
}
CallingConventions => {
let mut calling_conventions = rustc_abi::all_names();
calling_conventions.sort_unstable();
let calling_conventions = rustc_abi::all_names();
println_info!("{}", calling_conventions.join("\n"));
}
RelocationModels
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/symbol-names/basic.legacy.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: symbol-name(_ZN5basic4main17h144191e1523a280eE)
error: symbol-name(_ZN5basic4main17hc88b9d80a69d119aE)
--> $DIR/basic.rs:8:1
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^

error: demangling(basic::main::h144191e1523a280e)
error: demangling(basic::main::hc88b9d80a69d119a)
--> $DIR/basic.rs:8:1
|
LL | #[rustc_symbol_name]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/symbol-names/issue-60925.legacy.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h71f988fda3b6b180E)
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17hbddb77d6f71afb32E)
--> $DIR/issue-60925.rs:21:9
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^

error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h71f988fda3b6b180)
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::hbddb77d6f71afb32)
--> $DIR/issue-60925.rs:21:9
|
LL | #[rustc_symbol_name]
Expand Down