From e9cdb9666b9ec204791fb17b614bfb223ced36c5 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 2 Jun 2023 01:40:38 +0300 Subject: [PATCH] rustup: update to `nightly-2023-04-15`. --- CHANGELOG.md | 4 +- crates/rustc_codegen_spirv/build.rs | 4 +- crates/rustc_codegen_spirv/src/abi.rs | 4 +- .../src/builder/builder_methods.rs | 41 +++++++++------ .../rustc_codegen_spirv/src/builder_spirv.rs | 5 ++ .../src/codegen_cx/constant.rs | 4 ++ .../src/codegen_cx/declare.rs | 20 +++++-- .../rustc_codegen_spirv/src/codegen_cx/mod.rs | 2 +- crates/rustc_codegen_spirv/src/lib.rs | 4 +- crates/rustc_codegen_spirv/src/link.rs | 52 +++++-------------- crates/spirv-std/macros/src/lib.rs | 2 + rust-toolchain.toml | 6 +-- tests/ui/dis/ptr_copy.normal.stderr | 8 +-- 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 +- .../spirv-attr/invalid-matrix-type-empty.rs | 6 +-- .../invalid-matrix-type-empty.stderr | 4 +- 20 files changed, 93 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49d7eabf98..af819e4244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (using ranges instead of just the starting position, and tracking inlined calls) ### Changed 🛠 +- [PR#1067](https://github.com/EmbarkStudios/rust-gpu/pull/1067) updated toolchain to `nightly-2023-04-15` - [PR#1038](https://github.com/EmbarkStudios/rust-gpu/pull/1038) relaxed `glam` version requirements (from only `0.22`, to `>=0.22, <=0.24`) ### Removed 🔥 @@ -66,7 +67,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (see also [the `--no-early-report-zombies` codegen args docs](docs/src/codegen-args.md#--no-early-report-zombies)) - [PR#1035](https://github.com/EmbarkStudios/rust-gpu/pull/1035) reduced the number of CGUs ("codegen units") used by `spirv-builder` to just `1` - [PR#1011](https://github.com/EmbarkStudios/rust-gpu/pull/1011) made `NonWritable` all read-only storage buffers (i.e. those typed `&T`, where `T` doesn't have interior mutability) -- [PR#1029](https://github.com/EmbarkStudios/rust-gpu/pull/1029) fixed SampledImage::sample() fns being unnecessarily marked as unsafe +- [PR#1029](https://github.com/EmbarkStudios/rust-gpu/pull/1029) fixed `SampledImage::sample` `fn`s being unnecessarily marked as `unsafe` +- [PR#1005](https://github.com/EmbarkStudios/rust-gpu/pull/1005) updated toolchain to `nightly-2023-03-04` ### Fixed 🩹 - [PR#1041](https://github.com/EmbarkStudios/rust-gpu/pull/1041) fixed `Image::gather()` not always returning a `Vec4`. diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index 4bdb7d2570..de1f77fb77 100644 --- a/crates/rustc_codegen_spirv/build.rs +++ b/crates/rustc_codegen_spirv/build.rs @@ -10,9 +10,9 @@ use std::process::{Command, ExitCode}; /// `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"); const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain] -channel = "nightly-2023-03-04" +channel = "nightly-2023-04-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 44cfafe2fafe816395d3acc434663a45d5178c41"#; +# commit_hash = 84dd17b56a931a631a23dfd5ef2018fd3ef49108"#; fn get_rustc_commit_hash() -> Result> { let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc")); diff --git a/crates/rustc_codegen_spirv/src/abi.rs b/crates/rustc_codegen_spirv/src/abi.rs index d4e2004b58..4a5f9d07c6 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -424,7 +424,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { if let TyKind::Adt(adt, _) = self.ty.kind() { if let Variants::Single { index } = self.variants { for i in self.fields.index_by_increasing_offset() { - let field = &adt.variants()[index].fields[i]; + let field = &adt.variants()[index].fields[i.into()]; field_names.push(field.name); } } @@ -711,7 +711,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) - field_offsets.push(offset); if let Variants::Single { index } = ty.variants { if let TyKind::Adt(adt, _) = ty.ty.kind() { - let field = &adt.variants()[index].fields[i]; + let field = &adt.variants()[index].fields[i.into()]; field_names.push(field.name); } else { // FIXME(eddyb) this looks like something that should exist in rustc. diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index 72c0107fa5..701766c811 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -657,6 +657,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { } fn set_span(&mut self, span: Span) { + // HACK(eddyb) this is what `#[track_caller]` does, and we need it to be + // able to point at e.g. a use of `panic!`, instead of its implementation, + // but it should be more fine-grained and/or include macro backtraces in + // debuginfo (so the decision to use them can be deferred). + let span = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); + let old_span = self.current_span.replace(span); // FIXME(eddyb) enable this once cross-block interactions are figured out @@ -2392,10 +2398,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { &[SpirvValue { kind: SpirvValueKind::Def(format_args_id), .. - }, SpirvValue { - kind: SpirvValueKind::IllegalConst(_panic_location_id), - .. - }] => format_args_id, + }, _] => format_args_id, _ => return None, }; @@ -2445,21 +2448,27 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { (operands.next().unwrap(), operands.next().unwrap()) }) .filter(|&(store_dst_id, _)| store_dst_id == load_src_id)?; - let (call_fmt_args_new_idx, _) = relevant_insts_next_back(Op::FunctionCall) + let call_fmt_args_new_idx = relevant_insts_next_back(Op::FunctionCall) .filter(|&(_, result_id, _)| result_id == Some(store_val_id)) .map(|(i, _, mut operands)| (i, operands.next().unwrap(), operands)) .filter(|&(_, callee, _)| self.fmt_args_new_fn_ids.borrow().contains(&callee)) - .map(|(i, _, mut call_args)| { - assert_eq!(call_args.len(), 4); - let mut arg = || call_args.next().unwrap(); - (i, [arg(), arg(), arg(), arg()]) - }) - .filter(|&(_, [_, _, _, fmt_args_len_id])| { - // Only ever remove `fmt::Arguments` with no runtime values. - matches!( - self.builder.lookup_const_by_id(fmt_args_len_id), - Some(SpirvConst::U32(0)) - ) + .and_then(|(i, _, mut call_args)| { + if call_args.len() == 4 { + // `::new_v1` + let mut arg = || call_args.next().unwrap(); + let [_, _, _, fmt_args_len_id] = [arg(), arg(), arg(), arg()]; + // Only ever remove `fmt::Arguments` with no runtime values. + Some(i).filter(|_| { + matches!( + self.builder.lookup_const_by_id(fmt_args_len_id), + Some(SpirvConst::U32(0)) + ) + }) + } else { + // `::new_const` + assert_eq!(call_args.len(), 2); + Some(i) + } })?; // Lastly, ensure that the `Op{Store,Load}` pair operates on diff --git a/crates/rustc_codegen_spirv/src/builder_spirv.rs b/crates/rustc_codegen_spirv/src/builder_spirv.rs index ee55c01851..d0899749d4 100644 --- a/crates/rustc_codegen_spirv/src/builder_spirv.rs +++ b/crates/rustc_codegen_spirv/src/builder_spirv.rs @@ -683,6 +683,11 @@ impl<'tcx> BuilderSpirv<'tcx> { &self, span: Span, ) -> (DebugFileSpirv<'tcx>, Range<(u32, u32)>) { + // HACK(eddyb) this is similar to what `#[track_caller]` does, and it + // allows us to point to the use site of a macro, instead of inside the + // macro (but ideally we would record the entire macro backtrace). + let span = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); + let (lo, hi) = (span.lo(), span.hi()); let lo_loc = self.source_map.lookup_char_pos(lo); diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index dd75cc687c..4a48fb9b1d 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -127,6 +127,10 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { fn const_undef(&self, ty: Self::Type) -> Self::Value { self.undef(ty) } + fn const_poison(&self, ty: Self::Type) -> Self::Value { + // No distinction between undef and poison. + self.const_undef(ty) + } fn const_int(&self, t: Self::Type, i: i64) -> Self::Value { self.constant_int(t, i as u64) } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index f062bbdcf0..0f1d86857f 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -7,6 +7,7 @@ use crate::spirv_type::SpirvType; use rspirv::spirv::{FunctionControl, LinkageType, StorageClass, Word}; use rustc_attr::InlineAttr; use rustc_codegen_ssa::traits::{BaseTypeMethods, PreDefineMethods, StaticMethods}; +use rustc_hir::def::DefKind; use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; @@ -124,8 +125,16 @@ impl<'tcx> CodegenCx<'tcx> { let declared = fn_id.with_type(function_type); - let attrs = - AggregatedSpirvAttributes::parse(self, self.tcx.get_attrs_unchecked(instance.def_id())); + let attrs = AggregatedSpirvAttributes::parse( + self, + match self.tcx.def_kind(instance.def_id()) { + // This was made to ICE cross-crate at some point, but then got + // reverted in https://github.com/rust-lang/rust/pull/111381. + // FIXME(eddyb) remove this workaround once we rustup past that. + DefKind::Closure => &[], + _ => self.tcx.get_attrs_unchecked(instance.def_id()), + }, + ); if let Some(entry) = attrs.entry.map(|attr| attr.value) { let entry_name = entry .name @@ -178,7 +187,12 @@ impl<'tcx> CodegenCx<'tcx> { // HACK(eddyb) there is no good way to identify this definition // (e.g. no `#[lang = "..."]` attribute), but this works well enough. - if demangled_symbol_name == "::new_v1" { + if [ + "::new_v1", + "::new_const", + ] + .contains(&&demangled_symbol_name[..]) + { self.fmt_args_new_fn_ids.borrow_mut().insert(fn_id); } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index 7a23248627..03ef201d45 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -69,7 +69,7 @@ pub struct CodegenCx<'tcx> { // it mandatory even for `panic!("...")` (that were previously separate). pub panic_entry_point_ids: RefCell>, - /// `core::fmt::Arguments::new_v1` instances (for Rust 2021 panics). + /// `core::fmt::Arguments::new_{v1,const}` instances (for Rust 2021 panics). pub fmt_args_new_fn_ids: RefCell>, /// Intrinsic for loading a from a &[u32]. The PassMode is the mode of the . diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index c966120bfb..3e944094be 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -19,7 +19,7 @@ #![feature(assert_matches)] #![feature(result_flattening)] #![feature(lint_reasons)] -#![feature(once_cell)] +#![feature(lazy_cell)] // crate-specific exceptions: #![allow( unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd @@ -104,7 +104,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; use rustc_middle::mir::pretty::write_mir_pretty; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, query, DefIdTree, Instance, InstanceDef, TyCtxt}; +use rustc_middle::ty::{self, query, Instance, InstanceDef, TyCtxt}; use rustc_session::config::{self, OutputFilenames, OutputType}; use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs index 7e78544305..1acfde5cb3 100644 --- a/crates/rustc_codegen_spirv/src/link.rs +++ b/crates/rustc_codegen_spirv/src/link.rs @@ -99,24 +99,14 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa file_list.push(obj); } for lib in codegen_results.crate_info.used_libraries.iter() { - match lib.kind { - NativeLibKind::Static { - bundle: None | Some(true), - .. - } => {} - NativeLibKind::Static { - bundle: Some(false), - .. - } - | NativeLibKind::Dylib { .. } - | NativeLibKind::Framework { .. } - | NativeLibKind::RawDylib - | NativeLibKind::LinkArg - | NativeLibKind::Unspecified => continue, - } - if let Some(name) = lib.name { + if let NativeLibKind::Static { + bundle: None | Some(true), + .. + } = lib.kind + { sess.err(format!( - "Adding native library to rlib not supported yet: {name}" + "adding native library to rlib not supported yet: {}", + lib.name )); } } @@ -441,39 +431,23 @@ fn add_upstream_native_libraries( for &cnum in &codegen_results.crate_info.used_crates { for lib in codegen_results.crate_info.native_libraries[&cnum].iter() { - let name = match lib.name { - Some(l) => l, - None => continue, - }; if !relevant_lib(sess, lib) { continue; } match lib.kind { - NativeLibKind::Dylib { .. } | NativeLibKind::Unspecified => sess.fatal(format!( - "TODO: dylib nativelibkind not supported yet: {name}" - )), - NativeLibKind::Framework { .. } => sess.fatal(format!( - "TODO: framework nativelibkind not supported yet: {name}" - )), NativeLibKind::Static { bundle: Some(false), .. - } => { - if data[cnum.as_usize() - 1] == Linkage::Static { - sess.fatal(format!( - "TODO: staticnobundle nativelibkind not supported yet: {name}" - )) - } - } + } if data[cnum.as_usize() - 1] != Linkage::Static => {} + NativeLibKind::Static { bundle: None | Some(true), .. } => {} - NativeLibKind::RawDylib => { - sess.fatal(format!("raw_dylib feature not yet implemented: {name}")) - } - NativeLibKind::LinkArg => sess.fatal(format!( - "TODO: linkarg nativelibkind not supported yet: {name}" + + _ => sess.fatal(format!( + "`NativeLibKind::{:?}` (name={:?}) not supported yet", + lib.kind, lib.name )), } } diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index bccd24129c..742bdbe3ba 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -195,6 +195,8 @@ pub fn gpu_only(_attr: TokenStream, item: TokenStream) -> TokenStream { block, } = syn::parse_macro_input!(item as syn::ItemFn); + // FIXME(eddyb) this looks like a clippy false positive (`sig` is used below). + #[allow(clippy::redundant_clone)] let fn_name = sig.ident.clone(); let sig_cpu = syn::Signature { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index cb3562fc74..3f12fdf965 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2023-03-04" +channel = "nightly-2023-04-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 44cfafe2fafe816395d3acc434663a45d5178c41 +# commit_hash = 84dd17b56a931a631a23dfd5ef2018fd3ef49108 # Whenever changing the nightly channel, update the commit hash above, and make -# sure to change REQUIRED_TOOLCHAIN in crates/rustc_codegen_spirv/src/build.rs also. +# sure to change `REQUIRED_TOOLCHAIN` in `crates/rustc_codegen_spirv/build.rs` also. diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index 416a87115c..fc05bc31fe 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:2460:9 + --> $CORE_SRC/intrinsics.rs:2724:9 | -2460 | copy(src, dst, count) +2724 | copy(src, dst, count) | ^^^^^^^^^^^^^^^^^^^^^ | note: used from within `core::intrinsics::copy::` - --> $CORE_SRC/intrinsics.rs:2447:21 + --> $CORE_SRC/intrinsics.rs:2710:21 | -2447 | pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { +2710 | 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 diff --git a/tests/ui/dis/ptr_read.stderr b/tests/ui/dis/ptr_read.stderr index c528b471ee..89590afb70 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 1157 8 +OpLine %8 1188 12 %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 c528b471ee..89590afb70 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 1157 8 +OpLine %8 1188 12 %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 97fe1c725a..c981155e3b 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 1354 8 +OpLine %11 1386 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 66e65d6857..35c03ba0b4 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 1354 8 +OpLine %11 1386 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 5d4494ac0c..c44f16c894 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 967 14 +OpLine %12 975 14 %13 = OpBitcast %14 %8 -OpLine %12 967 8 +OpLine %12 975 8 %15 = OpIEqual %16 %13 %17 OpNoLine OpSelectionMerge %18 None diff --git a/tests/ui/spirv-attr/invalid-matrix-type-empty.rs b/tests/ui/spirv-attr/invalid-matrix-type-empty.rs index d43ec4ce3d..f323a3f17a 100644 --- a/tests/ui/spirv-attr/invalid-matrix-type-empty.rs +++ b/tests/ui/spirv-attr/invalid-matrix-type-empty.rs @@ -4,9 +4,7 @@ use spirv_std::spirv; #[spirv(matrix)] -pub struct _EmptyStruct {} +pub struct EmptyStruct {} #[spirv(fragment)] -pub fn _entry() { - let _empty_struct = _EmptyStruct {}; -} +pub fn entry(#[spirv(push_constant)] matrix: &EmptyStruct) {} diff --git a/tests/ui/spirv-attr/invalid-matrix-type-empty.stderr b/tests/ui/spirv-attr/invalid-matrix-type-empty.stderr index 6b4ce892c9..6a02d04dd9 100644 --- a/tests/ui/spirv-attr/invalid-matrix-type-empty.stderr +++ b/tests/ui/spirv-attr/invalid-matrix-type-empty.stderr @@ -1,8 +1,8 @@ error: #[spirv(matrix)] type must have at least two fields --> $DIR/invalid-matrix-type-empty.rs:7:1 | -7 | pub struct _EmptyStruct {} - | ^^^^^^^^^^^^^^^^^^^^^^^ +7 | pub struct EmptyStruct {} + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error