Skip to content

Commit 9a7255e

Browse files
authored
Merge pull request rust-lang#4375 from rust-lang/rustup-2025-06-04
Automatic Rustup
2 parents 2d8ccc5 + db72088 commit 9a7255e

File tree

1,117 files changed

+61626
-6992
lines changed

Some content is hidden

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

1,117 files changed

+61626
-6992
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ members = [
44
# tidy-alphabetical-start
55
"compiler/rustc",
66
"src/build_helper",
7-
"src/etc/test-float-parse",
87
"src/rustc-std-workspace/rustc-std-workspace-alloc",
98
"src/rustc-std-workspace/rustc-std-workspace-core",
109
"src/rustc-std-workspace/rustc-std-workspace-std",
@@ -41,6 +40,7 @@ members = [
4140
"src/tools/rustdoc-themes",
4241
"src/tools/rustfmt",
4342
"src/tools/suggest-tests",
43+
"src/tools/test-float-parse",
4444
"src/tools/tidy",
4545
"src/tools/tier-check",
4646
"src/tools/unicode-table-generator",

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
use std::fmt;
2+
3+
#[cfg(feature = "nightly")]
4+
use rustc_macros::HashStable_Generic;
5+
6+
use crate::ExternAbi;
7+
8+
/// Calling convention to determine codegen
9+
///
10+
/// CanonAbi erases certain distinctions ExternAbi preserves, but remains target-dependent.
11+
/// There are still both target-specific variants and aliasing variants, though much fewer.
12+
/// The reason for this step is the frontend may wish to show an ExternAbi but implement that ABI
13+
/// using a different ABI than the string per se, or describe irrelevant differences, e.g.
14+
/// - extern "system"
15+
/// - extern "cdecl"
16+
/// - extern "C-unwind"
17+
/// In that sense, this erases mere syntactic distinctions to create a canonical *directive*,
18+
/// rather than picking the "actual" ABI.
19+
#[derive(Copy, Clone, Debug)]
20+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
21+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
22+
pub enum CanonAbi {
23+
// NOTE: the use of nested variants for some ABIs is for many targets they don't matter,
24+
// and this pushes the complexity of their reasoning to target-specific code,
25+
// allowing a `match` to easily exhaustively ignore these subcategories of variants.
26+
// Otherwise it is very tempting to avoid matching exhaustively!
27+
C,
28+
Rust,
29+
RustCold,
30+
31+
/// ABIs relevant to 32-bit Arm targets
32+
Arm(ArmCall),
33+
/// ABI relevant to GPUs: the entry point for a GPU kernel
34+
GpuKernel,
35+
36+
/// ABIs relevant to bare-metal interrupt targets
37+
// FIXME(workingjubilee): a particular reason for this nesting is we might not need these?
38+
// interrupt ABIs should have the same properties:
39+
// - uncallable by Rust calls, as LLVM rejects it in most cases
40+
// - uses a preserve-all-registers *callee* convention
41+
// - should always return `-> !` (effectively... it can't use normal `ret`)
42+
// what differs between targets is
43+
// - allowed arguments: x86 differs slightly, having 2-3 arguments which are handled magically
44+
// - may need special prologues/epilogues for some interrupts, without affecting "call ABI"
45+
Interrupt(InterruptKind),
46+
47+
/// ABIs relevant to Windows or x86 targets
48+
X86(X86Call),
49+
}
50+
51+
impl fmt::Display for CanonAbi {
52+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53+
self.to_erased_extern_abi().as_str().fmt(f)
54+
}
55+
}
56+
57+
impl CanonAbi {
58+
/// convert to the ExternAbi that *shares a string* with this CanonAbi
59+
///
60+
/// A target-insensitive mapping of CanonAbi to ExternAbi, convenient for "forwarding" impls.
61+
/// Importantly, the set of CanonAbi values is a logical *subset* of ExternAbi values,
62+
/// so this is injective: if you take an ExternAbi to a CanonAbi and back, you have lost data.
63+
const fn to_erased_extern_abi(self) -> ExternAbi {
64+
match self {
65+
CanonAbi::C => ExternAbi::C { unwind: false },
66+
CanonAbi::Rust => ExternAbi::Rust,
67+
CanonAbi::RustCold => ExternAbi::RustCold,
68+
CanonAbi::Arm(arm_call) => match arm_call {
69+
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
70+
ArmCall::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
71+
ArmCall::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
72+
},
73+
CanonAbi::GpuKernel => ExternAbi::GpuKernel,
74+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
75+
InterruptKind::Avr => ExternAbi::AvrInterrupt,
76+
InterruptKind::AvrNonBlocking => ExternAbi::AvrNonBlockingInterrupt,
77+
InterruptKind::Msp430 => ExternAbi::Msp430Interrupt,
78+
InterruptKind::RiscvMachine => ExternAbi::RiscvInterruptM,
79+
InterruptKind::RiscvSupervisor => ExternAbi::RiscvInterruptS,
80+
InterruptKind::X86 => ExternAbi::X86Interrupt,
81+
},
82+
CanonAbi::X86(x86_call) => match x86_call {
83+
X86Call::Fastcall => ExternAbi::Fastcall { unwind: false },
84+
X86Call::Stdcall => ExternAbi::Stdcall { unwind: false },
85+
X86Call::SysV64 => ExternAbi::SysV64 { unwind: false },
86+
X86Call::Thiscall => ExternAbi::Thiscall { unwind: false },
87+
X86Call::Vectorcall => ExternAbi::Vectorcall { unwind: false },
88+
X86Call::Win64 => ExternAbi::Win64 { unwind: false },
89+
},
90+
}
91+
}
92+
}
93+
94+
/// Callee codegen for interrupts
95+
///
96+
/// This is named differently from the "Call" enums because it is different:
97+
/// these "ABI" differences are not relevant to callers, since there is "no caller".
98+
/// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar.
99+
#[derive(Copy, Clone, Debug)]
100+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
101+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
102+
pub enum InterruptKind {
103+
Avr,
104+
AvrNonBlocking,
105+
Msp430,
106+
RiscvMachine,
107+
RiscvSupervisor,
108+
X86,
109+
}
110+
111+
/// ABIs defined for x86-{32,64}
112+
///
113+
/// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now?
114+
#[derive(Clone, Copy, Debug)]
115+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
116+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
117+
pub enum X86Call {
118+
/// "fastcall" has both GNU and Windows variants
119+
Fastcall,
120+
/// "stdcall" has both GNU and Windows variants
121+
Stdcall,
122+
SysV64,
123+
Thiscall,
124+
Vectorcall,
125+
Win64,
126+
}
127+
128+
/// ABIs defined for 32-bit Arm
129+
#[derive(Copy, Clone, Debug)]
130+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
131+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
132+
pub enum ArmCall {
133+
Aapcs,
134+
CCmseNonSecureCall,
135+
CCmseNonSecureEntry,
136+
}

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
77
#[cfg(feature = "nightly")]
88
use rustc_macros::{Decodable, Encodable};
99

10+
use crate::AbiFromStrErr;
11+
1012
#[cfg(test)]
1113
mod tests;
1214

@@ -99,11 +101,6 @@ macro_rules! abi_impls {
99101
}
100102
}
101103

102-
#[derive(Debug)]
103-
pub enum AbiFromStrErr {
104-
Unknown,
105-
}
106-
107104
abi_impls! {
108105
ExternAbi = {
109106
C { unwind: false } =><= "C",

compiler/rustc_abi/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
5555
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
5656

5757
mod callconv;
58+
mod canon_abi;
59+
mod extern_abi;
5860
mod layout;
5961
#[cfg(test)]
6062
mod tests;
6163

62-
mod extern_abi;
63-
6464
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
65+
pub use canon_abi::{ArmCall, CanonAbi, InterruptKind, X86Call};
6566
pub use extern_abi::{ExternAbi, all_names};
6667
#[cfg(feature = "nightly")]
6768
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
@@ -1895,3 +1896,11 @@ pub enum StructKind {
18951896
/// A univariant, but with a prefix of an arbitrary size & alignment (e.g., enum tag).
18961897
Prefixed(Size, Align),
18971898
}
1899+
1900+
#[derive(Clone, Debug)]
1901+
pub enum AbiFromStrErr {
1902+
/// not a known ABI
1903+
Unknown,
1904+
/// no "-unwind" variant can be used here
1905+
NoExplicitUnwind,
1906+
}

compiler/rustc_ast/src/ast.rs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ pub struct Path {
9999

100100
impl PartialEq<Symbol> for Path {
101101
#[inline]
102-
fn eq(&self, symbol: &Symbol) -> bool {
103-
matches!(&self.segments[..], [segment] if segment.ident.name == *symbol)
102+
fn eq(&self, name: &Symbol) -> bool {
103+
if let [segment] = self.segments.as_ref()
104+
&& segment.args.is_none()
105+
&& segment.ident.name == *name
106+
{
107+
true
108+
} else {
109+
false
110+
}
104111
}
105112
}
106113

@@ -120,17 +127,6 @@ impl Path {
120127
Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
121128
}
122129

123-
pub fn is_ident(&self, name: Symbol) -> bool {
124-
if let [segment] = self.segments.as_ref()
125-
&& segment.args.is_none()
126-
&& segment.ident.name == name
127-
{
128-
true
129-
} else {
130-
false
131-
}
132-
}
133-
134130
pub fn is_global(&self) -> bool {
135131
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
136132
}
@@ -2465,6 +2461,39 @@ impl TyKind {
24652461
None
24662462
}
24672463
}
2464+
2465+
/// Returns `true` if this type is considered a scalar primitive (e.g.,
2466+
/// `i32`, `u8`, `bool`, etc).
2467+
///
2468+
/// This check is based on **symbol equality** and does **not** remove any
2469+
/// path prefixes or references. If a type alias or shadowing is present
2470+
/// (e.g., `type i32 = CustomType;`), this method will still return `true`
2471+
/// for `i32`, even though it may not refer to the primitive type.
2472+
pub fn maybe_scalar(&self) -> bool {
2473+
let Some(ty_sym) = self.is_simple_path() else {
2474+
// unit type
2475+
return self.is_unit();
2476+
};
2477+
matches!(
2478+
ty_sym,
2479+
sym::i8
2480+
| sym::i16
2481+
| sym::i32
2482+
| sym::i64
2483+
| sym::i128
2484+
| sym::u8
2485+
| sym::u16
2486+
| sym::u32
2487+
| sym::u64
2488+
| sym::u128
2489+
| sym::f16
2490+
| sym::f32
2491+
| sym::f64
2492+
| sym::f128
2493+
| sym::char
2494+
| sym::bool
2495+
)
2496+
}
24682497
}
24692498

24702499
/// A pattern type pattern.

0 commit comments

Comments
 (0)