diff --git a/CHANGELOG.md b/CHANGELOG.md index ff056aada0..c1bc2c3555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed 🛠 -- [PR#1109](https://github.com/EmbarkStudios/rust-gpu/pull/1109) updated toolchain to `nightly-2023-12-16` +- [PR#1109](https://github.com/EmbarkStudios/rust-gpu/pull/1109) updated toolchain to `nightly-2023-12-31` - [PR#1100](https://github.com/EmbarkStudios/rust-gpu/pull/1100) updated toolchain to `nightly-2023-09-30` - [PR#1091](https://github.com/EmbarkStudios/rust-gpu/pull/1091) updated toolchain to `nightly-2023-08-29` - [PR#1085](https://github.com/EmbarkStudios/rust-gpu/pull/1085) updated toolchain to `nightly-2023-07-08` diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index 3f8886e383..432e3a6dab 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.toml"); const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain] -channel = "nightly-2023-12-16" +channel = "nightly-2023-12-31" components = ["rust-src", "rustc-dev", "llvm-tools"] -# commit_hash = a96d57bdb6d2bb6d233d7d5aaefc2995ab99be01"#; +# commit_hash = 2a3e63551fe21458637480a97b65a2d15dec8062"#; 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 38586dc9aa..f6a82a86fb 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -580,7 +580,7 @@ fn dig_scalar_pointee<'tcx>( let new_pointee = dig_scalar_pointee(cx, field, offset - field_offset); match pointee { Some(old_pointee) if old_pointee != new_pointee => { - cx.tcx.sess.fatal(format!( + cx.tcx.dcx().fatal(format!( "dig_scalar_pointee: unsupported Pointer with different \ pointee types ({old_pointee:?} vs {new_pointee:?}) at offset {offset:?} in {layout:#?}" )); @@ -728,7 +728,7 @@ fn trans_struct<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>) - if i == 0 { field_names.push(cx.sym.discriminant); } else { - cx.tcx.sess.fatal("Variants::Multiple has multiple fields") + cx.tcx.dcx().fatal("Variants::Multiple has multiple fields") } }; } @@ -784,7 +784,7 @@ impl fmt::Display for TyLayoutNameKey<'_> { write!(f, "::{}", def.variants()[index].name)?; } } - if let (TyKind::Coroutine(_, _, _), Some(index)) = (self.ty.kind(), self.variant) { + if let (TyKind::Coroutine(_, _), Some(index)) = (self.ty.kind(), self.variant) { write!(f, "::{}", CoroutineArgs::variant_name(index))?; } Ok(()) @@ -804,7 +804,7 @@ fn trans_intrinsic_type<'tcx>( if ty.size != Size::from_bytes(4) { return Err(cx .tcx - .sess + .dcx() .err("#[spirv(generic_image)] type must have size 4")); } @@ -848,7 +848,7 @@ fn trans_intrinsic_type<'tcx>( _ => { return Err(cx .tcx - .sess + .dcx() .span_err(span, "Invalid sampled type to `Image`.")); } }; @@ -871,7 +871,7 @@ fn trans_intrinsic_type<'tcx>( Some(v) => Ok(v), None => Err(cx .tcx - .sess + .dcx() .err(format!("Invalid value for Image const generic: {value}"))), } } @@ -897,7 +897,7 @@ fn trans_intrinsic_type<'tcx>( IntrinsicType::Sampler => { // see SpirvType::sizeof if ty.size != Size::from_bytes(4) { - return Err(cx.tcx.sess.err("#[spirv(sampler)] type must have size 4")); + return Err(cx.tcx.dcx().err("#[spirv(sampler)] type must have size 4")); } Ok(SpirvType::Sampler.def(span, cx)) } @@ -910,7 +910,7 @@ fn trans_intrinsic_type<'tcx>( if ty.size != Size::from_bytes(4) { return Err(cx .tcx - .sess + .dcx() .err("#[spirv(sampled_image)] type must have size 4")); } @@ -923,7 +923,7 @@ fn trans_intrinsic_type<'tcx>( } else { Err(cx .tcx - .sess + .dcx() .err("#[spirv(sampled_image)] type must have a generic image type")) } } @@ -931,7 +931,7 @@ fn trans_intrinsic_type<'tcx>( if ty.size != Size::from_bytes(4) { return Err(cx .tcx - .sess + .dcx() .err("#[spirv(runtime_array)] type must have size 4")); } @@ -943,7 +943,7 @@ fn trans_intrinsic_type<'tcx>( } else { Err(cx .tcx - .sess + .dcx() .err("#[spirv(runtime_array)] type must have a generic element type")) } } @@ -958,12 +958,12 @@ fn trans_intrinsic_type<'tcx>( if field_types.len() < 2 { return Err(cx .tcx - .sess + .dcx() .span_err(span, "#[spirv(matrix)] type must have at least two fields")); } let elem_type = field_types[0]; if !field_types.iter().all(|&ty| ty == elem_type) { - return Err(cx.tcx.sess.span_err( + return Err(cx.tcx.dcx().span_err( span, "#[spirv(matrix)] type fields must all be the same type", )); @@ -973,7 +973,7 @@ fn trans_intrinsic_type<'tcx>( ty => { return Err(cx .tcx - .sess + .dcx() .struct_span_err(span, "#[spirv(matrix)] type fields must all be vectors") .note(format!("field type is {}", ty.debug(elem_type, cx))) .emit()); diff --git a/crates/rustc_codegen_spirv/src/attr.rs b/crates/rustc_codegen_spirv/src/attr.rs index b59f683aa7..a7c16f9139 100644 --- a/crates/rustc_codegen_spirv/src/attr.rs +++ b/crates/rustc_codegen_spirv/src/attr.rs @@ -154,7 +154,7 @@ impl AggregatedSpirvAttributes { let (span, parsed_attr) = match parse_attr_result { Ok(span_and_parsed_attr) => span_and_parsed_attr, Err((span, msg)) => { - cx.tcx.sess.span_delayed_bug(span, msg); + cx.tcx.dcx().span_delayed_bug(span, msg); continue; } }; @@ -165,7 +165,7 @@ impl AggregatedSpirvAttributes { category, }) => { cx.tcx - .sess + .dcx() .span_delayed_bug(span, format!("multiple {category} attributes")); } } @@ -278,7 +278,7 @@ impl CheckSpirvAttrVisitor<'_> { let (span, parsed_attr) = match parse_attr_result { Ok(span_and_parsed_attr) => span_and_parsed_attr, Err((span, msg)) => { - self.tcx.sess.span_err(span, msg); + self.tcx.dcx().span_err(span, msg); continue; } }; @@ -323,7 +323,7 @@ impl CheckSpirvAttrVisitor<'_> { .filter_map(|r| r.ok()) .any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_))); if !parent_is_entry_point { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, "attribute is only valid on a parameter of an entry-point function", ); @@ -346,7 +346,7 @@ impl CheckSpirvAttrVisitor<'_> { }; if let Err(msg) = valid { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!("`{storage_class:?}` storage class {msg}"), ); @@ -367,7 +367,7 @@ impl CheckSpirvAttrVisitor<'_> { }; match valid_target { Err(Expected(expected_target)) => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!( "attribute is only valid on a {expected_target}, not on a {target}" @@ -381,7 +381,7 @@ impl CheckSpirvAttrVisitor<'_> { category, }) => { self.tcx - .sess + .dcx() .struct_span_err( span, format!("only one {category} attribute is allowed on a {target}"), @@ -397,7 +397,7 @@ impl CheckSpirvAttrVisitor<'_> { // so we can perform further checks, emit warnings, etc. if let Some(block_attr) = aggregated_attrs.block { - self.tcx.sess.span_warn( + self.tcx.dcx().span_warn( block_attr.span, "#[spirv(block)] is no longer needed and should be removed", ); diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index 4e1cad8186..efd1d7056d 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -2282,7 +2282,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { order: AtomicOrdering, failure_order: AtomicOrdering, _weak: bool, - ) -> Self::Value { + ) -> (Self::Value, Self::Value) { assert_ty_eq!(self, cmp.ty, src.ty); let ty = src.ty; @@ -2310,7 +2310,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { ) .unwrap() .with_type(access_ty); - self.bitcast(result, ty) + let result = self.bitcast(result, ty); + + let val = self.extract_value(result, 0); + let success = self.extract_value(result, 1); + + (val, success) } fn atomic_rmw( @@ -2987,7 +2992,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { Err(FormatArgsNotRecognized(step)) => { if let Some(current_span) = self.current_span { - let mut warn = self.tcx.sess.struct_span_warn( + let mut warn = self.tcx.dcx().struct_span_warn( current_span, "failed to find and remove `format_args!` construction for this `panic!`", ); diff --git a/crates/rustc_codegen_spirv/src/builder/mod.rs b/crates/rustc_codegen_spirv/src/builder/mod.rs index 9d46ea3fd5..b0d6ae1a8b 100644 --- a/crates/rustc_codegen_spirv/src/builder/mod.rs +++ b/crates/rustc_codegen_spirv/src/builder/mod.rs @@ -20,7 +20,7 @@ use rustc_codegen_ssa::traits::{ AbiBuilderMethods, ArgAbiMethods, BackendTypes, BuilderMethods, CoverageInfoBuilderMethods, DebugInfoBuilderMethods, HasCodegen, StaticBuilderMethods, TypeMembershipMethods, }; -use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed}; +use rustc_errors::{DiagnosticBuilder, DiagnosticMessage}; use rustc_middle::mir::Coverage; use rustc_middle::span_bug; use rustc_middle::ty::layout::{ @@ -69,32 +69,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } #[track_caller] - pub fn struct_err( - &self, - msg: impl Into, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + pub fn struct_err(&self, msg: impl Into) -> DiagnosticBuilder<'_> { if let Some(current_span) = self.current_span { - self.tcx.sess.struct_span_err(current_span, msg) + self.tcx.dcx().struct_span_err(current_span, msg) } else { - self.tcx.sess.struct_err(msg) + self.tcx.dcx().struct_err(msg) } } #[track_caller] pub fn err(&self, msg: impl Into) { if let Some(current_span) = self.current_span { - self.tcx.sess.span_err(current_span, msg); + self.tcx.dcx().span_err(current_span, msg); } else { - self.tcx.sess.err(msg); + self.tcx.dcx().err(msg); } } #[track_caller] pub fn fatal(&self, msg: impl Into) -> ! { if let Some(current_span) = self.current_span { - self.tcx.sess.span_fatal(current_span, msg) + self.tcx.dcx().span_fatal(current_span, msg) } else { - self.tcx.sess.fatal(msg) + self.tcx.dcx().fatal(msg) } } diff --git a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs index 97c4d9cfa1..52fa469314 100644 --- a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs +++ b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> { } => { if let Some(modifier) = modifier { self.tcx - .sess + .dcx() .span_err(span, format!("asm modifiers are not supported: {modifier}")); } let line = tokens.last_mut().unwrap(); @@ -455,7 +455,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } Token::Placeholder(_, span) | Token::Typeof(_, span, _) => { self.tcx - .sess + .dcx() .span_err(span, "cannot use a dynamic value as an instruction type"); return; } @@ -582,7 +582,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { )); } if tokens.next().is_some() { - self.tcx.sess.err(format!( + self.tcx.dcx().err(format!( "too many operands to instruction: {}", instruction.class.opname )); @@ -798,7 +798,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { )) => {} _ => { self.tcx - .sess + .dcx() .span_err(span, format!("invalid register: {reg}")); } } @@ -831,7 +831,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } Token::Typeof(_, span, _) => { self.tcx - .sess + .dcx() .span_err(span, "cannot assign to a typeof expression"); None } @@ -839,7 +839,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { InlineAsmOperandRef::In { reg, value: _ } => { self.check_reg(span, reg); self.tcx - .sess + .dcx() .span_err(span, "in register cannot be assigned to"); None } @@ -852,7 +852,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { match place { Some(place) => Some(OutRegister::Place(*place)), None => { - self.tcx.sess.span_err(span, "missing place for register"); + self.tcx.dcx().span_err(span, "missing place for register"); None } } @@ -867,26 +867,26 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { match out_place { Some(out_place) => Some(OutRegister::Place(*out_place)), None => { - self.tcx.sess.span_err(span, "missing place for register"); + self.tcx.dcx().span_err(span, "missing place for register"); None } } } InlineAsmOperandRef::Const { string: _ } => { self.tcx - .sess + .dcx() .span_err(span, "cannot write to const asm argument"); None } InlineAsmOperandRef::SymFn { instance: _ } => { self.tcx - .sess + .dcx() .span_err(span, "cannot write to function asm argument"); None } InlineAsmOperandRef::SymStatic { def_id: _ } => { self.tcx - .sess + .dcx() .span_err(span, "cannot write to static variable asm argument"); None } @@ -921,7 +921,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { TypeofKind::Dereference => match self.lookup_type(ty) { SpirvType::Pointer { pointee } => pointee, other => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!( "cannot use typeof* on non-pointer type: {}", @@ -943,7 +943,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { Some(place) => match self.lookup_type(place.llval.ty) { SpirvType::Pointer { pointee } => Some(pointee), other => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!( "out register type not pointer: {}", @@ -955,7 +955,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { }, None => { self.tcx - .sess + .dcx() .span_err(span, "missing place for out register typeof"); None } @@ -972,18 +972,18 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } InlineAsmOperandRef::Const { string: _ } => { self.tcx - .sess + .dcx() .span_err(span, "cannot take the type of a const asm argument"); None } InlineAsmOperandRef::SymFn { instance: _ } => { self.tcx - .sess + .dcx() .span_err(span, "cannot take the type of a function asm argument"); None } InlineAsmOperandRef::SymStatic { def_id: _ } => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, "cannot take the type of a static variable asm argument", ); @@ -1002,7 +1002,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } => { self.check_reg(span, reg); self.tcx - .sess + .dcx() .span_err(span, "out register cannot be used as a value"); None } @@ -1017,19 +1017,19 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } InlineAsmOperandRef::Const { string: _ } => { self.tcx - .sess + .dcx() .span_err(span, "const asm argument not supported yet"); None } InlineAsmOperandRef::SymFn { instance: _ } => { self.tcx - .sess + .dcx() .span_err(span, "function asm argument not supported yet"); None } InlineAsmOperandRef::SymStatic { def_id: _ } => { self.tcx - .sess + .dcx() .span_err(span, "static variable asm argument not supported yet"); None } @@ -1161,13 +1161,13 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { self.err(format!("expected a literal, not a string for a {kind:?}")); } Some(Token::Placeholder(_, span)) => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!("expected a literal, not a dynamic value for a {kind:?}"), ); } Some(Token::Typeof(_, span, _)) => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!("expected a literal, not a type for a {kind:?}"), ); @@ -1363,13 +1363,13 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { self.err(format!("expected a literal, not a string for a {kind:?}")); } Token::Placeholder(_, span) => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!("expected a literal, not a dynamic value for a {kind:?}"), ); } Token::Typeof(_, span, _) => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!("expected a literal, not a type for a {kind:?}"), ); diff --git a/crates/rustc_codegen_spirv/src/builder_spirv.rs b/crates/rustc_codegen_spirv/src/builder_spirv.rs index 7d6249cafc..9064a38a92 100644 --- a/crates/rustc_codegen_spirv/src/builder_spirv.rs +++ b/crates/rustc_codegen_spirv/src/builder_spirv.rs @@ -163,7 +163,7 @@ impl SpirvValue { SpirvValueKind::IllegalTypeUsed(id) => { cx.tcx - .sess + .dcx() .struct_span_err(span, "Can't use type as a value") .note(format!("Type: *{}", cx.debug_type(id))) .emit(); @@ -367,7 +367,7 @@ impl Eq for DebugFileKey {} impl Hash for DebugFileKey { fn hash(&self, state: &mut H) { let Self(sf) = self; - sf.name_hash.hash(state); + sf.stable_id.hash(state); sf.src_hash.hash(state); } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index eed04cd4c1..ba123ea594 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -64,7 +64,7 @@ impl<'tcx> CodegenCx<'tcx> { 0 | 1 => self.def_constant(ty, SpirvConst::Bool(val != 0)), _ => self .tcx - .sess + .dcx() .fatal(format!("Invalid constant value for bool: {val}")), }, SpirvType::Integer(128, _) => { @@ -72,7 +72,7 @@ impl<'tcx> CodegenCx<'tcx> { self.zombie_no_span(result.def_cx(self), "u128 constant"); result } - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "constant_int invalid on type {}", other.debug(ty, self) )), @@ -93,7 +93,7 @@ impl<'tcx> CodegenCx<'tcx> { match self.lookup_type(ty) { SpirvType::Float(32) => self.def_constant(ty, SpirvConst::F32((val as f32).to_bits())), SpirvType::Float(64) => self.def_constant(ty, SpirvConst::F64(val.to_bits())), - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "constant_float invalid on type {}", other.debug(ty, self) )), @@ -257,10 +257,10 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { 1 => self.constant_bool(DUMMY_SP, true), _ => self .tcx - .sess + .dcx() .fatal(format!("Invalid constant value for bool: {data}")), }, - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "scalar_to_backend Primitive::Int not supported on type {}", other.debug(ty, self) )), @@ -296,7 +296,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { GlobalAlloc::Memory(alloc) => { let pointee = match self.lookup_type(ty) { SpirvType::Pointer { pointee } => pointee, - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "GlobalAlloc::Memory type not implemented: {}", other.debug(ty, self) )), @@ -316,7 +316,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { .unwrap_memory(); let pointee = match self.lookup_type(ty) { SpirvType::Pointer { pointee } => pointee, - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "GlobalAlloc::VTable type not implemented: {}", other.debug(ty, self) )), @@ -335,7 +335,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { base_addr } else { self.tcx - .sess + .dcx() .fatal("Non-zero scalar_to_backend ptr.offset not supported") // let offset = self.constant_u64(ptr.offset.bytes()); // self.gep(base_addr, once(offset)) @@ -345,7 +345,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { value } else { self.tcx - .sess + .dcx() .fatal("Non-pointer-typed scalar_to_backend Scalar::Ptr not supported"); // unsafe { llvm::LLVMConstPtrToInt(llval, llty) } } @@ -447,7 +447,7 @@ impl<'tcx> CodegenCx<'tcx> { match ty_concrete { SpirvType::Void => self .tcx - .sess + .dcx() .fatal("cannot create const alloc of type void"), SpirvType::Bool | SpirvType::Integer(..) @@ -465,7 +465,7 @@ impl<'tcx> CodegenCx<'tcx> { 128 => Integer::I128, other => { self.tcx - .sess + .dcx() .fatal(format!("invalid size for integer: {other}")); } }; @@ -476,7 +476,7 @@ impl<'tcx> CodegenCx<'tcx> { 64 => Primitive::F64, other => { self.tcx - .sess + .dcx() .fatal(format!("invalid size for float: {other}")); } }, @@ -602,26 +602,26 @@ impl<'tcx> CodegenCx<'tcx> { } SpirvType::Function { .. } => self .tcx - .sess + .dcx() .fatal("TODO: SpirvType::Function not supported yet in create_const_alloc"), - SpirvType::Image { .. } => self.tcx.sess.fatal("cannot create a constant image value"), + SpirvType::Image { .. } => self.tcx.dcx().fatal("cannot create a constant image value"), SpirvType::Sampler => self .tcx - .sess + .dcx() .fatal("cannot create a constant sampler value"), SpirvType::SampledImage { .. } => self .tcx - .sess + .dcx() .fatal("cannot create a constant sampled image value"), SpirvType::InterfaceBlock { .. } => self .tcx - .sess + .dcx() .fatal("cannot create a constant interface block value"), SpirvType::AccelerationStructureKhr => self .tcx - .sess + .dcx() .fatal("cannot create a constant acceleration structure"), - SpirvType::RayQueryKhr => self.tcx.sess.fatal("cannot create a constant ray query"), + SpirvType::RayQueryKhr => self.tcx.dcx().fatal("cannot create a constant ray query"), } } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index 0786c22835..a927cc1259 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -167,7 +167,7 @@ impl<'tcx> CodegenCx<'tcx> { self.libm_intrinsics.borrow_mut().insert(fn_id, intrinsic); } None => { - self.tcx.sess.err(format!( + self.tcx.dcx().err(format!( "missing libm intrinsic {symbol_name}, which is {instance}" )); } @@ -279,7 +279,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { Linkage::External => Some(LinkageType::Export), Linkage::Internal => None, other => { - self.tcx.sess.err(format!( + self.tcx.dcx().err(format!( "TODO: Linkage type {other:?} not supported yet for static var symbol {symbol_name}" )); None @@ -308,7 +308,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { Linkage::External | Linkage::WeakAny => Some(LinkageType::Export), Linkage::Internal => None, other => { - self.tcx.sess.err(format!( + self.tcx.dcx().err(format!( "TODO: Linkage type {other:?} not supported yet for function symbol {symbol_name}" )); None @@ -340,7 +340,7 @@ impl<'tcx> StaticMethods for CodegenCx<'tcx> { }; let value_ty = match self.lookup_type(g.ty) { SpirvType::Pointer { pointee } => pointee, - other => self.tcx.sess.fatal(format!( + other => self.tcx.dcx().fatal(format!( "global had non-pointer type {}", other.debug(g.ty, self) )), diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs index 04e8268568..7af4d77aaf 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs @@ -75,7 +75,7 @@ impl<'tcx> CodegenCx<'tcx> { id } else { self.tcx - .sess + .dcx() .span_err(span, format!("cannot declare {name} as an entry point")); return; }; @@ -93,7 +93,7 @@ impl<'tcx> CodegenCx<'tcx> { // the `FnAbi` readjustment to only use `PassMode::Pair` for // pointers to `!Sized` types, but not other `ScalarPair`s. if !matches!(arg_abi.layout.ty.kind(), ty::Ref(..)) { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, format!( "entry point parameter type not yet supported \ @@ -105,7 +105,7 @@ impl<'tcx> CodegenCx<'tcx> { } // FIXME(eddyb) support these (by just ignoring them) - if there // is any validation concern, it should be done on the types. - PassMode::Ignore => self.tcx.sess.span_fatal( + PassMode::Ignore => self.tcx.dcx().span_fatal( hir_param.ty_span, format!( "entry point parameter type not yet supported \ @@ -123,7 +123,7 @@ impl<'tcx> CodegenCx<'tcx> { if fn_abi.ret.layout.ty.is_unit() { assert_matches!(fn_abi.ret.mode, PassMode::Ignore); } else { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!( "entry point should return `()`, not `{}`", @@ -274,7 +274,7 @@ impl<'tcx> CodegenCx<'tcx> { if is_ref { Some(StorageClass::UniformConstant) } else { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, format!( "entry parameter type must be by-reference: `&{}`", @@ -291,7 +291,7 @@ impl<'tcx> CodegenCx<'tcx> { let storage_class = storage_class_attr.value; if !is_ref { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( hir_param.ty_span, format!( "invalid entry param type `{}` for storage class `{storage_class:?}` \ @@ -303,13 +303,13 @@ impl<'tcx> CodegenCx<'tcx> { } match deduced_storage_class_from_ty { - Some(deduced) if storage_class == deduced => self.tcx.sess.span_warn( + Some(deduced) if storage_class == deduced => self.tcx.dcx().span_warn( storage_class_attr.span, "redundant storage class attribute, storage class is deduced from type", ), Some(deduced) => { self.tcx - .sess + .dcx() .struct_span_err(hir_param.span, "storage class mismatch") .span_label( storage_class_attr.span, @@ -338,7 +338,7 @@ impl<'tcx> CodegenCx<'tcx> { .unwrap_or_else(|| match (is_ref, explicit_mutbl) { (false, _) => StorageClass::Input, (true, hir::Mutability::Mut) => StorageClass::Output, - (true, hir::Mutability::Not) => self.tcx.sess.span_fatal( + (true, hir::Mutability::Not) => self.tcx.dcx().span_fatal( hir_param.ty_span, format!( "invalid entry param type `{}` (expected `{}` or `&mut {1}`)", @@ -355,7 +355,7 @@ impl<'tcx> CodegenCx<'tcx> { let storage_class_requires_read_only = expected_mutbl_for(storage_class) == hir::Mutability::Not; if !ref_is_read_only && storage_class_requires_read_only { - let mut err = self.tcx.sess.struct_span_err( + let mut err = self.tcx.dcx().struct_span_err( hir_param.ty_span, format!( "entry-point requires {}...", @@ -395,7 +395,7 @@ impl<'tcx> CodegenCx<'tcx> { let mut storage_class = Ok(storage_class); if let Some(spec_constant) = attrs.spec_constant { if ref_or_value_layout.ty != self.tcx.types.u32 { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, format!( "unsupported `#[spirv(spec_constant)]` type `{}` (expected `{}`)", @@ -403,7 +403,7 @@ impl<'tcx> CodegenCx<'tcx> { ), ); } else if let Some(storage_class) = attrs.storage_class { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( storage_class.span, "`#[spirv(spec_constant)]` cannot have a storage class", ); @@ -494,7 +494,7 @@ impl<'tcx> CodegenCx<'tcx> { // value. We currently only do that with unsized types, so if a type is a pair for some // other reason (e.g. a tuple), we bail. self.tcx - .sess + .dcx() .span_fatal(hir_param.ty_span, "pair type not supported yet") } let var_ptr_spirv_type; @@ -518,7 +518,7 @@ impl<'tcx> CodegenCx<'tcx> { match self.lookup_type(value_spirv_type) { SpirvType::RuntimeArray { .. } => {} _ => { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, "only plain slices are supported as unsized types", ); @@ -538,7 +538,7 @@ impl<'tcx> CodegenCx<'tcx> { // It's OK to use a RuntimeArray and not have a length parameter, but // it's just nicer ergonomics to use a slice. self.tcx - .sess + .dcx() .span_warn(hir_param.ty_span, "use &[T] instead of &RuntimeArray"); } None @@ -552,7 +552,7 @@ impl<'tcx> CodegenCx<'tcx> { match self.lookup_type(value_spirv_type) { SpirvType::RuntimeArray { .. } => { if is_unsized_with_len { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, "uniform_constant must use &RuntimeArray, not &[T]", ); @@ -560,7 +560,7 @@ impl<'tcx> CodegenCx<'tcx> { } _ => { if is_unsized { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, "only plain slices are supported as unsized types", ); @@ -581,7 +581,7 @@ impl<'tcx> CodegenCx<'tcx> { var_ptr_spirv_type = self.type_ptr_to(value_spirv_type); if is_unsized { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( hir_param.ty_span, format!( "unsized types are not supported for {}", @@ -644,7 +644,7 @@ impl<'tcx> CodegenCx<'tcx> { let mut decoration_supersedes_location = false; if let Some(builtin) = attrs.builtin { if let Err(SpecConstant { .. }) = storage_class { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( builtin.span, format!( "`#[spirv(spec_constant)]` cannot be `{:?}` builtin", @@ -661,7 +661,7 @@ impl<'tcx> CodegenCx<'tcx> { } if let Some(descriptor_set) = attrs.descriptor_set { if let Err(SpecConstant { .. }) = storage_class { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( descriptor_set.span, "`#[spirv(descriptor_set = ...)]` cannot apply to `#[spirv(spec_constant)]`", ); @@ -675,7 +675,7 @@ impl<'tcx> CodegenCx<'tcx> { } if let Some(binding) = attrs.binding { if let Err(SpecConstant { .. }) = storage_class { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( binding.span, "`#[spirv(binding = ...)]` cannot apply to `#[spirv(spec_constant)]`", ); @@ -689,7 +689,7 @@ impl<'tcx> CodegenCx<'tcx> { } if let Some(flat) = attrs.flat { if let Err(SpecConstant { .. }) = storage_class { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( flat.span, "`#[spirv(flat)]` cannot apply to `#[spirv(spec_constant)]`", ); @@ -699,7 +699,7 @@ impl<'tcx> CodegenCx<'tcx> { } if let Some(invariant) = attrs.invariant { if storage_class != Ok(StorageClass::Output) { - self.tcx.sess.span_fatal( + self.tcx.dcx().span_fatal( invariant.span, "`#[spirv(invariant)]` is only valid on Output variables", ); @@ -732,17 +732,17 @@ impl<'tcx> CodegenCx<'tcx> { ); } else if is_subpass_input { self.tcx - .sess + .dcx() .span_err(hir_param.ty_span, "Missing capability InputAttachment"); } else { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( attachment_index.span, "#[spirv(input_attachment_index)] is only valid on Image types with dim = SubpassData" ); } decoration_supersedes_location = true; } else if is_subpass_input { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( hir_param.ty_span, "Image types with dim = SubpassData require #[spirv(input_attachment_index)] decoration", ); @@ -839,7 +839,7 @@ impl<'tcx> CodegenCx<'tcx> { && !(is_builtin && matches!(storage_class, StorageClass::Input | StorageClass::Output)) { self.tcx - .sess + .dcx() .span_err(span, "entry-point parameter cannot contain `bool`s"); } @@ -887,7 +887,7 @@ impl<'tcx> CodegenCx<'tcx> { _ => None, }; if let Some((span, must_or_cannot)) = flat_mismatch { - self.tcx.sess.span_err( + self.tcx.dcx().span_err( span, format!( "`{execution_model:?}` entry-point `{storage_class:?}` parameter \ diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index e9a378d038..e784431133 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -106,7 +106,7 @@ impl<'tcx> CodegenCx<'tcx> { .map(|s| s.parse()) .collect::>() .unwrap_or_else(|error| { - tcx.sess.err(error); + tcx.dcx().err(error); Vec::new() }); @@ -269,7 +269,9 @@ impl CodegenArgs { pub fn from_session(sess: &Session) -> Self { match CodegenArgs::parse(&sess.opts.cg.llvm_args) { Ok(ok) => ok, - Err(err) => sess.fatal(format!("Unable to parse llvm-args: {err}")), + Err(err) => sess + .dcx() + .fatal(format!("Unable to parse llvm-args: {err}")), } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs index c6a086c5a9..6b6a57dece 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs @@ -20,7 +20,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'tcx> { #[inline] fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { if let LayoutError::SizeOverflow(_) = err { - self.tcx.sess.span_fatal(span, err.to_string()) + self.tcx.dcx().span_fatal(span, err.to_string()) } else { span_bug!(span, "failed to get layout for `{}`: {}", ty, err) } @@ -38,7 +38,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'tcx> { fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { - self.tcx.sess.emit_fatal(Spanned { span, node: err }) + self.tcx.dcx().emit_fatal(Spanned { span, node: err }) } else { match fn_abi_request { FnAbiRequest::OfFnPtr { sig, extra_args } => { @@ -211,7 +211,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { 64 => TypeKind::Double, other => self .tcx - .sess + .dcx() .fatal(format!("Invalid float width in type_kind: {other}")), }, SpirvType::Adt { .. } | SpirvType::InterfaceBlock { .. } => { @@ -241,7 +241,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { match self.lookup_type(ty) { SpirvType::Pointer { pointee } => pointee, SpirvType::Vector { element, .. } => element, - spirv_type => self.tcx.sess.fatal(format!( + spirv_type => self.tcx.dcx().fatal(format!( "element_type called on invalid type: {spirv_type:?}" )), } @@ -253,7 +253,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { SpirvType::Vector { count, .. } => count as usize, ty => self .tcx - .sess + .dcx() .fatal(format!("vector_length called on non-vector type: {ty:?}")), } } @@ -263,7 +263,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { SpirvType::Float(width) => width as usize, ty => self .tcx - .sess + .dcx() .fatal(format!("float_width called on non-float type: {ty:?}")), } } @@ -274,7 +274,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { SpirvType::Integer(width, _) => width as u64, ty => self .tcx - .sess + .dcx() .fatal(format!("int_width called on non-integer type: {ty:?}")), } } diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index f9635f5c68..864d767394 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -99,7 +99,7 @@ use rustc_codegen_ssa::traits::{ }; use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, ModuleKind}; use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::{ErrorGuaranteed, FatalError, Handler}; +use rustc_errors::{DiagCtxt, ErrorGuaranteed, FatalError}; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::mir::mono::{MonoItem, MonoItemData}; @@ -294,7 +294,7 @@ impl WriteBackendMethods for SpirvCodegenBackend { fn run_link( _cgcx: &CodegenContext, - _diag_handler: &Handler, + _diag_handler: &DiagCtxt, _modules: Vec>, ) -> Result, FatalError> { todo!() @@ -326,7 +326,7 @@ impl WriteBackendMethods for SpirvCodegenBackend { unsafe fn optimize( _: &CodegenContext, - _: &Handler, + _: &DiagCtxt, _: &ModuleCodegen, _: &ModuleConfig, ) -> Result<(), FatalError> { @@ -357,7 +357,7 @@ impl WriteBackendMethods for SpirvCodegenBackend { unsafe fn codegen( cgcx: &CodegenContext, - _diag_handler: &Handler, + _diag_handler: &DiagCtxt, module: ModuleCodegen, _config: &ModuleConfig, ) -> Result { diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs index a926a2ae08..f6237195d8 100644 --- a/crates/rustc_codegen_spirv/src/link.rs +++ b/crates/rustc_codegen_spirv/src/link.rs @@ -9,7 +9,7 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul use rustc_codegen_ssa::back::write::CodegenContext; use rustc_codegen_ssa::{CodegenResults, NativeLib}; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::FatalError; +use rustc_errors::{DiagnosticBuilder, FatalError}; use rustc_metadata::fs::METADATA_FILENAME; use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; @@ -87,7 +87,8 @@ pub fn link( ); } other => { - sess.err(format!("CrateType {other:?} not supported yet")); + sess.dcx() + .err(format!("CrateType {other:?} not supported yet")); } } match out_filename { @@ -124,7 +125,7 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa .. } = lib.kind { - sess.err(format!( + sess.dcx().err(format!( "adding native library to rlib not supported yet: {}", lib.name )); @@ -278,7 +279,7 @@ fn post_link_single_module( (optlevel, false) => format!("optlevel={optlevel:?}"), (optlevel, true) => format!("optlevel={optlevel:?}, debuginfo=None"), }; - sess.warn(format!( + sess.dcx().warn(format!( "`spirv-opt` should have ran ({reason}) but was disabled by `--no-spirv-opt`" )); spv_binary @@ -295,7 +296,9 @@ fn post_link_single_module( let save_modules_timer = sess.timer("link_save_modules"); if let Err(e) = std::fs::write(out_filename, spirv_tools::binary::from_binary(&spv_binary)) { - let mut err = sess.struct_err("failed to serialize spirv-binary to disk"); + let mut err = sess + .dcx() + .struct_err("failed to serialize spirv-binary to disk"); err.note(format!("module `{}`", out_filename.display())); err.note(format!("I/O error: {e:#}")); err.emit(); @@ -343,14 +346,18 @@ fn do_spirv_opt( // TODO: Adds spans here? Not sure how useful with binary, but maybe? let mut err = match msg.level { - Level::Fatal | Level::InternalError => { - // FIXME(eddyb) this was `struct_fatal` but that doesn't seem - // necessary and also lacks `.forget_guarantee()`. - sess.struct_err(msg.message).forget_guarantee() - } - Level::Error => sess.struct_err(msg.message).forget_guarantee(), - Level::Warning => sess.struct_warn(msg.message), - Level::Info | Level::Debug => sess.struct_note(msg.message), + Level::Fatal | Level::InternalError => DiagnosticBuilder::<()>::new( + sess.dcx(), + rustc_errors::Level::Error { lint: false }, + msg.message, + ), + Level::Error => DiagnosticBuilder::<()>::new( + sess.dcx(), + rustc_errors::Level::Error { lint: false }, + msg.message, + ), + Level::Warning => sess.dcx().struct_warn(msg.message), + Level::Info | Level::Debug => sess.dcx().struct_note(msg.message), }; err.note(format!("module `{}`", filename.display())); @@ -363,7 +370,7 @@ fn do_spirv_opt( Ok(spirv_tools::binary::Binary::OwnedU32(words)) => words, Ok(binary) => binary.as_words().to_vec(), Err(e) => { - let mut err = sess.struct_warn(e.to_string()); + let mut err = sess.dcx().struct_warn(e.to_string()); err.note("spirv-opt failed, leaving as unoptimized"); err.note(format!("module `{}`", filename.display())); err.emit(); @@ -383,7 +390,7 @@ fn do_spirv_val( let validator = val::create(sess.target.options.env.parse().ok()); if let Err(e) = validator.validate(spv_binary, Some(options)) { - let mut err = sess.struct_err(e.to_string()); + let mut err = sess.dcx().struct_err(e.to_string()); err.note("spirv-val failed"); err.note(format!("module `{}`", filename.display())); err.emit(); @@ -433,7 +440,7 @@ fn add_upstream_rust_crates( Linkage::Static => rlibs.push(src.rlib.as_ref().unwrap().0.clone()), //Linkage::Dynamic => rlibs.push(src.dylib.as_ref().unwrap().0.clone()), Linkage::Dynamic => { - sess.err("TODO: Linkage::Dynamic not supported yet"); + sess.dcx().err("TODO: Linkage::Dynamic not supported yet"); } } } @@ -467,7 +474,7 @@ fn add_upstream_native_libraries( .. } => {} - _ => sess.fatal(format!( + _ => sess.dcx().fatal(format!( "`NativeLibKind::{:?}` (name={:?}) not supported yet", lib.kind, lib.name )), @@ -600,7 +607,7 @@ fn do_link( match link_result { Ok(v) => v, Err(rustc_errors::ErrorGuaranteed { .. }) => { - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); bug!("Linker errored, but no error reported"); } } diff --git a/crates/rustc_codegen_spirv/src/linker/import_export_link.rs b/crates/rustc_codegen_spirv/src/linker/import_export_link.rs index 160a1dd1c7..2300083de6 100644 --- a/crates/rustc_codegen_spirv/src/linker/import_export_link.rs +++ b/crates/rustc_codegen_spirv/src/linker/import_export_link.rs @@ -56,7 +56,9 @@ fn find_import_export_pairs_and_killed_params( }; let type_id = *type_map.get(&id).expect("Unexpected op"); if exports.insert(name, (id, type_id)).is_some() { - return Err(sess.err(format!("Multiple exports found for {name:?}"))); + return Err(sess + .dcx() + .err(format!("Multiple exports found for {name:?}"))); } } let mut any_err = None; @@ -68,7 +70,7 @@ fn find_import_export_pairs_and_killed_params( }; let (export_id, export_type) = match exports.get(name) { None => { - any_err = Some(sess.err(format!("Unresolved symbol {name:?}"))); + any_err = Some(sess.dcx().err(format!("Unresolved symbol {name:?}"))); continue; } Some(&x) => x, @@ -184,6 +186,7 @@ fn check_tys_equal( result } Err(sess + .dcx() .struct_err(format!("Types mismatch for {name:?}")) .note(format!( "import type: {}", diff --git a/crates/rustc_codegen_spirv/src/linker/inline.rs b/crates/rustc_codegen_spirv/src/linker/inline.rs index c036464ade..4705fb8a02 100644 --- a/crates/rustc_codegen_spirv/src/linker/inline.rs +++ b/crates/rustc_codegen_spirv/src/linker/inline.rs @@ -117,7 +117,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> { if !inlined_to_legalize_dont_inlines.is_empty() { let names = get_names(module); for f in inlined_to_legalize_dont_inlines { - sess.warn(format!( + sess.dcx().warn(format!( "`#[inline(never)]` function `{}` needs to be inlined \ because it has illegal argument or return types", get_name(&names, f) @@ -235,7 +235,7 @@ fn deny_recursion_in_module(sess: &Session, module: &Module) -> super::Result<() let names = get_names(module); let current_name = get_name(&names, module.functions[current].def_id().unwrap()); let next_name = get_name(&names, module.functions[next].def_id().unwrap()); - *has_recursion = Some(sess.err(format!( + *has_recursion = Some(sess.dcx().err(format!( "module has recursion, which is not allowed: `{current_name}` calls `{next_name}`" ))); break; @@ -626,7 +626,7 @@ impl Inliner<'_, '_> { let return_jump = self.id(); // Rewrite OpReturns of the callee. let (mut inlined_callee_blocks, extra_debug_insts_pre_call, extra_debug_insts_post_call) = - self.get_inlined_blocks(callee, call_debug_insts, return_variable, return_jump); + self.get_inlined_blocks(&callee, call_debug_insts, return_variable, return_jump); // Clone the IDs of the callee, because otherwise they'd be defined multiple times if the // fn is inlined multiple times. self.add_clone_id_rules(&mut rewrite_rules, &inlined_callee_blocks); diff --git a/crates/rustc_codegen_spirv/src/linker/mod.rs b/crates/rustc_codegen_spirv/src/linker/mod.rs index 8c5b93235e..8ea308d42c 100644 --- a/crates/rustc_codegen_spirv/src/linker/mod.rs +++ b/crates/rustc_codegen_spirv/src/linker/mod.rs @@ -167,7 +167,7 @@ pub fn link( bound += module.header.as_ref().unwrap().bound - 1; let this_version = module.header.as_ref().unwrap().version(); if version != this_version { - return Err(sess.err(format!( + return Err(sess.dcx().err(format!( "cannot link two modules with different SPIR-V versions: v{}.{} and v{}.{}", version.0, version.1, this_version.0, this_version.1 ))); @@ -426,6 +426,7 @@ pub fn link( }; return Err(sess + .dcx() .struct_err(format!("{e}")) .note("while lowering SPIR-V module to SPIR-T (spirt::spv::lower)") .note(format!("input SPIR-V module {was_saved_msg}")) @@ -534,7 +535,7 @@ pub fn link( } if any_spirt_bugs { - let mut note = sess.struct_note("SPIR-T bugs were reported"); + let mut note = sess.dcx().struct_note("SPIR-T bugs were reported"); note.help(format!( "pretty-printed SPIR-T was saved to {}.html", dump_spirt_file_path.as_ref().unwrap().display() @@ -576,12 +577,12 @@ pub fn link( if ext_inst_set.starts_with(custom_insts::CUSTOM_EXT_INST_SET_PREFIX) { let expected = &custom_insts::CUSTOM_EXT_INST_SET[..]; if ext_inst_set == expected { - return Err(sess.err(format!( + return Err(sess.dcx().err(format!( "`OpExtInstImport {ext_inst_set:?}` should not have been \ left around after SPIR-T passes" ))); } else { - return Err(sess.err(format!( + return Err(sess.dcx().err(format!( "unsupported `OpExtInstImport {ext_inst_set:?}` (expected {expected:?} name - version mismatch?)" ))); diff --git a/crates/rustc_codegen_spirv/src/linker/simple_passes.rs b/crates/rustc_codegen_spirv/src/linker/simple_passes.rs index 7ca44add13..2375cf24db 100644 --- a/crates/rustc_codegen_spirv/src/linker/simple_passes.rs +++ b/crates/rustc_codegen_spirv/src/linker/simple_passes.rs @@ -245,12 +245,13 @@ pub fn check_fragment_insts(sess: &Session, module: &Module) -> Result<()> { .collect::>() .join("\n"); any_err = Some( - sess.struct_err(format!( - "{} cannot be used outside a fragment shader", - inst.class.opname - )) - .note(note) - .emit(), + sess.dcx() + .struct_err(format!( + "{} cannot be used outside a fragment shader", + inst.class.opname + )) + .note(note) + .emit(), ); } } diff --git a/crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs b/crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs index b658c4b09f..236e282e63 100644 --- a/crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs +++ b/crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs @@ -3,7 +3,7 @@ use crate::custom_decorations::{ }; use crate::custom_insts::{self, CustomInst, CustomOp}; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{DiagnosticBuilder, EmissionGuarantee}; use rustc_session::Session; use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; @@ -306,11 +306,11 @@ impl UseOrigin<'_> { } } - fn note( + fn note( &self, cx: &Context, span_regen: &mut SpanRegenerator<'_>, - err: &mut DiagnosticBuilder<'_, impl rustc_errors::EmissionGuarantee>, + err: &mut DiagnosticBuilder<'_, G>, ) { let wk = &super::SpvSpecWithExtras::get().well_known; @@ -420,7 +420,10 @@ impl DiagnosticReporter<'_> { self.span_regen.spirt_attrs_to_rustc_span(self.cx, attrs) }) .unwrap_or(DUMMY_SP); - let mut err = self.sess.struct_span_err(def_span, reason.to_string()); + let mut err = self + .sess + .dcx() + .struct_span_err(def_span, reason.to_string()); for use_origin in use_stack_for_def.iter().rev() { use_origin.note(self.cx, &mut self.span_regen, &mut err); } @@ -463,14 +466,14 @@ impl DiagnosticReporter<'_> { let msg = [prefix, msg.to_string(), suffix].concat(); match level { DiagLevel::Bug(_) | DiagLevel::Error => { - let mut err = self.sess.struct_span_err(def_span, msg); + let mut err = self.sess.dcx().struct_span_err(def_span, msg); for use_origin in use_stack_for_def.iter().rev() { use_origin.note(self.cx, &mut self.span_regen, &mut err); } self.overall_result = Err(err.emit()); } DiagLevel::Warning => { - let mut warn = self.sess.struct_span_warn(def_span, msg); + let mut warn = self.sess.dcx().struct_span_warn(def_span, msg); for use_origin in use_stack_for_def.iter().rev() { use_origin.note(self.cx, &mut self.span_regen, &mut warn); } diff --git a/crates/rustc_codegen_spirv/src/linker/test.rs b/crates/rustc_codegen_spirv/src/linker/test.rs index 4b94588943..b3c2e5fd81 100644 --- a/crates/rustc_codegen_spirv/src/linker/test.rs +++ b/crates/rustc_codegen_spirv/src/linker/test.rs @@ -122,9 +122,8 @@ fn link_with_linker_opts( // is really a silent unwinding device, that should be treated the same as // `Err(ErrorGuaranteed)` returns from `link`). rustc_driver::catch_fatal_errors(|| { - let mut early_error_handler = rustc_session::EarlyErrorHandler::new( - rustc_session::config::ErrorOutputType::default(), - ); + let mut early_error_handler = + rustc_session::EarlyDiagCtxt::new(rustc_session::config::ErrorOutputType::default()); early_error_handler.initialize_checked_jobserver(); let matches = rustc_driver::handle_options( &early_error_handler, @@ -161,7 +160,7 @@ fn link_with_linker_opts( // HACK(eddyb) inject `write_diags` into `sess`, to work around // the removals in https://github.com/rust-lang/rust/pull/102992. - sess.parse_sess.span_diagnostic = { + sess.parse_sess.dcx = { let fallback_bundle = { extern crate rustc_error_messages; rustc_error_messages::fallback_fluent_bundle( @@ -173,8 +172,8 @@ fn link_with_linker_opts( rustc_errors::emitter::EmitterWriter::new(Box::new(buf), fallback_bundle) .sm(Some(sess.parse_sess.clone_source_map())); - rustc_errors::Handler::with_emitter(Box::new(emitter)) - .with_flags(sess.opts.unstable_opts.diagnostic_handler_flags(true)) + rustc_errors::DiagCtxt::with_emitter(Box::new(emitter)) + .with_flags(sess.opts.unstable_opts.dcx_flags(true)) }; let res = link( @@ -192,7 +191,7 @@ fn link_with_linker_opts( ), Default::default(), ); - assert_eq!(sess.has_errors(), res.as_ref().err().copied()); + assert_eq!(sess.dcx().has_errors(), res.as_ref().err().copied()); res.map(|res| match res { LinkResult::SingleModule(m) => *m, LinkResult::MultipleModules { .. } => unreachable!(), diff --git a/crates/rustc_codegen_spirv/src/linker/zombies.rs b/crates/rustc_codegen_spirv/src/linker/zombies.rs index 6e73af472d..a33dca831f 100644 --- a/crates/rustc_codegen_spirv/src/linker/zombies.rs +++ b/crates/rustc_codegen_spirv/src/linker/zombies.rs @@ -6,7 +6,7 @@ use crate::custom_insts::{self, CustomOp}; use rspirv::dr::{Instruction, Module, Operand}; use rspirv::spirv::{Op, Word}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::DiagnosticBuilder; use rustc_session::Session; use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; @@ -239,7 +239,7 @@ impl<'a> ZombieReporter<'a> { fn add_use_note_to_err( &mut self, - err: &mut DiagnosticBuilder<'a, ErrorGuaranteed>, + err: &mut DiagnosticBuilder<'a>, span: Span, zombie: Zombie<'_>, zombie_use: &ZombieUse<'_>, @@ -278,7 +278,7 @@ impl<'a> ZombieReporter<'a> { fn build_errors_keyed_by_leaf_id( &mut self, zombie: Zombie<'_>, - ) -> FxIndexMap> { + ) -> FxIndexMap> { // FIXME(eddyb) this is a bit inefficient, compared to some kind of // "small map", but this is the error path, and being correct is more // important here - in particular, we don't want to ignore *any* leaves. @@ -294,7 +294,7 @@ impl<'a> ZombieReporter<'a> { let reason = self.span_regen.zombie_for_id(zombie.id).unwrap().reason; errors_keyed_by_leaf_id.insert( zombie.id, - self.sess.struct_span_err(span, reason.to_string()), + self.sess.dcx().struct_span_err(span, reason.to_string()), ); } ZombieKind::Uses(zombie_uses) => { diff --git a/crates/rustc_codegen_spirv/src/spirv_type.rs b/crates/rustc_codegen_spirv/src/spirv_type.rs index 73cfdc662f..7cfffc6d79 100644 --- a/crates/rustc_codegen_spirv/src/spirv_type.rs +++ b/crates/rustc_codegen_spirv/src/spirv_type.rs @@ -297,7 +297,7 @@ impl SpirvType<'_> { } ref other => cx .tcx - .sess + .dcx() .fatal(format!("def_with_id invalid for type {other:?}")), }; cx.type_cache_def(result, self.tcx_arena_alloc_slices(cx), def_span); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 93684251f0..8a89005026 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ [toolchain] -channel = "nightly-2023-12-16" +channel = "nightly-2023-12-31" components = ["rust-src", "rustc-dev", "llvm-tools"] -# commit_hash = a96d57bdb6d2bb6d233d7d5aaefc2995ab99be01 +# commit_hash = 2a3e63551fe21458637480a97b65a2d15dec8062 # 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/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index 76c49bd4e5..06c839cbf0 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:2793:9 + --> $CORE_SRC/intrinsics.rs:2794:9 | -2793 | copy(src, dst, count) +2794 | copy(src, dst, count) | ^^^^^^^^^^^^^^^^^^^^^ | note: used from within `core::intrinsics::copy::` - --> $CORE_SRC/intrinsics.rs:2779:21 + --> $CORE_SRC/intrinsics.rs:2780:21 | -2779 | pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { +2780 | 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