Skip to content

Commit 7714c6e

Browse files
committed
Auto merge of #154757 - matthiaskrgr:rollup-IMZZ0nA, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #153286 (various fixes for scalable vectors) - #153592 (Add `min_adt_const_params` gate) - #154051 (use libm for acosh and asinh for f16, f32, and f64) - #154743 (Remove an unused `StableHash` impl.) - #154752 (Add comment to borrow-checker)
2 parents 2972b5e + 6bbea3d commit 7714c6e

54 files changed

Lines changed: 1603 additions & 257 deletions

File tree

Some content is hidden

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

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_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;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::fmt::{self, Write};
33
use std::hash::{Hash, Hasher};
44
use std::path::PathBuf;
55
use std::sync::Arc;
6-
use std::{iter, ptr};
6+
use std::{assert_matches, iter, ptr};
77

88
use libc::{c_longlong, c_uint};
9-
use rustc_abi::{Align, Size};
9+
use rustc_abi::{Align, Layout, NumScalableVectors, Size};
1010
use rustc_codegen_ssa::debuginfo::type_names::{VTableNameKind, cpp_like_debuginfo};
1111
use rustc_codegen_ssa::traits::*;
1212
use rustc_hir::def::{CtorKind, DefKind};
@@ -16,12 +16,12 @@ use rustc_middle::ty::layout::{
1616
HasTypingEnv, LayoutOf, TyAndLayout, WIDE_PTR_ADDR, WIDE_PTR_EXTRA,
1717
};
1818
use rustc_middle::ty::{
19-
self, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Ty, TyCtxt, Visibility,
19+
self, AdtDef, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Ty, TyCtxt, Visibility,
2020
};
2121
use rustc_session::config::{self, DebugInfo, Lto};
2222
use rustc_span::{DUMMY_SP, FileName, RemapPathScopeComponents, SourceFile, Span, Symbol, hygiene};
2323
use rustc_symbol_mangling::typeid_for_trait_ref;
24-
use rustc_target::spec::DebuginfoKind;
24+
use rustc_target::spec::{Arch, DebuginfoKind};
2525
use smallvec::smallvec;
2626
use tracing::{debug, instrument};
2727

@@ -33,7 +33,7 @@ use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_na
3333
use super::utils::{DIB, debug_context, get_namespace_for_item, is_node_local_to_unit};
3434
use crate::common::{AsCCharPtr, CodegenCx};
3535
use crate::debuginfo::metadata::type_map::build_type_with_children;
36-
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
36+
use crate::debuginfo::utils::{WidePtrKind, create_DIArray, wide_pointer_kind};
3737
use crate::debuginfo::{DIBuilderExt, dwarf_const};
3838
use crate::llvm::debuginfo::{
3939
DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock,
@@ -1039,6 +1039,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10391039
span: Span,
10401040
) -> DINodeCreationResult<'ll> {
10411041
let struct_type = unique_type_id.expect_ty();
1042+
10421043
let ty::Adt(adt_def, _) = struct_type.kind() else {
10431044
bug!("build_struct_type_di_node() called with non-struct-type: {:?}", struct_type);
10441045
};
@@ -1051,14 +1052,29 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10511052
} else {
10521053
None
10531054
};
1055+
let name = compute_debuginfo_type_name(cx.tcx, struct_type, false);
1056+
1057+
if struct_type.is_scalable_vector() {
1058+
let parts = struct_type.scalable_vector_parts(cx.tcx).unwrap();
1059+
return build_scalable_vector_di_node(
1060+
cx,
1061+
unique_type_id,
1062+
name,
1063+
*adt_def,
1064+
parts,
1065+
struct_type_and_layout.layout,
1066+
def_location,
1067+
containing_scope,
1068+
);
1069+
}
10541070

10551071
type_map::build_type_with_children(
10561072
cx,
10571073
type_map::stub(
10581074
cx,
10591075
Stub::Struct,
10601076
unique_type_id,
1061-
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
1077+
&name,
10621078
def_location,
10631079
size_and_align_of(struct_type_and_layout),
10641080
Some(containing_scope),
@@ -1101,6 +1117,100 @@ fn build_struct_type_di_node<'ll, 'tcx>(
11011117
)
11021118
}
11031119

1120+
/// Generate debuginfo for a `#[rustc_scalable_vector]` type.
1121+
///
1122+
/// Debuginfo for a scalable vector uses a derived type based on a composite type. The composite
1123+
/// type has the `DIFlagVector` flag set and is based on the element type of the scalable vector.
1124+
/// The composite type has a subrange from 0 to an expression that calculates the number of
1125+
/// elements in the vector.
1126+
///
1127+
/// ```text,ignore
1128+
/// !1 = !DIDerivedType(tag: DW_TAG_typedef, name: "svint16_t", ..., baseType: !2, ...)
1129+
/// !2 = !DICompositeType(tag: DW_TAG_array_type, baseType: !3, ..., flags: DIFlagVector, elements: !4)
1130+
/// !3 = !DIBasicType(name: "i16", size: 16, encoding: DW_ATE_signed)
1131+
/// !4 = !{!5}
1132+
/// !5 = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_constu, 4, DW_OP_bregx, 46, 0, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
1133+
/// ```
1134+
///
1135+
/// See the `CodegenType::CreateType(const BuiltinType *BT)` implementation in Clang for how this
1136+
/// is generated for C and C++.
1137+
fn build_scalable_vector_di_node<'ll, 'tcx>(
1138+
cx: &CodegenCx<'ll, 'tcx>,
1139+
unique_type_id: UniqueTypeId<'tcx>,
1140+
name: String,
1141+
adt_def: AdtDef<'tcx>,
1142+
(element_count, element_ty, number_of_vectors): (u16, Ty<'tcx>, NumScalableVectors),
1143+
layout: Layout<'tcx>,
1144+
def_location: Option<DefinitionLocation<'ll>>,
1145+
containing_scope: &'ll DIScope,
1146+
) -> DINodeCreationResult<'ll> {
1147+
use dwarf_const::{DW_OP_bregx, DW_OP_constu, DW_OP_minus, DW_OP_mul};
1148+
assert!(adt_def.repr().scalable());
1149+
// This logic is specific to AArch64 for the moment, but can be extended for other architectures
1150+
// later.
1151+
assert_matches!(cx.tcx.sess.target.arch, Arch::AArch64);
1152+
1153+
let (file_metadata, line_number) = if let Some(def_location) = def_location {
1154+
(def_location.0, def_location.1)
1155+
} else {
1156+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
1157+
};
1158+
1159+
let (bitstride, element_di_node) = if element_ty.is_bool() {
1160+
(Some(llvm::LLVMValueAsMetadata(cx.const_i64(1))), type_di_node(cx, cx.tcx.types.u8))
1161+
} else {
1162+
(None, type_di_node(cx, element_ty))
1163+
};
1164+
1165+
let number_of_elements: u64 = (element_count as u64) * (number_of_vectors.0 as u64);
1166+
let number_of_elements_per_vg = number_of_elements / 2;
1167+
let mut expr = smallvec::SmallVec::<[u64; 9]>::new();
1168+
// `($number_of_elements_per_vector_granule * (value_of_register(AArch64::VG) + 0)) - 1`
1169+
expr.push(DW_OP_constu); // Push a constant onto the stack
1170+
expr.push(number_of_elements_per_vg);
1171+
expr.push(DW_OP_bregx); // Push the value of a register + offset on to the stack
1172+
expr.push(/* AArch64::VG */ 46u64);
1173+
expr.push(0u64);
1174+
expr.push(DW_OP_mul); // Multiply top two values on stack
1175+
expr.push(DW_OP_constu); // Push a constant onto the stack
1176+
expr.push(1u64);
1177+
expr.push(DW_OP_minus); // Subtract top two values on stack
1178+
1179+
let di_builder = DIB(cx);
1180+
let metadata = unsafe {
1181+
let upper = llvm::LLVMDIBuilderCreateExpression(di_builder, expr.as_ptr(), expr.len());
1182+
let subrange = llvm::LLVMRustDIGetOrCreateSubrange(
1183+
di_builder,
1184+
/* CountNode */ None,
1185+
llvm::LLVMValueAsMetadata(cx.const_i64(0)),
1186+
upper,
1187+
/* Stride */ None,
1188+
);
1189+
let subscripts = create_DIArray(di_builder, &[Some(subrange)]);
1190+
let vector_ty = llvm::LLVMRustDICreateVectorType(
1191+
di_builder,
1192+
/* Size */ 0,
1193+
layout.align.bits() as u32,
1194+
element_di_node,
1195+
subscripts,
1196+
bitstride,
1197+
);
1198+
llvm::LLVMDIBuilderCreateTypedef(
1199+
di_builder,
1200+
vector_ty,
1201+
name.as_ptr(),
1202+
name.len(),
1203+
file_metadata,
1204+
line_number,
1205+
Some(containing_scope),
1206+
layout.align.bits() as u32,
1207+
)
1208+
};
1209+
1210+
debug_context(cx).type_map.insert(unique_type_id, metadata);
1211+
DINodeCreationResult { di_node: metadata, already_stored_in_typemap: true }
1212+
}
1213+
11041214
//=-----------------------------------------------------------------------------
11051215
// Tuples
11061216
//=-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)