Skip to content

Commit 981cf69

Browse files
committed
Auto merge of #154773 - matthiaskrgr:rollup-DMnqd9w, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #153286 (various fixes for scalable vectors) - #153592 (Add `min_adt_const_params` gate) - #154675 (Improve shadowed private field diagnostics) - #154653 (Remove rustc_on_unimplemented's append_const_msg) - #154743 (Remove an unused `StableHash` impl.) - #154752 (Add comment to borrow-checker) - #154764 (Add tests for three ICEs that have already been fixed)
2 parents 2972b5e + 7a68d3f commit 981cf69

File tree

64 files changed

+2401
-324
lines changed

Some content is hidden

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

64 files changed

+2401
-324
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use tracing::{debug, trace};
1010

1111
use crate::{
1212
AbiAlign, Align, BackendRepr, FieldsShape, HasDataLayout, IndexSlice, IndexVec, Integer,
13-
LayoutData, Niche, NonZeroUsize, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding,
14-
TargetDataLayout, Variants, WrappingRange,
13+
LayoutData, Niche, NonZeroUsize, NumScalableVectors, Primitive, ReprOptions, Scalar, Size,
14+
StructKind, TagEncoding, TargetDataLayout, Variants, WrappingRange,
1515
};
1616

1717
mod coroutine;
@@ -204,13 +204,19 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
204204
&self,
205205
element: F,
206206
count: u64,
207+
number_of_vectors: NumScalableVectors,
207208
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F>
208209
where
209210
FieldIdx: Idx,
210211
VariantIdx: Idx,
211212
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
212213
{
213-
vector_type_layout(SimdVectorKind::Scalable, self.cx.data_layout(), element, count)
214+
vector_type_layout(
215+
SimdVectorKind::Scalable(number_of_vectors),
216+
self.cx.data_layout(),
217+
element,
218+
count,
219+
)
214220
}
215221

216222
pub fn simd_type<FieldIdx, VariantIdx, F>(
@@ -1526,7 +1532,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
15261532

15271533
enum SimdVectorKind {
15281534
/// `#[rustc_scalable_vector]`
1529-
Scalable,
1535+
Scalable(NumScalableVectors),
15301536
/// `#[repr(simd, packed)]`
15311537
PackedFixed,
15321538
/// `#[repr(simd)]`
@@ -1559,9 +1565,10 @@ where
15591565
let size =
15601566
elt.size.checked_mul(count, dl).ok_or_else(|| LayoutCalculatorError::SizeOverflow)?;
15611567
let (repr, align) = match kind {
1562-
SimdVectorKind::Scalable => {
1563-
(BackendRepr::SimdScalableVector { element, count }, dl.llvmlike_vector_align(size))
1564-
}
1568+
SimdVectorKind::Scalable(number_of_vectors) => (
1569+
BackendRepr::SimdScalableVector { element, count, number_of_vectors },
1570+
dl.llvmlike_vector_align(size),
1571+
),
15651572
// Non-power-of-two vectors have padding up to the next power-of-two.
15661573
// If we're a packed repr, remove the padding while keeping the alignment as close
15671574
// to a vector as possible.

compiler/rustc_abi/src/lib.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,28 @@ impl AddressSpace {
16961696
pub const ZERO: Self = AddressSpace(0);
16971697
}
16981698

1699+
/// How many scalable vectors are in a `BackendRepr::ScalableVector`?
1700+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1701+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1702+
pub struct NumScalableVectors(pub u8);
1703+
1704+
impl NumScalableVectors {
1705+
/// Returns a `NumScalableVector` for a non-tuple scalable vector (e.g. a single vector).
1706+
pub fn for_non_tuple() -> Self {
1707+
NumScalableVectors(1)
1708+
}
1709+
1710+
// Returns `NumScalableVectors` for values of two through eight, which are a valid number of
1711+
// fields for a tuple of scalable vectors to have. `1` is a valid value of `NumScalableVectors`
1712+
// but not for a tuple which would have a field count.
1713+
pub fn from_field_count(count: usize) -> Option<Self> {
1714+
match count {
1715+
2..8 => Some(NumScalableVectors(count as u8)),
1716+
_ => None,
1717+
}
1718+
}
1719+
}
1720+
16991721
/// The way we represent values to the backend
17001722
///
17011723
/// Previously this was conflated with the "ABI" a type is given, as in the platform-specific ABI.
@@ -1714,6 +1736,7 @@ pub enum BackendRepr {
17141736
SimdScalableVector {
17151737
element: Scalar,
17161738
count: u64,
1739+
number_of_vectors: NumScalableVectors,
17171740
},
17181741
SimdVector {
17191742
element: Scalar,
@@ -1820,8 +1843,12 @@ impl BackendRepr {
18201843
BackendRepr::SimdVector { element: element.to_union(), count }
18211844
}
18221845
BackendRepr::Memory { .. } => BackendRepr::Memory { sized: true },
1823-
BackendRepr::SimdScalableVector { element, count } => {
1824-
BackendRepr::SimdScalableVector { element: element.to_union(), count }
1846+
BackendRepr::SimdScalableVector { element, count, number_of_vectors } => {
1847+
BackendRepr::SimdScalableVector {
1848+
element: element.to_union(),
1849+
count,
1850+
number_of_vectors,
1851+
}
18251852
}
18261853
}
18271854
}
@@ -2161,7 +2188,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
21612188
}
21622189

21632190
/// Returns `true` if the size of the type is only known at runtime.
2164-
pub fn is_runtime_sized(&self) -> bool {
2191+
pub fn is_scalable_vector(&self) -> bool {
21652192
matches!(self.backend_repr, BackendRepr::SimdScalableVector { .. })
21662193
}
21672194

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::ops::Range;
33
use rustc_errors::E0232;
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
6-
AppendConstMessage, Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg,
7-
Name, NameValue, OnUnimplementedCondition, Piece, Predicate,
6+
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
7+
OnUnimplementedCondition, Piece, Predicate,
88
};
99
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
1010
use rustc_macros::Diagnostic;
@@ -92,7 +92,6 @@ fn parse_directive_items<'p, S: Stage>(
9292
let mut notes = ThinVec::new();
9393
let mut parent_label = None;
9494
let mut subcommands = ThinVec::new();
95-
let mut append_const_msg = None;
9695

9796
for item in items {
9897
let span = item.span();
@@ -131,7 +130,6 @@ fn parse_directive_items<'p, S: Stage>(
131130
let Some(ret) = (||{
132131
Some($($code)*)
133132
})() else {
134-
135133
malformed!()
136134
};
137135
ret
@@ -159,8 +157,13 @@ fn parse_directive_items<'p, S: Stage>(
159157
let item: &MetaItemParser = or_malformed!(item.meta_item()?);
160158
let name = or_malformed!(item.ident()?).name;
161159

162-
// Some things like `message = "message"` must have a value.
163-
// But with things like `append_const_msg` that is optional.
160+
// Currently, as of April 2026, all arguments of all diagnostic attrs
161+
// must have a value, like `message = "message"`. Thus in a well-formed
162+
// diagnostic attribute this is never `None`.
163+
//
164+
// But we don't assert its presence yet because we don't want to mention it
165+
// if someone does something like `#[diagnostic::on_unimplemented(doesnt_exist)]`.
166+
// That happens in the big `match` below.
164167
let value: Option<Ident> = match item.args().name_value() {
165168
Some(nv) => Some(or_malformed!(nv.value_as_ident()?)),
166169
None => None,
@@ -223,14 +226,6 @@ fn parse_directive_items<'p, S: Stage>(
223226
let value = or_malformed!(value?);
224227
notes.push(parse_format(value))
225228
}
226-
227-
(Mode::RustcOnUnimplemented, sym::append_const_msg) => {
228-
append_const_msg = if let Some(msg) = value {
229-
Some(AppendConstMessage::Custom(msg.name, item.span()))
230-
} else {
231-
Some(AppendConstMessage::Default)
232-
}
233-
}
234229
(Mode::RustcOnUnimplemented, sym::parent_label) => {
235230
let value = or_malformed!(value?);
236231
if parent_label.is_none() {
@@ -290,7 +285,6 @@ fn parse_directive_items<'p, S: Stage>(
290285
label,
291286
notes,
292287
parent_label,
293-
append_const_msg,
294288
})
295289
}
296290

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
447447
let tcx = self.infcx.tcx;
448448

449449
for proj in &user_ty.projs {
450+
// Necessary for non-trivial patterns whose user-type annotation is an opaque type,
451+
// e.g. `let (_a,): Tait = whatever`, see #105897
450452
if !self.infcx.next_trait_solver()
451453
&& let ty::Alias(ty::Opaque, ..) = curr_projected_ty.ty.kind()
452454
{

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use rustc_data_structures::fx::FxHashSet;
2424
use rustc_middle::bug;
2525
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2626
use rustc_middle::ty::layout::{
27-
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
27+
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
28+
LayoutOfHelpers, TyAndLayout,
2829
};
2930
use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
3031
use rustc_span::Span;
@@ -943,8 +944,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
943944
.get_address(self.location)
944945
}
945946

946-
fn scalable_alloca(&mut self, _elt: u64, _align: Align, _element_ty: Ty<'_>) -> RValue<'gcc> {
947-
todo!()
947+
fn alloca_with_ty(&mut self, ty: TyAndLayout<'tcx>) -> RValue<'gcc> {
948+
self.alloca(ty.layout.size, ty.layout.align.abi)
948949
}
949950

950951
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
145145
self.const_int(self.type_i32(), i as i64)
146146
}
147147

148+
fn const_i64(&self, i: i64) -> RValue<'gcc> {
149+
self.const_int(self.type_i64(), i)
150+
}
151+
148152
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
149153
self.gcc_int(typ, int)
150154
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ pub(crate) mod autodiff;
77
pub(crate) mod gpu_offload;
88

99
use libc::{c_char, c_uint};
10-
use rustc_abi as abi;
11-
use rustc_abi::{Align, Size, WrappingRange};
10+
use rustc_abi::{self as abi, Align, Size, WrappingRange};
1211
use rustc_codegen_ssa::MemFlags;
1312
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
1413
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
@@ -616,21 +615,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
616615
}
617616
}
618617

619-
fn scalable_alloca(&mut self, elt: u64, align: Align, element_ty: Ty<'_>) -> Self::Value {
618+
fn alloca_with_ty(&mut self, layout: TyAndLayout<'tcx>) -> Self::Value {
620619
let mut bx = Builder::with_cx(self.cx);
621620
bx.position_at_start(unsafe { llvm::LLVMGetFirstBasicBlock(self.llfn()) });
622-
let llvm_ty = match element_ty.kind() {
623-
ty::Bool => bx.type_i1(),
624-
ty::Int(int_ty) => self.cx.type_int_from_ty(*int_ty),
625-
ty::Uint(uint_ty) => self.cx.type_uint_from_ty(*uint_ty),
626-
ty::Float(float_ty) => self.cx.type_float_from_ty(*float_ty),
627-
_ => unreachable!("scalable vectors can only contain a bool, int, uint or float"),
628-
};
621+
let scalable_vector_ty = layout.llvm_type(self.cx);
629622

630623
unsafe {
631-
let ty = llvm::LLVMScalableVectorType(llvm_ty, elt.try_into().unwrap());
632-
let alloca = llvm::LLVMBuildAlloca(&bx.llbuilder, ty, UNNAMED);
633-
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
624+
let alloca = llvm::LLVMBuildAlloca(&bx.llbuilder, scalable_vector_ty, UNNAMED);
625+
llvm::LLVMSetAlignment(alloca, layout.align.abi.bytes() as c_uint);
634626
alloca
635627
}
636628
}

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
159159
self.const_int(self.type_i32(), i as i64)
160160
}
161161

162+
fn const_i64(&self, i: i64) -> &'ll Value {
163+
self.const_int(self.type_i64(), i as i64)
164+
}
165+
162166
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
163167
debug_assert!(
164168
self.type_kind(t) == TypeKind::Integer,

compiler/rustc_codegen_llvm/src/debuginfo/dwarf_const.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ declare_constant!(DW_OP_plus_uconst: u64);
3535
/// Double-checked by a static assertion in `RustWrapper.cpp`.
3636
#[allow(non_upper_case_globals)]
3737
pub(crate) const DW_OP_LLVM_fragment: u64 = 0x1000;
38+
#[allow(non_upper_case_globals)]
39+
pub(crate) const DW_OP_constu: u64 = 0x10;
40+
#[allow(non_upper_case_globals)]
41+
pub(crate) const DW_OP_minus: u64 = 0x1c;
42+
#[allow(non_upper_case_globals)]
43+
pub(crate) const DW_OP_mul: u64 = 0x1e;
44+
#[allow(non_upper_case_globals)]
45+
pub(crate) const DW_OP_bregx: u64 = 0x92;
3846
// It describes the actual value of a source variable which might not exist in registers or in memory.
3947
#[allow(non_upper_case_globals)]
4048
pub(crate) const DW_OP_stack_value: u64 = 0x9f;

0 commit comments

Comments
 (0)