Skip to content

Commit 4967fd2

Browse files
authored
Merge pull request #2461 from rust-lang/rustc-pull
Rustc pull update
2 parents 8290ab5 + 7565e75 commit 4967fd2

File tree

1,755 files changed

+72483
-16301
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,755 files changed

+72483
-16301
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,6 +4673,7 @@ dependencies = [
46734673
"bincode",
46744674
"rustc-hash 2.1.1",
46754675
"serde",
4676+
"serde_derive",
46764677
"serde_json",
46774678
]
46784679

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: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
// convert to the ExternAbi that *shares a string* with this CanonAbi.
54+
// FIXME: ideally we'd avoid printing `CanonAbi`, and preserve `ExternAbi` everywhere
55+
// that we need to generate error messages.
56+
let erased_abi = match self {
57+
CanonAbi::C => ExternAbi::C { unwind: false },
58+
CanonAbi::Rust => ExternAbi::Rust,
59+
CanonAbi::RustCold => ExternAbi::RustCold,
60+
CanonAbi::Arm(arm_call) => match arm_call {
61+
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
62+
ArmCall::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
63+
ArmCall::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
64+
},
65+
CanonAbi::GpuKernel => ExternAbi::GpuKernel,
66+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
67+
InterruptKind::Avr => ExternAbi::AvrInterrupt,
68+
InterruptKind::AvrNonBlocking => ExternAbi::AvrNonBlockingInterrupt,
69+
InterruptKind::Msp430 => ExternAbi::Msp430Interrupt,
70+
InterruptKind::RiscvMachine => ExternAbi::RiscvInterruptM,
71+
InterruptKind::RiscvSupervisor => ExternAbi::RiscvInterruptS,
72+
InterruptKind::X86 => ExternAbi::X86Interrupt,
73+
},
74+
CanonAbi::X86(x86_call) => match x86_call {
75+
X86Call::Fastcall => ExternAbi::Fastcall { unwind: false },
76+
X86Call::Stdcall => ExternAbi::Stdcall { unwind: false },
77+
X86Call::SysV64 => ExternAbi::SysV64 { unwind: false },
78+
X86Call::Thiscall => ExternAbi::Thiscall { unwind: false },
79+
X86Call::Vectorcall => ExternAbi::Vectorcall { unwind: false },
80+
X86Call::Win64 => ExternAbi::Win64 { unwind: false },
81+
},
82+
};
83+
erased_abi.as_str().fmt(f)
84+
}
85+
}
86+
87+
/// Callee codegen for interrupts
88+
///
89+
/// This is named differently from the "Call" enums because it is different:
90+
/// these "ABI" differences are not relevant to callers, since there is "no caller".
91+
/// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar.
92+
#[derive(Copy, Clone, Debug)]
93+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
94+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
95+
pub enum InterruptKind {
96+
Avr,
97+
AvrNonBlocking,
98+
Msp430,
99+
RiscvMachine,
100+
RiscvSupervisor,
101+
X86,
102+
}
103+
104+
/// ABIs defined for x86-{32,64}
105+
///
106+
/// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now?
107+
#[derive(Clone, Copy, Debug)]
108+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
109+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
110+
pub enum X86Call {
111+
/// "fastcall" has both GNU and Windows variants
112+
Fastcall,
113+
/// "stdcall" has both GNU and Windows variants
114+
Stdcall,
115+
SysV64,
116+
Thiscall,
117+
Vectorcall,
118+
Win64,
119+
}
120+
121+
/// ABIs defined for 32-bit Arm
122+
#[derive(Copy, Clone, Debug)]
123+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
124+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
125+
pub enum ArmCall {
126+
Aapcs,
127+
CCmseNonSecureCall,
128+
CCmseNonSecureEntry,
129+
}

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,98 @@ 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

13-
use ExternAbi as Abi;
14-
15+
/// ABI we expect to see within `extern "{abi}"`
1516
#[derive(Clone, Copy, Debug)]
1617
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable))]
1718
pub enum ExternAbi {
18-
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
19-
// hashing tests. These are used in many places, so giving them stable values reduces test
20-
// churn. The specific values are meaningless.
21-
Rust,
19+
/* universal */
20+
/// presumed C ABI for the platform
2221
C {
2322
unwind: bool,
2423
},
25-
Cdecl {
24+
/// ABI of the "system" interface, e.g. the Win32 API, always "aliasing"
25+
System {
2626
unwind: bool,
2727
},
28-
Stdcall {
28+
29+
/// that's us!
30+
Rust,
31+
/// the mostly-unused `unboxed_closures` ABI, effectively now an impl detail unless someone
32+
/// puts in the work to make it viable again... but would we need a special ABI?
33+
RustCall,
34+
/// For things unlikely to be called, where reducing register pressure in
35+
/// `extern "Rust"` callers is worth paying extra cost in the callee.
36+
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
37+
RustCold,
38+
39+
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
40+
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
41+
Unadjusted,
42+
43+
/// UEFI ABI, usually an alias of C, but sometimes an arch-specific alias
44+
/// and only valid on platforms that have a UEFI standard
45+
EfiApi,
46+
47+
/* arm */
48+
/// Arm Architecture Procedure Call Standard, sometimes `ExternAbi::C` is an alias for this
49+
Aapcs {
2950
unwind: bool,
3051
},
31-
Fastcall {
52+
/// extremely constrained barely-C ABI for TrustZone
53+
CCmseNonSecureCall,
54+
/// extremely constrained barely-C ABI for TrustZone
55+
CCmseNonSecureEntry,
56+
57+
/* gpu */
58+
/// An entry-point function called by the GPU's host
59+
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
60+
GpuKernel,
61+
/// An entry-point function called by the GPU's host
62+
// FIXME: why do we have two of these?
63+
PtxKernel,
64+
65+
/* interrupt */
66+
AvrInterrupt,
67+
AvrNonBlockingInterrupt,
68+
Msp430Interrupt,
69+
RiscvInterruptM,
70+
RiscvInterruptS,
71+
X86Interrupt,
72+
73+
/* x86 */
74+
/// `ExternAbi::C` but spelled funny because x86
75+
Cdecl {
3276
unwind: bool,
3377
},
34-
Vectorcall {
78+
/// gnu-stdcall on "unix" and win-stdcall on "windows"
79+
Stdcall {
3580
unwind: bool,
3681
},
37-
Thiscall {
82+
/// gnu-fastcall on "unix" and win-fastcall on "windows"
83+
Fastcall {
3884
unwind: bool,
3985
},
40-
Aapcs {
86+
/// windows C++ ABI
87+
Thiscall {
4188
unwind: bool,
4289
},
43-
Win64 {
90+
/// uses AVX and stuff
91+
Vectorcall {
4492
unwind: bool,
4593
},
94+
95+
/* x86_64 */
4696
SysV64 {
4797
unwind: bool,
4898
},
49-
PtxKernel,
50-
Msp430Interrupt,
51-
X86Interrupt,
52-
/// An entry-point function called by the GPU's host
53-
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
54-
GpuKernel,
55-
EfiApi,
56-
AvrInterrupt,
57-
AvrNonBlockingInterrupt,
58-
CCmseNonSecureCall,
59-
CCmseNonSecureEntry,
60-
System {
99+
Win64 {
61100
unwind: bool,
62101
},
63-
RustCall,
64-
/// *Not* a stable ABI, just directly use the Rust types to describe the ABI for LLVM. Even
65-
/// normally ABI-compatible Rust types can become ABI-incompatible with this ABI!
66-
Unadjusted,
67-
/// For things unlikely to be called, where reducing register pressure in
68-
/// `extern "Rust"` callers is worth paying extra cost in the callee.
69-
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
70-
RustCold,
71-
RiscvInterruptM,
72-
RiscvInterruptS,
73102
}
74103

75104
macro_rules! abi_impls {
@@ -99,11 +128,6 @@ macro_rules! abi_impls {
99128
}
100129
}
101130

102-
#[derive(Debug)]
103-
pub enum AbiFromStrErr {
104-
Unknown,
105-
}
106-
107131
abi_impls! {
108132
ExternAbi = {
109133
C { unwind: false } =><= "C",
@@ -227,7 +251,7 @@ pub fn all_names() -> Vec<&'static str> {
227251

228252
impl ExternAbi {
229253
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
230-
pub const FALLBACK: Abi = Abi::C { unwind: false };
254+
pub const FALLBACK: ExternAbi = ExternAbi::C { unwind: false };
231255

232256
pub fn name(self) -> &'static str {
233257
self.as_str()

compiler/rustc_abi/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
758758
niche_variants,
759759
niche_start,
760760
},
761-
tag_field: 0,
761+
tag_field: FieldIdx::new(0),
762762
variants: IndexVec::new(),
763763
},
764764
fields: FieldsShape::Arbitrary {
@@ -1072,7 +1072,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10721072
variants: Variants::Multiple {
10731073
tag,
10741074
tag_encoding: TagEncoding::Direct,
1075-
tag_field: 0,
1075+
tag_field: FieldIdx::new(0),
10761076
variants: IndexVec::new(),
10771077
},
10781078
fields: FieldsShape::Arbitrary {

compiler/rustc_abi/src/layout/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub(super) fn layout<
158158
// Build a prefix layout, including "promoting" all ineligible
159159
// locals as part of the prefix. We compute the layout of all of
160160
// these fields at once to get optimal packing.
161-
let tag_index = prefix_layouts.len();
161+
let tag_index = prefix_layouts.next_index();
162162

163163
// `variant_fields` already accounts for the reserved variants, so no need to add them.
164164
let max_discr = (variant_fields.len() - 1) as u128;
@@ -187,7 +187,7 @@ pub(super) fn layout<
187187

188188
// "a" (`0..b_start`) and "b" (`b_start..`) correspond to
189189
// "outer" and "promoted" fields respectively.
190-
let b_start = FieldIdx::new(tag_index + 1);
190+
let b_start = tag_index.plus(1);
191191
let offsets_b = IndexVec::from_raw(offsets.raw.split_off(b_start.index()));
192192
let offsets_a = offsets;
193193

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ rustc_index::newtype_index! {
3939
pub struct FieldIdx {}
4040
}
4141

42+
impl FieldIdx {
43+
/// The second field, at index 1.
44+
///
45+
/// For use alongside [`FieldIdx::ZERO`], particularly with scalar pairs.
46+
pub const ONE: FieldIdx = FieldIdx::from_u32(1);
47+
}
48+
4249
rustc_index::newtype_index! {
4350
/// The *source-order* index of a variant in a type.
4451
///
@@ -274,7 +281,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
274281

275282
/// Finds the one field that is not a 1-ZST.
276283
/// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields.
277-
pub fn non_1zst_field<C>(&self, cx: &C) -> Option<(usize, Self)>
284+
pub fn non_1zst_field<C>(&self, cx: &C) -> Option<(FieldIdx, Self)>
278285
where
279286
Ty: TyAbiInterface<'a, C> + Copy,
280287
{
@@ -288,7 +295,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
288295
// More than one non-1-ZST field.
289296
return None;
290297
}
291-
found = Some((field_idx, field));
298+
found = Some((FieldIdx::from_usize(field_idx), field));
292299
}
293300
found
294301
}

0 commit comments

Comments
 (0)