From 4c256b6b12ecae1937f20dd9c7529c9739ed8ee6 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 3 Dec 2024 17:55:18 +0200 Subject: [PATCH] rustup: update to `nightly-2024-11-22` (~1.84). --- crates/rustc_codegen_spirv/build.rs | 4 +- crates/rustc_codegen_spirv/src/abi.rs | 105 +++++++++--------- .../src/builder/builder_methods.rs | 18 +-- .../src/builder/intrinsics.rs | 6 +- crates/rustc_codegen_spirv/src/builder/mod.rs | 16 ++- .../src/codegen_cx/declare.rs | 6 +- .../src/codegen_cx/entry.rs | 2 +- .../rustc_codegen_spirv/src/codegen_cx/mod.rs | 28 ++--- .../src/codegen_cx/type_.rs | 19 ++-- crates/rustc_codegen_spirv/src/lib.rs | 6 +- crates/rustc_codegen_spirv/src/linker/dce.rs | 2 +- .../rustc_codegen_spirv/src/linker/inline.rs | 8 +- .../src/linker/peephole_opts.rs | 13 +-- crates/rustc_codegen_spirv/src/target.rs | 2 +- crates/spirv-builder/src/lib.rs | 6 +- rust-toolchain.toml | 4 +- tests/src/main.rs | 2 +- tests/ui/dis/issue-1062.stderr | 2 +- tests/ui/dis/ptr_copy.normal.stderr | 36 +++--- tests/ui/dis/ptr_read.stderr | 2 +- tests/ui/dis/ptr_read_method.stderr | 2 +- tests/ui/dis/ptr_write.stderr | 2 +- tests/ui/dis/ptr_write_method.stderr | 2 +- tests/ui/lang/core/unwrap_or.stderr | 4 +- 24 files changed, 145 insertions(+), 152 deletions(-) diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index 2ae057a102..b82a0e31c6 100644 --- a/crates/rustc_codegen_spirv/build.rs +++ b/crates/rustc_codegen_spirv/build.rs @@ -15,9 +15,9 @@ use std::{env, fs, mem}; /// `cargo publish`. We need to figure out a way to do this properly, but let's hardcode it for now :/ //const REQUIRED_RUST_TOOLCHAIN: &str = include_str!("../../rust-toolchain.toml"); const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain] -channel = "nightly-2024-10-12" +channel = "nightly-2024-11-22" components = ["rust-src", "rustc-dev", "llvm-tools"] -# commit_hash = 1bc403daadbebb553ccc211a0a8eebb73989665f"#; +# commit_hash = b19329a37cedf2027517ae22c87cf201f93d776e"#; fn rustc_output(arg: &str) -> Result> { let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".into()); diff --git a/crates/rustc_codegen_spirv/src/abi.rs b/crates/rustc_codegen_spirv/src/abi.rs index ba857df9b8..04d1bf9860 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -9,12 +9,11 @@ use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::ErrorGuaranteed; use rustc_index::Idx; -use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; use rustc_middle::ty::{ - self, Const, CoroutineArgs, CoroutineArgsExt as _, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, - TyCtxt, TyKind, UintTy, + self, Const, CoroutineArgs, CoroutineArgsExt as _, FloatTy, IntTy, PolyFnSig, Ty, TyCtxt, + TyKind, UintTy, }; use rustc_middle::ty::{GenericArgsRef, ScalarInt}; use rustc_middle::{bug, span_bug}; @@ -23,10 +22,10 @@ use rustc_span::def_id::DefId; use rustc_span::{Span, Symbol}; use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode}; use rustc_target::abi::{ - Abi, Align, FieldsShape, LayoutS, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding, - VariantIdx, Variants, + Align, BackendRepr, FieldsShape, LayoutData, Primitive, ReprFlags, ReprOptions, Scalar, Size, + TagEncoding, VariantIdx, Variants, }; -use rustc_target::spec::abi::Abi as SpecAbi; +use rustc_target::spec::abi::Abi; use std::cell::RefCell; use std::collections::hash_map::Entry; use std::fmt; @@ -47,8 +46,8 @@ pub(crate) fn provide(providers: &mut Providers) { let result = (rustc_interface::DEFAULT_QUERY_PROVIDERS.fn_sig)(tcx, def_id); result.map_bound(|outer| { outer.map_bound(|mut inner| { - if let SpecAbi::C { .. } = inner.abi { - inner.abi = SpecAbi::Unadjusted; + if let Abi::C { .. } = inner.abi { + inner.abi = Abi::Unadjusted; } inner }) @@ -98,22 +97,21 @@ pub(crate) fn provide(providers: &mut Providers) { Ok(readjust_fn_abi(tcx, result?)) }; - // FIXME(eddyb) remove this by deriving `Clone` for `LayoutS` upstream. - // FIXME(eddyb) the `S` suffix is a naming antipattern, rename upstream. + // FIXME(eddyb) remove this by deriving `Clone` for `LayoutData` upstream. fn clone_layout( - layout: &LayoutS, - ) -> LayoutS { - let LayoutS { + layout: &LayoutData, + ) -> LayoutData { + let LayoutData { ref fields, ref variants, - abi, + backend_repr, largest_niche, align, size, max_repr_align, unadjusted_abi_align, } = *layout; - LayoutS { + LayoutData { fields: match *fields { FieldsShape::Primitive => FieldsShape::Primitive, FieldsShape::Union(count) => FieldsShape::Union(count), @@ -151,7 +149,7 @@ pub(crate) fn provide(providers: &mut Providers) { variants: variants.clone(), }, }, - abi, + backend_repr, largest_niche, align, size, @@ -171,7 +169,7 @@ pub(crate) fn provide(providers: &mut Providers) { }; if hide_niche { - layout = tcx.mk_layout(LayoutS { + layout = tcx.mk_layout(LayoutData { largest_niche: None, ..clone_layout(layout.0.0) }); @@ -192,6 +190,10 @@ pub(crate) fn provide(providers: &mut Providers) { // an option (may require Rust-GPU distinguishing between "SPIR-V interface" // and "Rust-facing" types, which is even worse when the `OpTypeVector`s // may be e.g. nested in `struct`s/arrays/etc. - at least buffers are easy). + // + // FIXME(eddyb) maybe using `#[spirv(vector)]` and `BackendRepr::Memory`, + // no claims at `rustc`-understood SIMD whatsoever, would be enough? + // (i.e. only SPIR-V caring about such a type vs a struct/array) providers.check_well_formed = |tcx, def_id| { let trivial_struct = match tcx.hir_node_by_def_id(def_id) { rustc_hir::Node::Item(item) => match item.kind { @@ -263,6 +265,14 @@ pub(crate) fn provide(providers: &mut Providers) { (rustc_interface::DEFAULT_QUERY_PROVIDERS.check_well_formed)(tcx, def_id) }; + + // HACK(eddyb) work around https://github.com/rust-lang/rust/pull/132173 + // (and further changes from https://github.com/rust-lang/rust/pull/132843) + // starting to ban SIMD ABI misuse (or at least starting to warn about it). + // + // FIXME(eddyb) same as the FIXME comment on `check_well_formed`: + // need to migrate away from `#[repr(simd)]` ASAP. + providers.check_mono_item = |_, _| {}; } /// If a struct contains a pointer to itself, even indirectly, then doing a naiive recursive walk @@ -450,9 +460,9 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { // Note: ty.layout is orthogonal to ty.ty, e.g. `ManuallyDrop>` has abi // `ScalarPair`. - // There's a few layers that we go through here. First we inspect layout.abi, then if relevant, layout.fields, etc. - match self.abi { - Abi::Uninhabited => SpirvType::Adt { + // There's a few layers that we go through here. First we inspect layout.backend_repr, then if relevant, layout.fields, etc. + match self.backend_repr { + BackendRepr::Uninhabited => SpirvType::Adt { def_id: def_id_for_spirv_type_adt(*self), size: Some(Size::ZERO), align: Align::from_bytes(0).unwrap(), @@ -461,13 +471,13 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { field_names: None, } .def_with_name(cx, span, TyLayoutNameKey::from(*self)), - Abi::Scalar(scalar) => trans_scalar(cx, span, *self, scalar, Size::ZERO), - Abi::ScalarPair(a, b) => { - // NOTE(eddyb) unlike `Abi::Scalar`'s simpler newtype-unpacking - // behavior, `Abi::ScalarPair` can be composed in two ways: - // * two `Abi::Scalar` fields (and any number of ZST fields), + BackendRepr::Scalar(scalar) => trans_scalar(cx, span, *self, scalar, Size::ZERO), + BackendRepr::ScalarPair(a, b) => { + // NOTE(eddyb) unlike `BackendRepr::Scalar`'s simpler newtype-unpacking + // behavior, `BackendRepr::ScalarPair` can be composed in two ways: + // * two `BackendRepr::Scalar` fields (and any number of ZST fields), // gets handled the same as a `struct { a, b }`, further below - // * an `Abi::ScalarPair` field (and any number of ZST fields), + // * an `BackendRepr::ScalarPair` field (and any number of ZST fields), // which requires more work to allow taking a reference to // that field, and there are two potential approaches: // 1. wrapping that field's SPIR-V type in a single-field @@ -477,7 +487,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { // 2. reusing that field's SPIR-V type, instead of defining // a new one, offering the `(a, b)` shape `rustc_codegen_ssa` // expects, while letting noop pointercasts access the sole - // `Abi::ScalarPair` field - this is the approach taken here + // `BackendRepr::ScalarPair` field - this is the approach taken here let mut non_zst_fields = (0..self.fields.count()) .map(|i| (i, self.field(cx, i))) .filter(|(_, field)| !field.is_zst()); @@ -491,7 +501,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { if self.fields.offset(i) == Size::ZERO && field.size == self.size && field.align == self.align - && field.abi == self.abi + && field.backend_repr == self.backend_repr { return field.spirv_type(span, cx); } @@ -532,7 +542,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { } .def_with_name(cx, span, TyLayoutNameKey::from(*self)) } - Abi::Vector { element, count } => { + BackendRepr::Vector { element, count } => { let elem_spirv = trans_scalar(cx, span, *self, element, Size::ZERO); SpirvType::Vector { element: elem_spirv, @@ -540,7 +550,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { } .def(span, cx) } - Abi::Aggregate { sized: _ } => trans_aggregate(cx, span, *self), + BackendRepr::Memory { sized: _ } => trans_aggregate(cx, span, *self), } } } @@ -553,8 +563,8 @@ pub fn scalar_pair_element_backend_type<'tcx>( ty: TyAndLayout<'tcx>, index: usize, ) -> Word { - let [a, b] = match ty.layout.abi() { - Abi::ScalarPair(a, b) => [a, b], + let [a, b] = match ty.layout.backend_repr() { + BackendRepr::ScalarPair(a, b) => [a, b], other => span_bug!( span, "scalar_pair_element_backend_type invalid abi: {:?}", @@ -901,7 +911,7 @@ fn trans_intrinsic_type<'tcx>( // ) -> P { // let adt_def = const_.ty.ty_adt_def().unwrap(); // assert!(adt_def.is_enum()); - // let destructured = cx.tcx.destructure_const(ParamEnv::reveal_all().and(const_)); + // let destructured = cx.tcx.destructure_const(TypingEnv::fully_monomorphized().and(const_)); // let idx = destructured.variant.unwrap(); // let value = const_.ty.discriminant_for_variant(cx.tcx, idx).unwrap().val as u64; // <_>::from_u64(value).unwrap() @@ -974,24 +984,17 @@ fn trans_intrinsic_type<'tcx>( cx: &CodegenCx<'tcx>, const_: Const<'tcx>, ) -> Result { - const_ - .eval(cx.tcx, ParamEnv::reveal_all(), DUMMY_SP) - .map_err(|e| match e { - ErrorHandled::Reported(reported_error_info, _) => { - Some(reported_error_info.into()) - } - ErrorHandled::TooGeneric(_) => None, - }) - .and_then(|(const_ty, const_val)| { - assert!(const_ty.is_integral()); - P::from_scalar_int(const_val.try_to_scalar_int().ok_or(None)?).ok_or(None) - }) - .map_err(|already_reported| { - already_reported.unwrap_or_else(|| { - cx.tcx - .dcx() - .err(format!("invalid value for Image const generic: {const_}")) - }) + let (const_val, const_ty) = const_ + .try_to_valtree() + .expect("expected monomorphic const in codegen"); + assert!(const_ty.is_integral()); + const_val + .try_to_scalar_int() + .and_then(P::from_scalar_int) + .ok_or_else(|| { + cx.tcx + .dcx() + .err(format!("invalid value for Image const generic: {const_}")) }) } diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index ce16d013e5..7e61c1b989 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -28,7 +28,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; use rustc_span::Span; use rustc_target::abi::call::FnAbi; -use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange}; +use rustc_target::abi::{Align, BackendRepr, Scalar, Size, WrappingRange}; use smallvec::SmallVec; use std::borrow::Cow; use std::cell::Cell; @@ -1523,7 +1523,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { place.val.align, ); OperandValue::Immediate(self.to_immediate(llval, place.layout)) - } else if let Abi::ScalarPair(a, b) = place.layout.abi { + } else if let BackendRepr::ScalarPair(a, b) = place.layout.backend_repr { let b_offset = a .primitive() .size(self) @@ -2668,16 +2668,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { // ignore } - fn instrprof_increment( - &mut self, - _fn_name: Self::Value, - _hash: Self::Value, - _num_counters: Self::Value, - _index: Self::Value, - ) { - todo!() - } - fn call( &mut self, callee_ty: Self::Type, @@ -3176,8 +3166,8 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let layout = self.layout_of(ty); - let scalar = match layout.abi { - Abi::Scalar(scalar) => Some(scalar.primitive()), + let scalar = match layout.backend_repr { + BackendRepr::Scalar(scalar) => Some(scalar.primitive()), _ => None, }; let debug_printf_fmt = match (spec, scalar) { diff --git a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs index 45a38a826c..53e9d23233 100644 --- a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs +++ b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs @@ -13,7 +13,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::{BuilderMethods, IntrinsicCallBuilderMethods}; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{FnDef, Instance, ParamEnv, Ty, TyKind}; +use rustc_middle::ty::{FnDef, Instance, Ty, TyKind, TypingEnv}; use rustc_middle::{bug, ty}; use rustc_span::Span; use rustc_span::sym; @@ -75,7 +75,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> { llresult: Self::Value, _span: Span, ) -> Result<(), ty::Instance<'tcx>> { - let callee_ty = instance.ty(self.tcx, ParamEnv::reveal_all()); + let callee_ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized()); let (def_id, fn_args) = match *callee_ty.kind() { FnDef(def_id, fn_args) => (def_id, fn_args), @@ -85,7 +85,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> { let sig = callee_ty.fn_sig(self.tcx); let sig = self .tcx - .normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), sig); + .normalize_erasing_late_bound_regions(TypingEnv::fully_monomorphized(), sig); let arg_tys = sig.inputs(); let name = self.tcx.item_name(def_id); diff --git a/crates/rustc_codegen_spirv/src/builder/mod.rs b/crates/rustc_codegen_spirv/src/builder/mod.rs index 654009baa6..972432267e 100644 --- a/crates/rustc_codegen_spirv/src/builder/mod.rs +++ b/crates/rustc_codegen_spirv/src/builder/mod.rs @@ -28,10 +28,10 @@ use rustc_errors::{Diag, DiagMessage}; use rustc_middle::mir::coverage::CoverageKind; use rustc_middle::span_bug; use rustc_middle::ty::layout::{ - FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, - TyAndLayout, + FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, + LayoutOfHelpers, TyAndLayout, }; -use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt}; +use rustc_middle::ty::{Instance, Ty, TyCtxt, TypingEnv}; use rustc_span::Span; use rustc_span::def_id::DefId; use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode}; @@ -175,6 +175,10 @@ impl<'a, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'tcx> { todo!() } + fn get_dbg_loc(&self) -> Option { + None + } + fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) { todo!() } @@ -264,9 +268,9 @@ impl<'a, 'tcx> BackendTypes for Builder<'a, 'tcx> { type DILocation = as BackendTypes>::DILocation; } -impl<'a, 'tcx> HasParamEnv<'tcx> for Builder<'a, 'tcx> { - fn param_env(&self) -> ParamEnv<'tcx> { - self.cx.param_env() +impl<'a, 'tcx> HasTypingEnv<'tcx> for Builder<'a, 'tcx> { + fn typing_env(&self) -> TypingEnv<'tcx> { + self.cx.typing_env() } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index d3482c866d..eae83d8e93 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -16,7 +16,7 @@ use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf}; -use rustc_middle::ty::{self, Instance, ParamEnv, TypeVisitableExt}; +use rustc_middle::ty::{self, Instance, TypeVisitableExt, TypingEnv}; use rustc_span::Span; use rustc_span::def_id::DefId; use rustc_target::abi::Align; @@ -257,7 +257,7 @@ impl<'tcx> CodegenCx<'tcx> { "get_static() should always hit the cache for statics defined in the same CGU, but did not for `{def_id:?}`" ); - let ty = instance.ty(self.tcx, ParamEnv::reveal_all()); + let ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized()); let sym = self.tcx.symbol_name(instance).name; let span = self.tcx.def_span(def_id); let g = self.declare_global(span, self.layout_of(ty).spirv_type(span, self)); @@ -289,7 +289,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'tcx> { symbol_name: &str, ) { let instance = Instance::mono(self.tcx, def_id); - let ty = instance.ty(self.tcx, ParamEnv::reveal_all()); + let ty = instance.ty(self.tcx, TypingEnv::fully_monomorphized()); let span = self.tcx.def_span(def_id); let spvty = self.layout_of(ty).spirv_type(span, self); let linkage = match linkage { diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs index 98c992f5ba..7dcd22d291 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs @@ -240,7 +240,7 @@ impl<'tcx> CodegenCx<'tcx> { if is_ref && !value_layout .ty - .is_freeze(self.tcx, ty::ParamEnv::reveal_all()) => + .is_freeze(self.tcx, ty::TypingEnv::fully_monomorphized()) => { hir::Mutability::Mut } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index 81e131d771..f806a5e3a3 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -26,14 +26,14 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def_id::DefId; use rustc_middle::mir; use rustc_middle::mir::mono::CodegenUnit; -use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt}; -use rustc_middle::ty::{Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; +use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv}; +use rustc_middle::ty::{Instance, PolyExistentialTraitRef, Ty, TyCtxt, TypingEnv}; use rustc_session::Session; use rustc_span::symbol::Symbol; use rustc_span::{DUMMY_SP, SourceFile, Span}; use rustc_target::abi::call::{FnAbi, PassMode}; use rustc_target::abi::{AddressSpace, HasDataLayout, TargetDataLayout}; -use rustc_target::spec::{HasTargetSpec, Target, TargetTriple}; +use rustc_target::spec::{HasTargetSpec, Target, TargetTuple}; use std::cell::RefCell; use std::collections::BTreeSet; use std::iter::once; @@ -94,15 +94,15 @@ pub struct CodegenCx<'tcx> { impl<'tcx> CodegenCx<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, codegen_unit: &'tcx CodegenUnit<'tcx>) -> Self { // Validate the target spec, as the backend doesn't control `--target`. - let target_triple = tcx.sess.opts.target_triple.triple(); - let target: SpirvTarget = target_triple.parse().unwrap_or_else(|_| { - let qualifier = if !target_triple.starts_with("spirv-") { + let target_tuple = tcx.sess.opts.target_triple.tuple(); + let target: SpirvTarget = target_tuple.parse().unwrap_or_else(|_| { + let qualifier = if !target_tuple.starts_with("spirv-") { "non-SPIR-V " } else { "" }; tcx.dcx().fatal(format!( - "{qualifier}target `{target_triple}` not supported by `rustc_codegen_spirv`", + "{qualifier}target `{target_tuple}` not supported by `rustc_codegen_spirv`", )) }); let target_spec_mismatched_jsons = { @@ -119,12 +119,12 @@ impl<'tcx> CodegenCx<'tcx> { // ideally `spirv-builder` can be forced to pass an exact match. // // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative. - TargetTriple::TargetTriple(_) => { + TargetTuple::TargetTuple(_) => { // FIXME(eddyb) this case should be impossible as upstream // `rustc` doesn't support `spirv-*` targets! (expected != found).then(|| [expected, found].map(|spec| spec.to_json())) } - TargetTriple::TargetJson { contents, .. } => { + TargetTuple::TargetJson { contents, .. } => { let expected = expected.to_json(); let found = serde_json::from_str(contents).unwrap(); (expected != found).then_some([expected, found]) @@ -139,12 +139,12 @@ impl<'tcx> CodegenCx<'tcx> { .filter(|k| expected.get(k) != found.get(k)); tcx.dcx() - .struct_fatal(format!("mismatched `{target_triple}` target spec")) + .struct_fatal(format!("mismatched `{target_tuple}` target spec")) .with_note(format!( "expected (built into `rustc_codegen_spirv`):\n{expected:#}" )) .with_note(match &tcx.sess.opts.target_triple { - TargetTriple::TargetJson { + TargetTuple::TargetJson { path_for_rustdoc, contents, .. @@ -839,9 +839,9 @@ impl<'tcx> HasTargetSpec for CodegenCx<'tcx> { } } -impl<'tcx> HasParamEnv<'tcx> for CodegenCx<'tcx> { - fn param_env(&self) -> ParamEnv<'tcx> { - ParamEnv::reveal_all() +impl<'tcx> HasTypingEnv<'tcx> for CodegenCx<'tcx> { + fn typing_env(&self) -> TypingEnv<'tcx> { + TypingEnv::fully_monomorphized() } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs index be5010ac9d..f0005a9e42 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs @@ -15,7 +15,7 @@ use rustc_middle::{bug, span_bug}; use rustc_span::source_map::Spanned; use rustc_span::{DUMMY_SP, Span}; use rustc_target::abi::call::{CastTarget, FnAbi, Reg}; -use rustc_target::abi::{Abi, AddressSpace}; +use rustc_target::abi::{AddressSpace, BackendRepr}; impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; @@ -96,17 +96,20 @@ impl<'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'tcx> { } fn is_backend_immediate(&self, layout: TyAndLayout<'tcx>) -> bool { - match layout.abi { - Abi::Scalar(_) | Abi::Vector { .. } => true, - Abi::ScalarPair(..) => false, - Abi::Uninhabited | Abi::Aggregate { .. } => layout.is_zst(), + match layout.backend_repr { + BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => true, + BackendRepr::ScalarPair(..) => false, + BackendRepr::Uninhabited | BackendRepr::Memory { .. } => layout.is_zst(), } } fn is_backend_scalar_pair(&self, layout: TyAndLayout<'tcx>) -> bool { - match layout.abi { - Abi::ScalarPair(..) => true, - Abi::Uninhabited | Abi::Scalar(_) | Abi::Vector { .. } | Abi::Aggregate { .. } => false, + match layout.backend_repr { + BackendRepr::ScalarPair(..) => true, + BackendRepr::Uninhabited + | BackendRepr::Scalar(_) + | BackendRepr::Vector { .. } + | BackendRepr::Memory { .. } => false, } } diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index 91aa9e8b45..f5ab65665d 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -4,12 +4,12 @@ #![allow(rustc::untranslatable_diagnostic)] #![feature(assert_matches)] #![feature(box_patterns)] +#![feature(debug_closure_helpers)] #![feature(file_buffered)] #![feature(if_let_guard)] #![feature(let_chains)] #![feature(negative_impls)] #![feature(rustdoc_internals)] -#![feature(strict_provenance)] #![feature(trait_alias)] #![feature(try_blocks)] // HACK(eddyb) end of `rustc_codegen_ssa` crate-level attributes (see `build.rs`). @@ -194,13 +194,13 @@ fn is_blocklisted_fn<'tcx>( // Helper for detecting `<_ as core::fmt::Debug>::fmt` (in impls). let is_debug_fmt_method = |def_id| match tcx.opt_associated_item(def_id) { Some(assoc) if assoc.ident(tcx).name == sym::fmt => match assoc.container { - ty::ImplContainer => { + ty::AssocItemContainer::Impl => { let impl_def_id = assoc.container_id(tcx); tcx.impl_trait_ref(impl_def_id) .map(|tr| tr.skip_binder().def_id) == Some(debug_trait_def_id) } - ty::TraitContainer => false, + ty::AssocItemContainer::Trait => false, }, _ => false, }; diff --git a/crates/rustc_codegen_spirv/src/linker/dce.rs b/crates/rustc_codegen_spirv/src/linker/dce.rs index 3cc865a741..c21429a535 100644 --- a/crates/rustc_codegen_spirv/src/linker/dce.rs +++ b/crates/rustc_codegen_spirv/src/linker/dce.rs @@ -103,7 +103,7 @@ fn is_rooted(inst: &Instruction, rooted: &FxIndexSet) -> bool { // referenced by roots inst.operands .iter() - .any(|op| op.id_ref_any().map_or(false, |w| rooted.contains(&w))) + .any(|op| op.id_ref_any().is_some_and(|w| rooted.contains(&w))) } } diff --git a/crates/rustc_codegen_spirv/src/linker/inline.rs b/crates/rustc_codegen_spirv/src/linker/inline.rs index 48574f036f..60c735aefc 100644 --- a/crates/rustc_codegen_spirv/src/linker/inline.rs +++ b/crates/rustc_codegen_spirv/src/linker/inline.rs @@ -179,10 +179,10 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> { // Drop OpName etc. for inlined functions module.debug_names.retain(|inst| { - !inst.operands.iter().any(|op| { - op.id_ref_any() - .map_or(false, |id| dropped_ids.contains(&id)) - }) + !inst + .operands + .iter() + .any(|op| op.id_ref_any().is_some_and(|id| dropped_ids.contains(&id))) }); Ok(()) diff --git a/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs b/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs index 3947b300ba..6a0df87bfd 100644 --- a/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs +++ b/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs @@ -332,15 +332,11 @@ fn process_instruction( } let vector_width = vector_ty_inst.operands[1].unwrap_literal_bit32(); // `results` is the defining instruction for each scalar component of the final result. - let results = match inst + let results = inst .operands .iter() .map(|op| defs.get(&op.unwrap_id_ref())) - .collect::>>() - { - Some(r) => r, - None => return None, - }; + .collect::>>()?; let operation_opcode = results[0].class.opcode; // Figure out the operands for the vectorized instruction. @@ -455,10 +451,7 @@ fn can_fuse_bool( inst: &Instruction, ) -> bool { fn constant_value(types: &FxHashMap, val: Word) -> Option { - let inst = match types.get(&val) { - None => return None, - Some(inst) => inst, - }; + let inst = types.get(&val)?; if inst.class.opcode != Op::Constant { return None; } diff --git a/crates/rustc_codegen_spirv/src/target.rs b/crates/rustc_codegen_spirv/src/target.rs index 2f319e611f..313c0a474b 100644 --- a/crates/rustc_codegen_spirv/src/target.rs +++ b/crates/rustc_codegen_spirv/src/target.rs @@ -113,7 +113,7 @@ impl std::str::FromStr for SpirvTarget { let mut iter = target.split('-'); let error = || InvalidTarget(target.into()); - if iter.next().map_or(true, |arch| arch != ARCH) { + if iter.next() != Some(ARCH) { return Err(error()); } diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 7385c488f1..a2f4d5278d 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -836,9 +836,9 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { // inner invocation of Cargo (because e.g. build scripts might read them), // before we set any of our own below. for (key, _) in env::vars_os() { - let remove = key.to_str().map_or(false, |s| { - s.starts_with("CARGO_FEATURES_") || s.starts_with("CARGO_CFG_") - }); + let remove = key + .to_str() + .is_some_and(|s| s.starts_with("CARGO_FEATURES_") || s.starts_with("CARGO_CFG_")); if remove { cargo.env_remove(key); } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 8854f7bfe7..551cee7f67 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2024-10-12" +channel = "nightly-2024-11-22" components = ["rust-src", "rustc-dev", "llvm-tools"] -# commit_hash = 1bc403daadbebb553ccc211a0a8eebb73989665f +# commit_hash = b19329a37cedf2027517ae22c87cf201f93d776e # Whenever changing the nightly channel, update the commit hash above, and make # sure to change `REQUIRED_TOOLCHAIN` in `crates/rustc_codegen_spirv/build.rs` also. diff --git a/tests/src/main.rs b/tests/src/main.rs index 93ebdcad43..551e6eb92f 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -304,7 +304,7 @@ fn find_lib( && ends_with_dash_hash(name.to_str().unwrap()); let extension_matches = path .extension() - .map_or(false, |ext| ext == expected_extension); + .is_some_and(|ext| ext == expected_extension); name_matches && extension_matches }) diff --git a/tests/ui/dis/issue-1062.stderr b/tests/ui/dis/issue-1062.stderr index ddda7238d2..e62cf988bf 100644 --- a/tests/ui/dis/issue-1062.stderr +++ b/tests/ui/dis/issue-1062.stderr @@ -4,7 +4,7 @@ OpLine %5 11 12 %6 = OpLoad %7 %8 OpLine %5 11 35 %9 = OpLoad %7 %10 -OpLine %11 1148 4 +OpLine %11 1199 4 %12 = OpBitwiseAnd %7 %9 %13 %14 = OpISub %7 %15 %12 %16 = OpShiftLeftLogical %7 %6 %12 diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index 3f5360a3dc..e376de2e58 100644 --- a/tests/ui/dis/ptr_copy.normal.stderr +++ b/tests/ui/dis/ptr_copy.normal.stderr @@ -1,13 +1,13 @@ error: cannot memcpy dynamically sized data - --> $CORE_SRC/intrinsics.rs:3419:9 + --> $CORE_SRC/intrinsics/mod.rs:4158:9 | -3419 | copy(src, dst, count) +4158 | copy(src, dst, count) | ^^^^^^^^^^^^^^^^^^^^^ | note: used from within `core::intrinsics::copy::` - --> $CORE_SRC/intrinsics.rs:3399:21 + --> $CORE_SRC/intrinsics/mod.rs:4134:21 | -3399 | pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { +4134 | pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { | ^^^^ note: called by `ptr_copy::copy_via_raw_ptr` --> $DIR/ptr_copy.rs:28:18 @@ -28,27 +28,27 @@ note: called by `main` error: cannot cast between pointer types from `*f32` to `*struct () { }` - --> $CORE_SRC/intrinsics.rs:3408:9 + --> $CORE_SRC/intrinsics/mod.rs:4146:9 | -3408 | / ub_checks::assert_unsafe_precondition!( -3409 | | check_language_ub, -3410 | | "ptr::copy requires that both pointer arguments are aligned and non-null", -3411 | | ( +4146 | / ub_checks::assert_unsafe_precondition!( +4147 | | check_language_ub, +4148 | | "ptr::copy requires that both pointer arguments are aligned and non-null", +4149 | | ( ... | -3417 | | && ub_checks::is_aligned_and_not_null(dst, align) -3418 | | ); +4156 | | && ub_checks::maybe_is_aligned_and_not_null(dst, align, zero_size) +4157 | | ); | |_________^ | note: used from within `core::intrinsics::copy::` - --> $CORE_SRC/intrinsics.rs:3408:9 + --> $CORE_SRC/intrinsics/mod.rs:4146:9 | -3408 | / ub_checks::assert_unsafe_precondition!( -3409 | | check_language_ub, -3410 | | "ptr::copy requires that both pointer arguments are aligned and non-null", -3411 | | ( +4146 | / ub_checks::assert_unsafe_precondition!( +4147 | | check_language_ub, +4148 | | "ptr::copy requires that both pointer arguments are aligned and non-null", +4149 | | ( ... | -3417 | | && ub_checks::is_aligned_and_not_null(dst, align) -3418 | | ); +4156 | | && ub_checks::maybe_is_aligned_and_not_null(dst, align, zero_size) +4157 | | ); | |_________^ note: called by `ptr_copy::copy_via_raw_ptr` --> $DIR/ptr_copy.rs:28:18 diff --git a/tests/ui/dis/ptr_read.stderr b/tests/ui/dis/ptr_read.stderr index 401b6f61af..ee8fd2aab4 100644 --- a/tests/ui/dis/ptr_read.stderr +++ b/tests/ui/dis/ptr_read.stderr @@ -2,7 +2,7 @@ %4 = OpFunctionParameter %5 %6 = OpFunctionParameter %5 %7 = OpLabel -OpLine %8 1434 8 +OpLine %8 1374 8 %9 = OpLoad %10 %4 OpLine %11 7 13 OpStore %6 %9 diff --git a/tests/ui/dis/ptr_read_method.stderr b/tests/ui/dis/ptr_read_method.stderr index 401b6f61af..ee8fd2aab4 100644 --- a/tests/ui/dis/ptr_read_method.stderr +++ b/tests/ui/dis/ptr_read_method.stderr @@ -2,7 +2,7 @@ %4 = OpFunctionParameter %5 %6 = OpFunctionParameter %5 %7 = OpLabel -OpLine %8 1434 8 +OpLine %8 1374 8 %9 = OpLoad %10 %4 OpLine %11 7 13 OpStore %6 %9 diff --git a/tests/ui/dis/ptr_write.stderr b/tests/ui/dis/ptr_write.stderr index 1445422d42..2ca3b239fc 100644 --- a/tests/ui/dis/ptr_write.stderr +++ b/tests/ui/dis/ptr_write.stderr @@ -4,7 +4,7 @@ %7 = OpLabel OpLine %8 7 35 %9 = OpLoad %10 %4 -OpLine %11 1639 8 +OpLine %11 1578 8 OpStore %6 %9 OpNoLine OpReturn diff --git a/tests/ui/dis/ptr_write_method.stderr b/tests/ui/dis/ptr_write_method.stderr index 0075401c67..5ff386ef8c 100644 --- a/tests/ui/dis/ptr_write_method.stderr +++ b/tests/ui/dis/ptr_write_method.stderr @@ -4,7 +4,7 @@ %7 = OpLabel OpLine %8 7 37 %9 = OpLoad %10 %4 -OpLine %11 1639 8 +OpLine %11 1578 8 OpStore %6 %9 OpNoLine OpReturn diff --git a/tests/ui/lang/core/unwrap_or.stderr b/tests/ui/lang/core/unwrap_or.stderr index 45b5e9bdf6..7f46d10973 100644 --- a/tests/ui/lang/core/unwrap_or.stderr +++ b/tests/ui/lang/core/unwrap_or.stderr @@ -3,9 +3,9 @@ OpLine %5 13 11 %6 = OpCompositeInsert %7 %8 %9 0 %10 = OpCompositeExtract %11 %6 1 -OpLine %12 990 14 +OpLine %12 993 14 %13 = OpBitcast %14 %8 -OpLine %12 990 8 +OpLine %12 993 8 %15 = OpIEqual %16 %13 %17 OpNoLine OpSelectionMerge %18 None