Skip to content

Commit ace45f7

Browse files
committed
rustup: update to nightly-2024-10-12 (~1.83).
1 parent 412ecba commit ace45f7

24 files changed

+199
-70
lines changed

crates/rustc_codegen_spirv/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use std::{env, fs, mem};
1515
/// `cargo publish`. We need to figure out a way to do this properly, but let's hardcode it for now :/
1616
//const REQUIRED_RUST_TOOLCHAIN: &str = include_str!("../../rust-toolchain.toml");
1717
const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain]
18-
channel = "nightly-2024-09-01"
18+
channel = "nightly-2024-10-12"
1919
components = ["rust-src", "rustc-dev", "llvm-tools"]
20-
# commit_hash = a7399ba69d37b019677a9c47fe89ceb8dd82db2d"#;
20+
# commit_hash = 1bc403daadbebb553ccc211a0a8eebb73989665f"#;
2121

2222
fn rustc_output(arg: &str) -> Result<String, Box<dyn Error>> {
2323
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
@@ -194,6 +194,9 @@ mod win {",
194194
);
195195
} else if relative_path == Path::new("src/mir/operand.rs") {
196196
src = src.replace("alloca(field.size,", "typed_alloca(llfield_ty,");
197+
198+
// HACK(eddyb) non-array `#[repr(simd)]` workaround (see `src/abi.rs`).
199+
src = src.replace("if constant_ty.is_simd() {", "if false {");
197200
}
198201

199202
fs::write(out_path, src)?;

crates/rustc_codegen_spirv/src/abi.rs

+89-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
55
use crate::codegen_cx::CodegenCx;
66
use crate::spirv_type::SpirvType;
7+
use itertools::Itertools;
78
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
89
use rustc_data_structures::fx::FxHashMap;
910
use rustc_errors::ErrorGuaranteed;
@@ -22,7 +23,8 @@ use rustc_span::def_id::DefId;
2223
use rustc_span::{Span, Symbol};
2324
use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode};
2425
use rustc_target::abi::{
25-
Abi, Align, FieldsShape, LayoutS, Primitive, Scalar, Size, TagEncoding, VariantIdx, Variants,
26+
Abi, Align, FieldsShape, LayoutS, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding,
27+
VariantIdx, Variants,
2628
};
2729
use rustc_target::spec::abi::Abi as SpecAbi;
2830
use std::cell::RefCell;
@@ -157,6 +159,7 @@ pub(crate) fn provide(providers: &mut Providers) {
157159
unadjusted_abi_align,
158160
}
159161
}
162+
160163
providers.layout_of = |tcx, key| {
161164
let TyAndLayout { ty, mut layout } =
162165
(rustc_interface::DEFAULT_QUERY_PROVIDERS.layout_of)(tcx, key)?;
@@ -176,6 +179,90 @@ pub(crate) fn provide(providers: &mut Providers) {
176179

177180
Ok(TyAndLayout { ty, layout })
178181
};
182+
183+
// HACK(eddyb) work around https://github.com/rust-lang/rust/pull/129403
184+
// banning "struct-style" `#[repr(simd)]` (in favor of "array-newtype-style"),
185+
// by simply bypassing "type definition WF checks" for affected types, which:
186+
// - can only really be sound for types with trivial field types, that are
187+
// either completely non-generic (covering most `#[repr(simd)]` `struct`s),
188+
// or *at most* one generic type parameter with no bounds/where clause
189+
// - relies on upstream `layout_of` not having had the non-array logic removed
190+
//
191+
// FIXME(eddyb) remove this once migrating beyond `#[repr(simd)]` becomes
192+
// an option (may require Rust-GPU distinguishing between "SPIR-V interface"
193+
// and "Rust-facing" types, which is even worse when the `OpTypeVector`s
194+
// may be e.g. nested in `struct`s/arrays/etc. - at least buffers are easy).
195+
providers.check_well_formed = |tcx, def_id| {
196+
let trivial_struct = match tcx.hir_node_by_def_id(def_id) {
197+
rustc_hir::Node::Item(item) => match item.kind {
198+
rustc_hir::ItemKind::Struct(
199+
_,
200+
&rustc_hir::Generics {
201+
params:
202+
&[]
203+
| &[
204+
rustc_hir::GenericParam {
205+
kind:
206+
rustc_hir::GenericParamKind::Type {
207+
default: None,
208+
synthetic: false,
209+
},
210+
..
211+
},
212+
],
213+
predicates: &[],
214+
has_where_clause_predicates: false,
215+
where_clause_span: _,
216+
span: _,
217+
},
218+
) => Some(tcx.adt_def(def_id)),
219+
_ => None,
220+
},
221+
_ => None,
222+
};
223+
let valid_non_array_simd_struct = trivial_struct.is_some_and(|adt_def| {
224+
let ReprOptions {
225+
int: None,
226+
align: None,
227+
pack: None,
228+
flags: ReprFlags::IS_SIMD,
229+
field_shuffle_seed: _,
230+
} = adt_def.repr()
231+
else {
232+
return false;
233+
};
234+
if adt_def.destructor(tcx).is_some() {
235+
return false;
236+
}
237+
238+
let field_types = adt_def
239+
.non_enum_variant()
240+
.fields
241+
.iter()
242+
.map(|f| tcx.type_of(f.did).instantiate_identity());
243+
field_types.dedup().exactly_one().is_ok_and(|elem_ty| {
244+
matches!(
245+
elem_ty.kind(),
246+
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Param(_)
247+
)
248+
})
249+
});
250+
251+
if valid_non_array_simd_struct {
252+
tcx.dcx()
253+
.struct_span_warn(
254+
tcx.def_span(def_id),
255+
"[Rust-GPU] temporarily re-allowing old-style `#[repr(simd)]` (with fields)",
256+
)
257+
.with_note("removed upstream by https://github.com/rust-lang/rust/pull/129403")
258+
.with_note("in favor of the new `#[repr(simd)] struct TxN([T; N]);` style")
259+
.with_note("(taking effect since `nightly-2024-09-12` / `1.83.0` stable)")
260+
.emit();
261+
return Ok(());
262+
}
263+
264+
(rustc_interface::DEFAULT_QUERY_PROVIDERS.check_well_formed)(tcx, def_id)
265+
};
179266
}
180267

181268
/// If a struct contains a pointer to itself, even indirectly, then doing a naiive recursive walk
@@ -458,7 +545,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
458545
}
459546
}
460547

461-
/// Only pub for `LayoutTypeMethods::scalar_pair_element_backend_type`. Think about what you're
548+
/// Only pub for `LayoutTypeCodegenMethods::scalar_pair_element_backend_type`. Think about what you're
462549
/// doing before calling this.
463550
pub fn scalar_pair_element_backend_type<'tcx>(
464551
cx: &CodegenCx<'tcx>,

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
44
use super::Builder;
55
use crate::abi::ConvSpirvType;
66
use crate::builder_spirv::{BuilderCursor, SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
7+
use crate::codegen_cx::CodegenCx;
78
use crate::custom_insts::{CustomInst, CustomOp};
89
use crate::spirv_type::SpirvType;
910
use itertools::Itertools;
@@ -16,9 +17,9 @@ use rustc_codegen_ssa::common::{
1617
};
1718
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1819
use rustc_codegen_ssa::mir::place::PlaceRef;
19-
use rustc_codegen_ssa::traits::BaseTypeMethods;
2020
use rustc_codegen_ssa::traits::{
21-
BackendTypes, BuilderMethods, ConstMethods, LayoutTypeMethods, OverflowOp,
21+
BackendTypes, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
22+
LayoutTypeCodegenMethods, OverflowOp,
2223
};
2324
use rustc_data_structures::fx::FxHashSet;
2425
use rustc_middle::bug;
@@ -958,6 +959,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
958959
}
959960

960961
impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
962+
type CodegenCx = CodegenCx<'tcx>;
963+
961964
fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self {
962965
let cursor = cx.builder.select_block_by_id(llbb);
963966
// FIXME(eddyb) change `Self::Function` to be more like a function index.

crates/rustc_codegen_spirv/src/builder/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rspirv::dr::Operand;
1111
use rspirv::spirv::GLOp;
1212
use rustc_codegen_ssa::mir::operand::OperandRef;
1313
use rustc_codegen_ssa::mir::place::PlaceRef;
14-
use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallMethods};
14+
use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallBuilderMethods};
1515
use rustc_middle::ty::layout::LayoutOf;
1616
use rustc_middle::ty::{FnDef, Instance, ParamEnv, Ty, TyKind};
1717
use rustc_middle::{bug, ty};
@@ -66,7 +66,7 @@ impl Builder<'_, '_> {
6666
}
6767
}
6868

69-
impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
69+
impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
7070
fn codegen_intrinsic_call(
7171
&mut self,
7272
instance: Instance<'tcx>,
@@ -360,15 +360,15 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
360360
cond
361361
}
362362

363-
fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Value) -> Self::Value {
363+
fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Metadata) -> Self::Value {
364364
todo!()
365365
}
366366

367367
fn type_checked_load(
368368
&mut self,
369369
_llvtable: Self::Value,
370370
_vtable_byte_offset: u64,
371-
_typeid: Self::Value,
371+
_typeid: Self::Metadata,
372372
) -> Self::Value {
373373
todo!()
374374
}

crates/rustc_codegen_spirv/src/builder/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use rspirv::spirv::Word;
2020
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
2121
use rustc_codegen_ssa::mir::place::PlaceRef;
2222
use rustc_codegen_ssa::traits::{
23-
AbiBuilderMethods, ArgAbiMethods, BackendTypes, BuilderMethods, CoverageInfoBuilderMethods,
24-
DebugInfoBuilderMethods, HasCodegen, StaticBuilderMethods, TypeMembershipMethods,
23+
AbiBuilderMethods, ArgAbiBuilderMethods, BackendTypes, BuilderMethods,
24+
CoverageInfoBuilderMethods, DebugInfoBuilderMethods, StaticBuilderMethods,
25+
TypeMembershipCodegenMethods,
2526
};
2627
use rustc_errors::{Diag, DiagMessage};
2728
use rustc_middle::mir::coverage::CoverageKind;
@@ -170,6 +171,10 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {
170171
todo!()
171172
}
172173

174+
fn clear_dbg_loc(&mut self) {
175+
todo!()
176+
}
177+
173178
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
174179
todo!()
175180
}
@@ -179,7 +184,7 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> {
179184
}
180185
}
181186

182-
impl<'a, 'tcx> ArgAbiMethods<'tcx> for Builder<'a, 'tcx> {
187+
impl<'a, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'a, 'tcx> {
183188
fn store_fn_arg(
184189
&mut self,
185190
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
@@ -247,7 +252,9 @@ impl<'a, 'tcx> StaticBuilderMethods for Builder<'a, 'tcx> {
247252

248253
impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> {
249254
type Value = <CodegenCx<'tcx> as BackendTypes>::Value;
255+
type Metadata = <CodegenCx<'tcx> as BackendTypes>::Metadata;
250256
type Function = <CodegenCx<'tcx> as BackendTypes>::Function;
257+
251258
type BasicBlock = <CodegenCx<'tcx> as BackendTypes>::BasicBlock;
252259
type Type = <CodegenCx<'tcx> as BackendTypes>::Type;
253260
type Funclet = <CodegenCx<'tcx> as BackendTypes>::Funclet;
@@ -257,10 +264,6 @@ impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> {
257264
type DILocation = <CodegenCx<'tcx> as BackendTypes>::DILocation;
258265
}
259266

260-
impl<'a, 'tcx> HasCodegen<'tcx> for Builder<'a, 'tcx> {
261-
type CodegenCx = CodegenCx<'tcx>;
262-
}
263-
264267
impl<'a, 'tcx> HasParamEnv<'tcx> for Builder<'a, 'tcx> {
265268
fn param_env(&self) -> ParamEnv<'tcx> {
266269
self.cx.param_env()
@@ -308,4 +311,4 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, 'tcx> {
308311
}
309312
}
310313

311-
impl<'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'tcx> {}
314+
impl<'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'tcx> {}

crates/rustc_codegen_spirv/src/builder_spirv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rspirv::spirv::{
1313
};
1414
use rspirv::{binary::Assemble, binary::Disassemble};
1515
use rustc_arena::DroplessArena;
16-
use rustc_codegen_ssa::traits::ConstMethods as _;
16+
use rustc_codegen_ssa::traits::ConstCodegenMethods as _;
1717
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818
use rustc_data_structures::sync::Lrc;
1919
use rustc_middle::bug;

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::abi::ConvSpirvType;
66
use crate::builder_spirv::{SpirvConst, SpirvValue, SpirvValueExt, SpirvValueKind};
77
use crate::spirv_type::SpirvType;
88
use rspirv::spirv::Word;
9-
use rustc_codegen_ssa::traits::{ConstMethods, MiscMethods, StaticMethods};
9+
use rustc_codegen_ssa::traits::{ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods};
1010
use rustc_middle::bug;
1111
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar, alloc_range};
1212
use rustc_middle::ty::layout::LayoutOf;
@@ -105,7 +105,7 @@ impl<'tcx> CodegenCx<'tcx> {
105105
}
106106
}
107107

108-
impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
108+
impl<'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'tcx> {
109109
fn const_null(&self, t: Self::Type) -> Self::Value {
110110
self.constant_null(t)
111111
}
@@ -253,10 +253,10 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
253253
self.get_fn_addr(instance.polymorphize(self.tcx)),
254254
self.data_layout().instruction_address_space,
255255
),
256-
GlobalAlloc::VTable(vty, trait_ref) => {
256+
GlobalAlloc::VTable(vty, dyn_ty) => {
257257
let alloc = self
258258
.tcx
259-
.global_alloc(self.tcx.vtable_allocation((vty, trait_ref)))
259+
.global_alloc(self.tcx.vtable_allocation((vty, dyn_ty.principal())))
260260
.unwrap_memory();
261261
let pointee = match self.lookup_type(ty) {
262262
SpirvType::Pointer { pointee } => pointee,

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::spirv_type::SpirvType;
1010
use itertools::Itertools;
1111
use rspirv::spirv::{FunctionControl, LinkageType, StorageClass, Word};
1212
use rustc_attr::InlineAttr;
13-
use rustc_codegen_ssa::traits::{PreDefineMethods, StaticMethods};
13+
use rustc_codegen_ssa::traits::{PreDefineCodegenMethods, StaticCodegenMethods};
1414
use rustc_hir::def::DefKind;
1515
use rustc_middle::bug;
1616
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
@@ -58,9 +58,9 @@ impl<'tcx> CodegenCx<'tcx> {
5858
}
5959

6060
// The call graph of how this is reachable is a little tangled, so:
61-
// MiscMethods::get_fn -> get_fn_ext -> declare_fn_ext
62-
// MiscMethods::get_fn_addr -> get_fn_ext -> declare_fn_ext
63-
// PreDefineMethods::predefine_fn -> declare_fn_ext
61+
// MiscCodegenMethods::get_fn -> get_fn_ext -> declare_fn_ext
62+
// MiscCodegenMethods::get_fn_addr -> get_fn_ext -> declare_fn_ext
63+
// PreDefineCodegenMethods::predefine_fn -> declare_fn_ext
6464
fn declare_fn_ext(&self, instance: Instance<'tcx>, linkage: Option<LinkageType>) -> SpirvValue {
6565
let def_id = instance.def_id();
6666

@@ -280,7 +280,7 @@ impl<'tcx> CodegenCx<'tcx> {
280280
}
281281
}
282282

283-
impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> {
283+
impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'tcx> {
284284
fn predefine_static(
285285
&self,
286286
def_id: DefId,
@@ -337,7 +337,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> {
337337
}
338338
}
339339

340-
impl<'tcx> StaticMethods for CodegenCx<'tcx> {
340+
impl<'tcx> StaticCodegenMethods for CodegenCx<'tcx> {
341341
fn static_addr_of(&self, cv: Self::Value, _align: Align, _kind: Option<&str>) -> Self::Value {
342342
self.def_constant(self.type_ptr_to(cv.ty), SpirvConst::PtrTo {
343343
pointee: cv.def_cx(self),

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rspirv::dr::Operand;
1111
use rspirv::spirv::{
1212
Capability, Decoration, Dim, ExecutionModel, FunctionControl, StorageClass, Word,
1313
};
14-
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
14+
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_errors::MultiSpan;
1717
use rustc_hir as hir;

0 commit comments

Comments
 (0)