Skip to content

Commit d5e900b

Browse files
committed
Auto merge of rust-lang#135509 - matthiaskrgr:rollup-4ua3iix, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#134940 (Make sure to scrape region constraints from deeply normalizing type outlives assumptions in borrowck) - rust-lang#135047 (Add gpu-kernel calling convention) - rust-lang#135228 (Improve `DispatchFromDyn` and `CoerceUnsized` impl validation) - rust-lang#135264 (Consider more erroneous layouts as `LayoutError::ReferencesError` to suppress spurious errors) - rust-lang#135302 (for purely return-type based searches, deprioritize clone-like functions) - rust-lang#135380 (Make sure we can produce `ConstArgHasWrongType` errors for valtree consts) - rust-lang#135425 (Do not consider traits that have unsatisfied const conditions to be conditionally const) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dd333ca + d0fb971 commit d5e900b

File tree

57 files changed

+985
-259
lines changed

Some content is hidden

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

57 files changed

+985
-259
lines changed

Diff for: compiler/rustc_abi/src/extern_abi/mod.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub enum ExternAbi {
4545
PtxKernel,
4646
Msp430Interrupt,
4747
X86Interrupt,
48+
/// An entry-point function called by the GPU's host
49+
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
50+
GpuKernel,
4851
EfiApi,
4952
AvrInterrupt,
5053
AvrNonBlockingInterrupt,
@@ -122,6 +125,7 @@ const AbiDatas: &[AbiData] = &[
122125
AbiData { abi: Abi::PtxKernel, name: "ptx-kernel" },
123126
AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt" },
124127
AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt" },
128+
AbiData { abi: Abi::GpuKernel, name: "gpu-kernel" },
125129
AbiData { abi: Abi::EfiApi, name: "efiapi" },
126130
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
127131
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
@@ -239,6 +243,10 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
239243
feature: sym::abi_x86_interrupt,
240244
explain: "x86-interrupt ABI is experimental and subject to change",
241245
}),
246+
"gpu-kernel" => Err(AbiDisabled::Unstable {
247+
feature: sym::abi_gpu_kernel,
248+
explain: "gpu-kernel ABI is experimental and subject to change",
249+
}),
242250
"avr-interrupt" | "avr-non-blocking-interrupt" => Err(AbiDisabled::Unstable {
243251
feature: sym::abi_avr_interrupt,
244252
explain: "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change",
@@ -293,20 +301,21 @@ impl Abi {
293301
PtxKernel => 19,
294302
Msp430Interrupt => 20,
295303
X86Interrupt => 21,
296-
EfiApi => 22,
297-
AvrInterrupt => 23,
298-
AvrNonBlockingInterrupt => 24,
299-
CCmseNonSecureCall => 25,
300-
CCmseNonSecureEntry => 26,
304+
GpuKernel => 22,
305+
EfiApi => 23,
306+
AvrInterrupt => 24,
307+
AvrNonBlockingInterrupt => 25,
308+
CCmseNonSecureCall => 26,
309+
CCmseNonSecureEntry => 27,
301310
// Cross-platform ABIs
302-
System { unwind: false } => 27,
303-
System { unwind: true } => 28,
304-
RustIntrinsic => 29,
305-
RustCall => 30,
306-
Unadjusted => 31,
307-
RustCold => 32,
308-
RiscvInterruptM => 33,
309-
RiscvInterruptS => 34,
311+
System { unwind: false } => 28,
312+
System { unwind: true } => 29,
313+
RustIntrinsic => 30,
314+
RustCall => 31,
315+
Unadjusted => 32,
316+
RustCold => 33,
317+
RiscvInterruptM => 34,
318+
RiscvInterruptS => 35,
310319
};
311320
debug_assert!(
312321
AbiDatas

Diff for: compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+48-19
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
55
use rustc_infer::infer::outlives::env::RegionBoundPairs;
66
use rustc_infer::infer::region_constraints::GenericKind;
77
use rustc_infer::infer::{InferCtxt, outlives};
8+
use rustc_infer::traits::ScrubbedTraitError;
89
use rustc_middle::mir::ConstraintCategory;
910
use rustc_middle::traits::ObligationCause;
1011
use rustc_middle::traits::query::OutlivesBound;
1112
use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
1213
use rustc_span::{ErrorGuaranteed, Span};
13-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
14-
use rustc_trait_selection::solve::deeply_normalize;
14+
use rustc_trait_selection::solve::NoSolution;
15+
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
1516
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1617
use tracing::{debug, instrument};
1718
use type_op::TypeOpOutput;
@@ -229,24 +230,14 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
229230
let mut constraints = vec![];
230231
let mut known_type_outlives_obligations = vec![];
231232
for bound in param_env.caller_bounds() {
232-
let Some(mut outlives) = bound.as_type_outlives_clause() else { continue };
233-
234-
// In the new solver, normalize the type-outlives obligation assumptions.
235-
if self.infcx.next_trait_solver() {
236-
match deeply_normalize(
237-
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), param_env),
233+
if let Some(outlives) = bound.as_type_outlives_clause() {
234+
self.normalize_and_push_type_outlives_obligation(
238235
outlives,
239-
) {
240-
Ok(normalized_outlives) => {
241-
outlives = normalized_outlives;
242-
}
243-
Err(e) => {
244-
self.infcx.err_ctxt().report_fulfillment_errors(e);
245-
}
246-
}
247-
}
248-
249-
known_type_outlives_obligations.push(outlives);
236+
span,
237+
&mut known_type_outlives_obligations,
238+
&mut constraints,
239+
);
240+
};
250241
}
251242

252243
let unnormalized_input_output_tys = self
@@ -356,6 +347,44 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
356347
}
357348
}
358349

350+
fn normalize_and_push_type_outlives_obligation(
351+
&self,
352+
mut outlives: ty::PolyTypeOutlivesPredicate<'tcx>,
353+
span: Span,
354+
known_type_outlives_obligations: &mut Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
355+
constraints: &mut Vec<&QueryRegionConstraints<'tcx>>,
356+
) {
357+
// In the new solver, normalize the type-outlives obligation assumptions.
358+
if self.infcx.next_trait_solver() {
359+
let Ok(TypeOpOutput {
360+
output: normalized_outlives,
361+
constraints: constraints_normalize,
362+
error_info: _,
363+
}) = CustomTypeOp::new(
364+
|ocx| {
365+
ocx.deeply_normalize(
366+
&ObligationCause::dummy_with_span(span),
367+
self.param_env,
368+
outlives,
369+
)
370+
.map_err(|_: Vec<ScrubbedTraitError<'tcx>>| NoSolution)
371+
},
372+
"normalize type outlives obligation",
373+
)
374+
.fully_perform(self.infcx, span)
375+
else {
376+
self.infcx.dcx().delayed_bug(format!("could not normalize {outlives:?}"));
377+
return;
378+
};
379+
outlives = normalized_outlives;
380+
if let Some(c) = constraints_normalize {
381+
constraints.push(c);
382+
}
383+
}
384+
385+
known_type_outlives_obligations.push(outlives);
386+
}
387+
359388
/// Update the type of a single local, which should represent
360389
/// either the return type of the MIR or one of its arguments. At
361390
/// the same time, compute and add any implied bounds that come

Diff for: compiler/rustc_codegen_cranelift/src/abi/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
6565
sess.dcx().fatal("C-cmse-nonsecure-entry call conv is not yet implemented");
6666
}
6767

68-
Conv::Msp430Intr | Conv::PtxKernel | Conv::AvrInterrupt | Conv::AvrNonBlockingInterrupt => {
68+
Conv::Msp430Intr
69+
| Conv::PtxKernel
70+
| Conv::GpuKernel
71+
| Conv::AvrInterrupt
72+
| Conv::AvrNonBlockingInterrupt => {
6973
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");
7074
}
7175
}

Diff for: compiler/rustc_codegen_llvm/src/abi.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Borrow;
12
use std::cmp;
23

34
use libc::c_uint;
@@ -312,7 +313,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
312313
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
313314
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
314315
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
315-
fn llvm_cconv(&self) -> llvm::CallConv;
316+
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv;
316317

317318
/// Apply attributes to a function declaration/definition.
318319
fn apply_attrs_llfn(
@@ -404,8 +405,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
404405
cx.type_ptr_ext(cx.data_layout().instruction_address_space)
405406
}
406407

407-
fn llvm_cconv(&self) -> llvm::CallConv {
408-
self.conv.into()
408+
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv {
409+
llvm::CallConv::from_conv(self.conv, cx.tcx.sess.target.arch.borrow())
409410
}
410411

411412
fn apply_attrs_llfn(
@@ -617,7 +618,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
617618
}
618619
}
619620

620-
let cconv = self.llvm_cconv();
621+
let cconv = self.llvm_cconv(&bx.cx);
621622
if cconv != llvm::CCallConv {
622623
llvm::SetInstructionCallConv(callsite, cconv);
623624
}
@@ -655,8 +656,8 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
655656
}
656657
}
657658

658-
impl From<Conv> for llvm::CallConv {
659-
fn from(conv: Conv) -> Self {
659+
impl llvm::CallConv {
660+
pub fn from_conv(conv: Conv, arch: &str) -> Self {
660661
match conv {
661662
Conv::C
662663
| Conv::Rust
@@ -666,6 +667,15 @@ impl From<Conv> for llvm::CallConv {
666667
Conv::Cold => llvm::ColdCallConv,
667668
Conv::PreserveMost => llvm::PreserveMost,
668669
Conv::PreserveAll => llvm::PreserveAll,
670+
Conv::GpuKernel => {
671+
if arch == "amdgpu" {
672+
llvm::AmdgpuKernel
673+
} else if arch == "nvptx64" {
674+
llvm::PtxKernel
675+
} else {
676+
panic!("Architecture {arch} does not support GpuKernel calling convention");
677+
}
678+
}
669679
Conv::AvrInterrupt => llvm::AvrInterrupt,
670680
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
671681
Conv::ArmAapcs => llvm::ArmAapcsCallConv,

Diff for: compiler/rustc_codegen_llvm/src/context.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,10 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
741741
if self.get_declared_value(entry_name).is_none() {
742742
Some(self.declare_entry_fn(
743743
entry_name,
744-
self.sess().target.entry_abi.into(),
744+
llvm::CallConv::from_conv(
745+
self.sess().target.entry_abi,
746+
self.sess().target.arch.borrow(),
747+
),
745748
llvm::UnnamedAddr::Global,
746749
fn_type,
747750
))

Diff for: compiler/rustc_codegen_llvm/src/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
125125
let llfn = declare_raw_fn(
126126
self,
127127
name,
128-
fn_abi.llvm_cconv(),
128+
fn_abi.llvm_cconv(self),
129129
llvm::UnnamedAddr::Global,
130130
llvm::Visibility::Default,
131131
fn_abi.llvm_type(self),

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub enum CallConv {
120120
X86_Intr = 83,
121121
AvrNonBlockingInterrupt = 84,
122122
AvrInterrupt = 85,
123+
AmdgpuKernel = 91,
123124
}
124125

125126
/// Must match the layout of `LLVMLinkage`.

Diff for: compiler/rustc_const_eval/src/check_consts/check.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ use crate::errors;
3535
type QualifResults<'mir, 'tcx, Q> =
3636
rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'mir, 'tcx, Q>>;
3737

38+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
39+
enum ConstConditionsHold {
40+
Yes,
41+
No,
42+
}
43+
3844
#[derive(Default)]
3945
pub(crate) struct Qualifs<'mir, 'tcx> {
4046
has_mut_interior: Option<QualifResults<'mir, 'tcx, HasMutInterior>>,
@@ -376,15 +382,15 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
376382
callee: DefId,
377383
callee_args: ty::GenericArgsRef<'tcx>,
378384
call_span: Span,
379-
) -> bool {
385+
) -> Option<ConstConditionsHold> {
380386
let tcx = self.tcx;
381387
if !tcx.is_conditionally_const(callee) {
382-
return false;
388+
return None;
383389
}
384390

385391
let const_conditions = tcx.const_conditions(callee).instantiate(tcx, callee_args);
386392
if const_conditions.is_empty() {
387-
return false;
393+
return None;
388394
}
389395

390396
let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(self.body.typing_env(tcx));
@@ -413,12 +419,13 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
413419
}));
414420

415421
let errors = ocx.select_all_or_error();
416-
if !errors.is_empty() {
422+
if errors.is_empty() {
423+
Some(ConstConditionsHold::Yes)
424+
} else {
417425
tcx.dcx()
418426
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
427+
Some(ConstConditionsHold::No)
419428
}
420-
421-
true
422429
}
423430

424431
pub fn check_drop_terminator(
@@ -706,7 +713,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
706713
trace!("attempting to call a trait method");
707714
let trait_is_const = tcx.is_const_trait(trait_did);
708715

709-
if trait_is_const {
716+
// Only consider a trait to be const if the const conditions hold.
717+
// Otherwise, it's really misleading to call something "conditionally"
718+
// const when it's very obviously not conditionally const.
719+
if trait_is_const && has_const_conditions == Some(ConstConditionsHold::Yes) {
710720
// Trait calls are always conditionally-const.
711721
self.check_op(ops::ConditionallyConstCall {
712722
callee,
@@ -730,7 +740,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
730740
}
731741

732742
// Even if we know the callee, ensure we can use conditionally-const calls.
733-
if has_const_conditions {
743+
if has_const_conditions.is_some() {
734744
self.check_op(ops::ConditionallyConstCall {
735745
callee,
736746
args: fn_args,

Diff for: compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ declare_features! (
361361
(unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
362362
/// Allows `extern "C-cmse-nonsecure-call" fn()`.
363363
(unstable, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391)),
364+
/// Allows `extern "gpu-kernel" fn()`.
365+
(unstable, abi_gpu_kernel, "CURRENT_RUSTC_VERSION", Some(135467)),
364366
/// Allows `extern "msp430-interrupt" fn()`.
365367
(unstable, abi_msp430_interrupt, "1.16.0", Some(38487)),
366368
/// Allows `extern "ptx-*" fn()`.

Diff for: compiler/rustc_hir_analysis/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ hir_analysis_dispatch_from_dyn_multi = implementing the `DispatchFromDyn` trait
135135
136136
hir_analysis_dispatch_from_dyn_repr = structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]`
137137
138-
hir_analysis_dispatch_from_dyn_zst = the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment, and nothing else
138+
hir_analysis_dispatch_from_dyn_zst = the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else
139139
.note = extra field `{$name}` of type `{$ty}` is not allowed
140140
141141
hir_analysis_drop_impl_negative = negative `Drop` impls are not supported

0 commit comments

Comments
 (0)