Skip to content

Commit 6d045f2

Browse files
committed
Auto merge of #157522 - jhpratt:rollup-scTvYPX, r=jhpratt
Rollup of 5 pull requests Successful merges: - #157016 (add `extern "tail"` calling convention) - #157264 (diagnostics: Fix ICE building a trait ref in method suggestions) - #157488 (compiletest: inject `#![windows_subsystem = "windows"]` to debuginfo tests on Windows) - #156136 (Move tests box) - #157494 (Convert `QueryRegionConstraint` into a struct)
2 parents 8954863 + af392d0 commit 6d045f2

40 files changed

Lines changed: 466 additions & 60 deletions

File tree

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum CanonAbi {
2828
Rust,
2929
RustCold,
3030
RustPreserveNone,
31+
RustTail,
3132

3233
/// An ABI that rustc does not know how to call or define.
3334
Custom,
@@ -59,7 +60,10 @@ pub enum CanonAbi {
5960
impl CanonAbi {
6061
pub fn is_rustic_abi(self) -> bool {
6162
match self {
62-
CanonAbi::Rust | CanonAbi::RustCold | CanonAbi::RustPreserveNone => true,
63+
CanonAbi::Rust
64+
| CanonAbi::RustCold
65+
| CanonAbi::RustPreserveNone
66+
| CanonAbi::RustTail => true,
6367
CanonAbi::C
6468
| CanonAbi::Custom
6569
| CanonAbi::Swift
@@ -81,6 +85,7 @@ impl fmt::Display for CanonAbi {
8185
CanonAbi::Rust => ExternAbi::Rust,
8286
CanonAbi::RustCold => ExternAbi::RustCold,
8387
CanonAbi::RustPreserveNone => ExternAbi::RustPreserveNone,
88+
CanonAbi::RustTail => ExternAbi::RustTail,
8489
CanonAbi::Custom => ExternAbi::Custom,
8590
CanonAbi::Swift => ExternAbi::Swift,
8691
CanonAbi::Arm(arm_call) => match arm_call {

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ pub enum ExternAbi {
4949
/// forcing callers to save all registers.
5050
RustPreserveNone,
5151

52+
/// Ensures that calls in tail position can always be optimized into a jump.
53+
///
54+
/// This ABI is not stable, and relies on LLVM implementation details.
55+
RustTail,
56+
5257
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
5358
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
5459
Unadjusted,
@@ -205,6 +210,7 @@ abi_impls! {
205210
System { unwind: true } =><= "system-unwind",
206211
SysV64 { unwind: false } =><= "sysv64",
207212
SysV64 { unwind: true } =><= "sysv64-unwind",
213+
RustTail =><= "tail",
208214
Thiscall { unwind: false } =><= "thiscall",
209215
Thiscall { unwind: true } =><= "thiscall-unwind",
210216
Unadjusted =><= "unadjusted",
@@ -280,7 +286,7 @@ impl ExternAbi {
280286
/// - are subject to change between compiler versions
281287
pub fn is_rustic_abi(self) -> bool {
282288
use ExternAbi::*;
283-
matches!(self, Rust | RustCall | RustCold | RustPreserveNone)
289+
matches!(self, Rust | RustCall | RustCold | RustPreserveNone | RustTail)
284290
}
285291

286292
/// Returns whether the ABI supports C variadics. This only controls whether we allow *imports*
@@ -354,6 +360,7 @@ impl ExternAbi {
354360
| Self::SysV64 { .. }
355361
| Self::Win64 { .. }
356362
| Self::RustPreserveNone
363+
| Self::RustTail
357364
| Self::Swift => true,
358365
}
359366
}

compiler/rustc_ast_lowering/src/stability.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
100100
feature: sym::rust_preserve_none_cc,
101101
explain: GateReason::Experimental,
102102
}),
103+
ExternAbi::RustTail => {
104+
Err(UnstableAbi { abi, feature: sym::rust_tail_cc, explain: GateReason::Experimental })
105+
}
103106
ExternAbi::RustInvalid => {
104107
Err(UnstableAbi { abi, feature: sym::rustc_attrs, explain: GateReason::ImplDetail })
105108
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ impl<'a> AstValidator<'a> {
424424
| CanonAbi::Rust
425425
| CanonAbi::RustCold
426426
| CanonAbi::RustPreserveNone
427+
| CanonAbi::RustTail
427428
| CanonAbi::Swift
428429
| CanonAbi::Arm(_)
429430
| CanonAbi::X86(_) => { /* nothing to check */ }

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::fx::FxHashSet;
22
use rustc_hir::def_id::LocalDefId;
33
use rustc_infer::infer::SubregionOrigin;
4-
use rustc_infer::infer::canonical::QueryRegionConstraints;
4+
use rustc_infer::infer::canonical::{QueryRegionConstraint, QueryRegionConstraints};
55
use rustc_infer::infer::outlives::env::RegionBoundPairs;
66
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
77
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
@@ -74,9 +74,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
7474
let assumptions =
7575
elaborate::elaborate_outlives_assumptions(self.infcx.tcx, assumptions.iter().copied());
7676

77-
for &(constraint, constraint_category, _) in constraints {
77+
for &QueryRegionConstraint { constraint, category, .. } in constraints {
7878
constraint.iter_outlives().for_each(|predicate| {
79-
self.convert(predicate, constraint_category, &assumptions);
79+
self.convert(predicate, category, &assumptions);
8080
});
8181
}
8282
}
@@ -296,7 +296,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
296296
// FIXME(higher_ranked_auto): What should we do with the assumptions here?
297297
if let Some(QueryRegionConstraints { constraints, assumptions: _ }) = constraints {
298298
next_outlives_predicates.extend(constraints.iter().flat_map(
299-
|(constraint, category, _)| {
299+
|QueryRegionConstraint { constraint, category, .. }| {
300300
constraint.iter_outlives().map(|outlives| (outlives, *category))
301301
},
302302
));

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ pub(crate) fn conv_to_call_conv(
5555
match c {
5656
CanonAbi::Rust | CanonAbi::RustCold | CanonAbi::C => default_call_conv,
5757

58-
// Cranelift doesn't currently have anything for this.
59-
CanonAbi::RustPreserveNone => default_call_conv,
58+
CanonAbi::RustPreserveNone | CanonAbi::RustTail => {
59+
sess.dcx().fatal(format!("call conv {c:?} is LLVM-specific"))
60+
}
6061

6162
// Functions with this calling convention can only be called from assembly, but it is
6263
// possible to declare an `extern "custom"` block, so the backend still needs a calling
@@ -71,7 +72,7 @@ pub(crate) fn conv_to_call_conv(
7172
},
7273

7374
CanonAbi::Interrupt(_) | CanonAbi::Arm(_) | CanonAbi::Swift => {
74-
sess.dcx().fatal("call conv {c:?} is not yet implemented")
75+
sess.dcx().fatal(format!("call conv {c:?} is not yet implemented"))
7576
}
7677
CanonAbi::GpuKernel => {
7778
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target")

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::bug;
1010
use rustc_middle::ty::Ty;
1111
use rustc_middle::ty::layout::LayoutOf;
1212
#[cfg(feature = "master")]
13-
use rustc_session::config;
13+
use rustc_session::{Session, config};
1414
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
1515
#[cfg(feature = "master")]
1616
use rustc_target::spec::Arch;
@@ -230,32 +230,43 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
230230

231231
#[cfg(feature = "master")]
232232
fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option<FnAttribute<'gcc>> {
233-
conv_to_fn_attribute(self.conv, &cx.tcx.sess.target.arch)
233+
conv_to_fn_attribute(cx.sess(), self.conv)
234234
}
235235
}
236236

237237
#[cfg(feature = "master")]
238-
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttribute<'gcc>> {
238+
pub fn conv_to_fn_attribute<'gcc>(sess: &Session, conv: CanonAbi) -> Option<FnAttribute<'gcc>> {
239239
let attribute = match conv {
240240
CanonAbi::C | CanonAbi::Rust => return None,
241-
// gcc/gccjit does not have anything for this.
242-
CanonAbi::RustPreserveNone => return None,
241+
CanonAbi::RustPreserveNone => {
242+
// This calling convention is LLVM-specific and unspecified.
243+
sess.dcx()
244+
.fatal("gcc/gccjit backend does not support RustPreserveNone calling convention")
245+
}
246+
CanonAbi::RustTail => {
247+
// This calling convention is LLVM-specific and unspecified.
248+
sess.dcx().fatal("gcc/gccjit backend does not support RustTail calling convention")
249+
}
243250
CanonAbi::RustCold => FnAttribute::Cold,
244251
// Functions with this calling convention can only be called from assembly, but it is
245252
// possible to declare an `extern "custom"` block, so the backend still needs a calling
246253
// convention for declaring foreign functions.
247254
CanonAbi::Custom => return None,
248-
// gcc/gccjit does not have anything for Swift's calling convention.
249-
CanonAbi::Swift => panic!("gcc/gccjit backend does not support Swift calling convention"),
255+
CanonAbi::Swift => {
256+
// gcc/gccjit does not have anything for Swift's calling convention.
257+
sess.dcx().fatal("gcc/gccjit backend does not support Swift calling convention")
258+
}
250259
CanonAbi::Arm(arm_call) => match arm_call {
251260
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
252261
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
253262
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
254263
},
255-
CanonAbi::GpuKernel => match arch {
264+
CanonAbi::GpuKernel => match &sess.target.arch {
256265
&Arch::AmdGpu => FnAttribute::GcnAmdGpuHsaKernel,
257266
&Arch::Nvptx64 => FnAttribute::NvptxKernel,
258-
arch => panic!("Arch {arch} does not support GpuKernel calling convention"),
267+
arch => sess
268+
.dcx()
269+
.fatal(format!("Arch {arch} does not support GpuKernel calling convention")),
259270
},
260271
// FIXME(antoyo): check if those AVR attributes are mapped correctly.
261272
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
486486
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
487487
let entry_name = self.sess().target.entry_name.as_ref();
488488
if !self.functions.borrow().contains_key(entry_name) {
489-
#[cfg(feature = "master")]
490-
let conv = conv_to_fn_attribute(self.sess().target.entry_abi, &self.sess().target.arch);
491-
#[cfg(not(feature = "master"))]
492-
let conv = None;
489+
let conv = cfg_select! {
490+
feature = "master" => conv_to_fn_attribute(self.sess(), self.sess().target.entry_abi),
491+
_ => None,
492+
};
493493
Some(self.declare_entry_fn(entry_name, fn_type, conv))
494494
} else {
495495
// If the symbol already exists, it is an error: for example, the user wrote

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
723723
Arch::X86_64 | Arch::AArch64 => llvm::PreserveNone,
724724
_ => llvm::CCallConv,
725725
},
726+
CanonAbi::RustTail => match &sess.target.arch {
727+
Arch::X86 | Arch::X86_64 | Arch::AArch64 => llvm::Tail,
728+
_ => sess.dcx().fatal("extern \"tail\" is only supported on x86_64 and aarch64"),
729+
},
726730
// Functions with this calling convention can only be called from assembly, but it is
727731
// possible to declare an `extern "custom"` block, so the backend still needs a calling
728732
// convention for declaring foreign functions.

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ declare_features! (
709709
(unstable, rust_cold_cc, "1.63.0", Some(97544)),
710710
/// Allows `extern "rust-preserve-none"`.
711711
(unstable, rust_preserve_none_cc, "1.95.0", Some(151401)),
712+
/// Allows `extern "tail"`.
713+
(unstable, rust_tail_cc, "CURRENT_RUSTC_VERSION", Some(157427)),
712714
/// Target features on s390x.
713715
(unstable, s390x_target_feature, "1.82.0", Some(150259)),
714716
/// Allows the use of the `sanitize` attribute.

0 commit comments

Comments
 (0)