From ac356d437fd06fe10286739355161c8bcb79e4f5 Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Fri, 17 Mar 2023 12:27:16 +0100 Subject: [PATCH 1/5] Upgrade to nightly-2023-02-01 --- crates/rustc_codegen_spirv/build.rs | 4 ++-- crates/rustc_codegen_spirv/src/abi.rs | 14 ++++++++------ .../src/codegen_cx/constant.rs | 15 +++++++-------- crates/rustc_codegen_spirv/src/lib.rs | 1 + rust-toolchain.toml | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index c89575e576..50956f82da 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-01-21" +channel = "nightly-2023-02-01" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 5ce39f42bd2c8bca9c570f0560ebe1fce4eddb14"#; +# commit_hash = dc1d9d50fba2f6a1ccab8748a0050cde38253f60"#; 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 d1fcfab0c0..4681daf3f8 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -44,11 +44,13 @@ pub(crate) fn provide(providers: &mut Providers) { // We can't capture the old fn_sig and just call that, because fn_sig is a `fn`, not a `Fn`, i.e. it can't // capture variables. Fortunately, the defaults are exposed (thanks rustdoc), so use that instead. let result = (rustc_interface::DEFAULT_QUERY_PROVIDERS.fn_sig)(tcx, def_id); - result.map_bound(|mut inner| { - if let SpecAbi::C { .. } = inner.abi { - inner.abi = SpecAbi::Unadjusted; - } - inner + result.map_bound(|outer| { + outer.map_bound(|mut inner| { + if let SpecAbi::C { .. } = inner.abi { + inner.abi = SpecAbi::Unadjusted; + } + inner + }) }) }; @@ -502,7 +504,7 @@ fn trans_scalar<'tcx>( } Primitive::F32 => SpirvType::Float(32).def(span, cx), Primitive::F64 => SpirvType::Float(64).def(span, cx), - Primitive::Pointer => { + Primitive::Pointer(_) => { let pointee_ty = dig_scalar_pointee(cx, ty, offset); // Pointers can be recursive. So, record what we're currently translating, and if we're already translating // the same type, emit an OpTypeForwardPointer and use that ID. diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index 34267e7655..93bf42e157 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -250,7 +250,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { assert_eq!(res.ty, ty); res } - Primitive::Pointer => { + Primitive::Pointer(_) => { if data == 0 { self.constant_null(ty) } else { @@ -317,14 +317,13 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { // let offset = self.constant_u64(ptr.offset.bytes()); // self.gep(base_addr, once(offset)) }; - if layout.primitive() != Primitive::Pointer { + if let Primitive::Pointer(_) = layout.primitive() { + assert_ty_eq!(self, value.ty, ty); + value + } else { self.tcx .sess .fatal("Non-pointer-typed scalar_to_backend Scalar::Ptr not supported"); - // unsafe { llvm::LLVMConstPtrToInt(llval, llty) } - } else { - assert_ty_eq!(self, value.ty, ty); - value } } } @@ -440,7 +439,7 @@ impl<'tcx> CodegenCx<'tcx> { .fatal(format!("invalid size for float: {other}")); } }, - SpirvType::Pointer { .. } => Primitive::Pointer, + SpirvType::Pointer { .. } => Primitive::Pointer(AddressSpace::DATA), unsupported_spirv_type => bug!( "invalid spirv type internal to create_alloc_const2: {:?}", unsupported_spirv_type @@ -454,7 +453,7 @@ impl<'tcx> CodegenCx<'tcx> { let value = match alloc.inner().read_scalar( self, alloc_range(*offset, size), - primitive.is_ptr(), + matches!(primitive, Primitive::Pointer(_)), ) { Ok(scalar) => { self.scalar_to_backend(scalar, self.primitive_to_scalar(primitive), ty) diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index 77b537ac08..10fdbb9406 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -284,6 +284,7 @@ impl CodegenBackend for SpirvCodegenBackend { impl WriteBackendMethods for SpirvCodegenBackend { type Module = Vec; type TargetMachine = (); + type TargetMachineError = String; type ModuleBuffer = SpirvModuleBuffer; type ThinData = (); type ThinBuffer = SpirvThinBuffer; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 65de5c2709..c0540c69a2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2023-01-21" +channel = "nightly-2023-02-01" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 5ce39f42bd2c8bca9c570f0560ebe1fce4eddb14 +# commit_hash = dc1d9d50fba2f6a1ccab8748a0050cde38253f60 # 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. From cec07bb092f62d87e8cfb336f90c9b481d49278c Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Fri, 17 Mar 2023 12:47:01 +0100 Subject: [PATCH 2/5] Upgrade to nightly-2023-02-15 --- crates/rustc_codegen_spirv/build.rs | 4 ++-- crates/rustc_codegen_spirv/src/linker/test.rs | 3 ++- rust-toolchain.toml | 4 ++-- tests/ui/arch/debug_printf_type_checking.stderr | 2 +- tests/ui/dis/ptr_copy.normal.stderr | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index 50956f82da..3421809057 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-02-01" +channel = "nightly-2023-02-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = dc1d9d50fba2f6a1ccab8748a0050cde38253f60"#; +# commit_hash = 0416b1a6f6d5c42696494e1a3a33580fd3f669d8"#; 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/linker/test.rs b/crates/rustc_codegen_spirv/src/linker/test.rs index a8bd254726..70d4fc8229 100644 --- a/crates/rustc_codegen_spirv/src/linker/test.rs +++ b/crates/rustc_codegen_spirv/src/linker/test.rs @@ -1,7 +1,7 @@ use super::{link, LinkResult}; use pipe::pipe; use rspirv::dr::{Loader, Module}; -use rustc_errors::registry::Registry; +use rustc_errors::{registry::Registry, TerminalUrl}; use rustc_session::{config::Input, CompilerIO}; use rustc_span::FileName; use std::io::Read; @@ -169,6 +169,7 @@ fn link_with_linker_opts( None, false, false, + TerminalUrl::No, ); rustc_errors::Handler::with_emitter_and_flags( diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c0540c69a2..e2f5169fd8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2023-02-01" +channel = "nightly-2023-02-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = dc1d9d50fba2f6a1ccab8748a0050cde38253f60 +# commit_hash = 0416b1a6f6d5c42696494e1a3a33580fd3f669d8 # 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. diff --git a/tests/ui/arch/debug_printf_type_checking.stderr b/tests/ui/arch/debug_printf_type_checking.stderr index 58cbef183f..228b6ad358 100644 --- a/tests/ui/arch/debug_printf_type_checking.stderr +++ b/tests/ui/arch/debug_printf_type_checking.stderr @@ -143,7 +143,7 @@ error[E0308]: mismatched types 24 | debug_printf!("%f", Vec2::splat(33.3)); | --------------------^^^^^^^^^^^^^^^^^- | | | - | | expected `f32`, found struct `Vec2` + | | expected `f32`, found `Vec2` | arguments to this function are incorrect | help: the return type of this call is `Vec2` due to the type of the argument passed diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index 40eb74cbe5..26f874bdef 100644 --- a/tests/ui/dis/ptr_copy.normal.stderr +++ b/tests/ui/dis/ptr_copy.normal.stderr @@ -1,7 +1,7 @@ error: Cannot memcpy dynamically sized data - --> $CORE_SRC/intrinsics.rs:2458:9 + --> $CORE_SRC/intrinsics.rs:2456:9 | -2458 | copy(src, dst, count) +2456 | copy(src, dst, count) | ^^^^^^^^^^^^^^^^^^^^^ | = note: Stack: From 5d9c96a5b86e32c746443364d0c3f78690129e7d Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Fri, 17 Mar 2023 15:31:24 +0100 Subject: [PATCH 3/5] Upgrade to nightly-03-04 --- crates/rustc_codegen_spirv/build.rs | 4 ++-- crates/rustc_codegen_spirv/src/abi.rs | 4 ++-- .../rustc_codegen_spirv/src/builder/builder_methods.rs | 2 +- crates/rustc_codegen_spirv/src/builder/intrinsics.rs | 9 ++++++++- crates/rustc_codegen_spirv/src/codegen_cx/declare.rs | 2 +- crates/rustc_codegen_spirv/src/lib.rs | 4 ++++ crates/rustc_codegen_spirv/src/linker/test.rs | 3 ++- crates/rustc_codegen_spirv/src/symbols.rs | 8 ++++---- rust-toolchain.toml | 4 ++-- tests/ui/dis/ptr_copy.normal.stderr | 4 ++-- tests/ui/lang/issue-836.rs | 2 +- 11 files changed, 29 insertions(+), 17 deletions(-) diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index 3421809057..4bdb7d2570 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-02-15" +channel = "nightly-2023-03-04" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 0416b1a6f6d5c42696494e1a3a33580fd3f669d8"#; +# commit_hash = 44cfafe2fafe816395d3acc434663a45d5178c41"#; 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 4681daf3f8..b320dffac1 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -96,7 +96,7 @@ pub(crate) fn provide(providers: &mut Providers) { // FIXME(eddyb) remove this by deriving `Clone` for `LayoutS` upstream. // FIXME(eddyb) the `S` suffix is a naming antipattern, rename upstream. - fn clone_layout(layout: &LayoutS) -> LayoutS { + fn clone_layout(layout: &LayoutS) -> LayoutS { let LayoutS { ref fields, ref variants, @@ -160,7 +160,7 @@ pub(crate) fn provide(providers: &mut Providers) { }; if hide_niche { - layout = tcx.intern_layout(LayoutS { + layout = tcx.mk_layout(LayoutS { largest_niche: None, ..clone_layout(layout.0 .0) }); diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index db4470374b..a4fe63db38 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -940,7 +940,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { OverflowOp::Mul => (self.mul(lhs, rhs), fals), }; self.zombie( - result.0.def(self), + result.1.def(self), match oop { OverflowOp::Add => "checked add is not supported yet", OverflowOp::Sub => "checked sub is not supported yet", diff --git a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs index 9e283bc7fe..705887c87e 100644 --- a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs +++ b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs @@ -314,7 +314,14 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> { let res3 = self.or(res3, res4); self.or(res1, res3) } - other => self.fatal(&format!("bswap not implemented for int width {other}")), + other => { + let undef = self.undef(ret_ty); + self.zombie( + undef.def(self), + &format!("bswap not implemented for int width {other}"), + ); + undef + } } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index ef139f0002..7757eecace 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -10,7 +10,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, TypeVisitable}; +use rustc_middle::ty::{self, Instance, ParamEnv, TypeVisitableExt}; use rustc_span::def_id::DefId; use rustc_span::Span; use rustc_target::abi::Align; diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index 10fdbb9406..071cfc8523 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -190,6 +190,10 @@ impl ThinBufferMethods for SpirvThinBuffer { struct SpirvCodegenBackend; impl CodegenBackend for SpirvCodegenBackend { + fn locale_resource(&self) -> &'static str { + rustc_errors::DEFAULT_LOCALE_RESOURCE + } + fn target_features(&self, sess: &Session, _allow_unstable: bool) -> Vec { let cmdline = sess.opts.cg.target_feature.split(','); let cfg = sess.target.options.features.split(','); diff --git a/crates/rustc_codegen_spirv/src/linker/test.rs b/crates/rustc_codegen_spirv/src/linker/test.rs index 70d4fc8229..7fd177a2a1 100644 --- a/crates/rustc_codegen_spirv/src/linker/test.rs +++ b/crates/rustc_codegen_spirv/src/linker/test.rs @@ -144,6 +144,7 @@ fn link_with_linker_opts( None, Registry::new(&[]), Default::default(), + Default::default(), None, None, ); @@ -154,7 +155,7 @@ fn link_with_linker_opts( let fallback_bundle = { extern crate rustc_error_messages; rustc_error_messages::fallback_fluent_bundle( - rustc_errors::DEFAULT_LOCALE_RESOURCES, + Vec::new(), sess.opts.unstable_opts.translate_directionality_markers, ) }; diff --git a/crates/rustc_codegen_spirv/src/symbols.rs b/crates/rustc_codegen_spirv/src/symbols.rs index 9d5ea4a460..4b9d5429c7 100644 --- a/crates/rustc_codegen_spirv/src/symbols.rs +++ b/crates/rustc_codegen_spirv/src/symbols.rs @@ -432,7 +432,7 @@ pub(crate) fn parse_attrs_for_checking<'a>( "unknown `rust_gpu` attribute, expected `rust_gpu::spirv`" .to_string(), ))), - Vec::new(), + Default::default(), ) } else if let Some(args) = attr.meta_item_list() { // #[rust_gpu::spirv(...)] @@ -445,15 +445,15 @@ pub(crate) fn parse_attrs_for_checking<'a>( "#[rust_gpu::spirv(..)] attribute must have at least one argument" .to_string(), ))), - Vec::new(), + Default::default(), ) } } else { // #[...] but not #[rust_gpu ...] - (None, Vec::new()) + (None, Default::default()) } } - AttrKind::DocComment(..) => (None, Vec::new()), // doccomment + AttrKind::DocComment(..) => (None, Default::default()), // doccomment }; whole_attr_error diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e2f5169fd8..cb3562fc74 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2023-02-15" +channel = "nightly-2023-03-04" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -# commit_hash = 0416b1a6f6d5c42696494e1a3a33580fd3f669d8 +# commit_hash = 44cfafe2fafe816395d3acc434663a45d5178c41 # 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. diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index 26f874bdef..c9f66e2d67 100644 --- a/tests/ui/dis/ptr_copy.normal.stderr +++ b/tests/ui/dis/ptr_copy.normal.stderr @@ -1,7 +1,7 @@ error: Cannot memcpy dynamically sized data - --> $CORE_SRC/intrinsics.rs:2456:9 + --> $CORE_SRC/intrinsics.rs:2460:9 | -2456 | copy(src, dst, count) +2460 | copy(src, dst, count) | ^^^^^^^^^^^^^^^^^^^^^ | = note: Stack: diff --git a/tests/ui/lang/issue-836.rs b/tests/ui/lang/issue-836.rs index 1919fa3b32..967d672265 100644 --- a/tests/ui/lang/issue-836.rs +++ b/tests/ui/lang/issue-836.rs @@ -34,7 +34,7 @@ pub fn main( let newtype_slice = Newtype(slice); *out = newtype_slice.get()[0]; *out += newtype_slice.slice_get()[1]; - *out += newtype_slice.deref_index(2); + *out += *newtype_slice.deref_index(2); let newtype_custom_pair = Newtype(CustomPair(*out, *out + 1)); *out += newtype_custom_pair.get().0; From 6da72c2531ed1fb75894324e122557d1a3091c64 Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Tue, 21 Mar 2023 13:20:00 +0100 Subject: [PATCH 4/5] Update tests/ui/lang/issue-836.rs Co-authored-by: Eduard-Mihai Burtescu --- tests/ui/lang/issue-836.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/lang/issue-836.rs b/tests/ui/lang/issue-836.rs index 967d672265..1919fa3b32 100644 --- a/tests/ui/lang/issue-836.rs +++ b/tests/ui/lang/issue-836.rs @@ -34,7 +34,7 @@ pub fn main( let newtype_slice = Newtype(slice); *out = newtype_slice.get()[0]; *out += newtype_slice.slice_get()[1]; - *out += *newtype_slice.deref_index(2); + *out += newtype_slice.deref_index(2); let newtype_custom_pair = Newtype(CustomPair(*out, *out + 1)); *out += newtype_custom_pair.get().0; From 985495e937d3d3a9b0d3afa0f198fc69649c7c3b Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Tue, 21 Mar 2023 13:25:08 +0100 Subject: [PATCH 5/5] Reinstated comment --- crates/rustc_codegen_spirv/src/codegen_cx/constant.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index 93bf42e157..28b82a995d 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -324,6 +324,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { self.tcx .sess .fatal("Non-pointer-typed scalar_to_backend Scalar::Ptr not supported"); + // unsafe { llvm::LLVMConstPtrToInt(llval, llty) } } } }