upgrade to 1.78.0 nightly-2024-03-14

This commit is contained in:
LemonHX 2024-03-16 00:43:42 +08:00
parent 5f545076d3
commit dbe0f256d6
31 changed files with 386 additions and 343 deletions

26
Cargo.lock generated
View File

@ -18,17 +18,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"
[[package]]
name = "ahash"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]]
name = "ahash"
version = "0.8.7"
@ -1157,15 +1146,6 @@ dependencies = [
"bitflags 2.4.2",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash 0.7.7",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -1178,7 +1158,7 @@ version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
dependencies = [
"ahash 0.8.7",
"ahash",
"allocator-api2",
]
@ -2139,7 +2119,6 @@ version = "0.9.0"
dependencies = [
"ar",
"either",
"hashbrown 0.11.2",
"indexmap 1.9.3",
"itertools",
"lazy_static",
@ -2160,6 +2139,7 @@ dependencies = [
"spirv-tools",
"syn 1.0.109",
"tempfile",
"termcolor",
]
[[package]]
@ -3428,7 +3408,7 @@ version = "0.29.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c824f11941eeae66ec71111cc2674373c772f482b58939bb4066b642aa2ffcf"
dependencies = [
"ahash 0.8.7",
"ahash",
"android-activity",
"atomic-waker",
"bitflags 2.4.2",

View File

@ -40,13 +40,13 @@ syn = { version = "1", features = ["extra-traits", "full"] }
[dependencies]
# HACK(eddyb) these only exist to unify features across dependency trees,
# in order to avoid multiple separate instances of `rustc_codegen_spirv`.
hashbrown = "0.11"
libc = { version = "0.2", features = ["align", "extra_traits"] }
num-traits = { version = "0.2", features = ["libm"] }
once_cell = "1"
regex = { version = "1", features = ["perf"] }
# Normal dependencies.
termcolor = "1.2"
ar = "0.9.0"
either = "1.8.0"
indexmap = "1.6.0"

View File

@ -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-21"
channel = "nightly-2024-03-14"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 5ac4c8a63ee305742071ac6dd11817f7c24adce2"#;
# commit_hash = 3cbb93223f33024db464a4df27a13c7cce870173"#;
fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));

View File

@ -505,8 +505,10 @@ fn trans_scalar<'tcx>(
Primitive::Int(width, signedness) => {
SpirvType::Integer(width.size().bits() as u32, signedness).def(span, cx)
}
Primitive::F16 => SpirvType::Float(16).def(span, cx),
Primitive::F32 => SpirvType::Float(32).def(span, cx),
Primitive::F64 => SpirvType::Float(64).def(span, cx),
Primitive::F128 => SpirvType::Float(128).def(span, cx),
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
@ -580,7 +582,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.sess.psess.dcx.fatal(format!(
"dig_scalar_pointee: unsupported Pointer with different \
pointee types ({old_pointee:?} vs {new_pointee:?}) at offset {offset:?} in {layout:#?}"
));
@ -728,7 +730,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.sess.psess.dcx.fatal("Variants::Multiple has multiple fields")
}
};
}
@ -784,7 +786,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(())
@ -805,6 +807,7 @@ fn trans_intrinsic_type<'tcx>(
return Err(cx
.tcx
.sess
.psess.dcx
.err("#[spirv(generic_image)] type must have size 4"));
}
@ -848,7 +851,7 @@ fn trans_intrinsic_type<'tcx>(
_ => {
return Err(cx
.tcx
.sess
.sess.psess.dcx
.span_err(span, "Invalid sampled type to `Image`."));
}
};
@ -871,7 +874,7 @@ fn trans_intrinsic_type<'tcx>(
Some(v) => Ok(v),
None => Err(cx
.tcx
.sess
.sess.psess.dcx
.err(format!("Invalid value for Image const generic: {value}"))),
}
}
@ -897,7 +900,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.sess.psess.dcx.err("#[spirv(sampler)] type must have size 4"));
}
Ok(SpirvType::Sampler.def(span, cx))
}
@ -910,7 +913,7 @@ fn trans_intrinsic_type<'tcx>(
if ty.size != Size::from_bytes(4) {
return Err(cx
.tcx
.sess
.sess.psess.dcx
.err("#[spirv(sampled_image)] type must have size 4"));
}
@ -923,7 +926,7 @@ fn trans_intrinsic_type<'tcx>(
} else {
Err(cx
.tcx
.sess
.sess.psess.dcx
.err("#[spirv(sampled_image)] type must have a generic image type"))
}
}
@ -931,7 +934,7 @@ fn trans_intrinsic_type<'tcx>(
if ty.size != Size::from_bytes(4) {
return Err(cx
.tcx
.sess
.sess.psess.dcx
.err("#[spirv(runtime_array)] type must have size 4"));
}
@ -943,7 +946,7 @@ fn trans_intrinsic_type<'tcx>(
} else {
Err(cx
.tcx
.sess
.sess.psess.dcx
.err("#[spirv(runtime_array)] type must have a generic element type"))
}
}
@ -958,12 +961,12 @@ fn trans_intrinsic_type<'tcx>(
if field_types.len() < 2 {
return Err(cx
.tcx
.sess
.sess.psess.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.sess.psess.dcx.span_err(
span,
"#[spirv(matrix)] type fields must all be the same type",
));
@ -973,10 +976,8 @@ fn trans_intrinsic_type<'tcx>(
ty => {
return Err(cx
.tcx
.sess
.struct_span_err(span, "#[spirv(matrix)] type fields must all be vectors")
.note(format!("field type is {}", ty.debug(elem_type, cx)))
.emit());
.sess.psess.dcx
.span_err(span, format!("#[spirv(matrix)] type fields must all be vectors, found {}", ty.debug(elem_type, cx))));
}
}

View File

@ -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.sess.psess.dcx.span_delayed_bug(span, msg);
continue;
}
};
@ -165,7 +165,7 @@ impl AggregatedSpirvAttributes {
category,
}) => {
cx.tcx
.sess
.sess.psess.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.sess.psess.dcx.span_err(span, msg);
continue;
}
};
@ -317,13 +317,13 @@ impl CheckSpirvAttrVisitor<'_> {
| SpirvAttribute::InputAttachmentIndex(_)
| SpirvAttribute::SpecConstant(_) => match target {
Target::Param => {
let parent_hir_id = self.tcx.hir().parent_id(hir_id);
let mut parent_hir_id = self.tcx.hir().parent_id_iter(hir_id);
let parent_is_entry_point =
parse_attrs(self.tcx.hir().attrs(parent_hir_id))
parse_attrs(self.tcx.hir().attrs(parent_hir_id.next().unwrap()))
.filter_map(|r| r.ok())
.any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_)));
if !parent_is_entry_point {
self.tcx.sess.span_err(
self.tcx.sess.psess.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.sess.psess.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.sess.psess.dcx.span_err(
span,
format!(
"attribute is only valid on a {expected_target}, not on a {target}"
@ -381,13 +381,13 @@ impl CheckSpirvAttrVisitor<'_> {
category,
}) => {
self.tcx
.sess
.sess.psess.dcx
.struct_span_err(
span,
format!("only one {category} attribute is allowed on a {target}"),
)
.span_note(prev_span, format!("previous {category} attribute"))
.emit();
;
}
},
}
@ -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.sess.psess.dcx.span_warn(
block_attr.span,
"#[spirv(block)] is no longer needed and should be removed",
);

View File

@ -28,7 +28,6 @@ use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
use smallvec::SmallVec;
use std::borrow::Cow;
use std::cell::Cell;
use std::convert::TryInto;
use std::iter::{self, empty};
macro_rules! simple_op {
@ -444,7 +443,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
///
/// That is, try to turn `((_: *T) as *u8).add(offset) as *Leaf` into a series
/// of struct field and array/vector element accesses.
fn recover_access_chain_from_offset(
pub(crate) fn recover_access_chain_from_offset(
&self,
mut ty: <Self as BackendTypes>::Type,
mut offset: Size,
@ -738,7 +737,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
current_span: Default::default(),
}
}
fn fadd_algebraic(&mut self, _: <Self as BackendTypes>::Value, _: <Self as BackendTypes>::Value) -> <Self as BackendTypes>::Value { todo!() }
fn fsub_algebraic(&mut self, _: <Self as BackendTypes>::Value, _: <Self as BackendTypes>::Value) -> <Self as BackendTypes>::Value { todo!() }
fn fmul_algebraic(&mut self, _: <Self as BackendTypes>::Value, _: <Self as BackendTypes>::Value) -> <Self as BackendTypes>::Value { todo!() }
fn fdiv_algebraic(&mut self, _: <Self as BackendTypes>::Value, _: <Self as BackendTypes>::Value) -> <Self as BackendTypes>::Value { todo!() }
fn frem_algebraic(&mut self, _: <Self as BackendTypes>::Value, _: <Self as BackendTypes>::Value) -> <Self as BackendTypes>::Value { todo!() }
fn cx(&self) -> &Self::CodegenCx {
self.cx
}
@ -1373,78 +1377,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
self.gep_help(ty, ptr, indices, true)
}
fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value {
let (offset, result_pointee_type) = match self.lookup_type(ty) {
SpirvType::Adt {
field_offsets,
field_types,
..
} => (field_offsets[idx as usize], field_types[idx as usize]),
SpirvType::Array { element, .. }
| SpirvType::RuntimeArray { element, .. }
| SpirvType::Vector { element, .. }
| SpirvType::Matrix { element, .. } => (
self.lookup_type(element).sizeof(self).unwrap() * idx,
element,
),
SpirvType::InterfaceBlock { inner_type } => {
assert_eq!(idx, 0);
(Size::ZERO, inner_type)
}
other => self.fatal(format!(
"struct_gep not on struct, array, or vector type: {other:?}, index {idx}"
)),
};
let result_type = self.type_ptr_to(result_pointee_type);
// Special-case field accesses through a `pointercast`, to accesss the
// right field in the original type, for the `Logical` addressing model.
let ptr = ptr.strip_ptrcasts();
let original_pointee_ty = match self.lookup_type(ptr.ty) {
SpirvType::Pointer { pointee } => pointee,
other => self.fatal(format!("struct_gep called on non-pointer type: {other:?}")),
};
if let Some((indices, _)) = self.recover_access_chain_from_offset(
original_pointee_ty,
offset,
self.lookup_type(result_pointee_type).sizeof(self),
Some(result_pointee_type),
) {
let original_ptr = ptr.def(self);
let indices = indices
.into_iter()
.map(|idx| self.constant_u32(self.span(), idx).def(self))
.collect::<Vec<_>>();
return self
.emit()
.access_chain(result_type, None, original_ptr, indices)
.unwrap()
.with_type(result_type);
}
// FIXME(eddyb) can we even get to this point, with valid SPIR-V?
// HACK(eddyb) temporary workaround for untyped pointers upstream.
// FIXME(eddyb) replace with untyped memory SPIR-V + `qptr` or similar.
let ptr = self.pointercast(ptr, self.type_ptr_to(ty));
// Important! LLVM, and therefore intel-compute-runtime, require the `getelementptr` instruction (and therefore
// OpAccessChain) on structs to be a constant i32. Not i64! i32.
if idx > u32::MAX as u64 {
self.fatal("struct_gep bigger than u32::MAX");
}
let index_const = self.constant_u32(self.span(), idx as u32).def(self);
self.emit()
.access_chain(
result_type,
None,
ptr.def(self),
[index_const].iter().cloned(),
)
.unwrap()
.with_type(result_type)
}
// intcast has the logic for dealing with bools, so use that
fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value {
self.intcast(val, dest_ty, false)
@ -2282,7 +2214,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 +2242,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
)
.unwrap()
.with_type(access_ty);
self.bitcast(result, ty)
(self.bitcast(result, ty),self.bitcast(result, ty))
}
fn atomic_rmw(
@ -2987,7 +2919,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.sess.psess.dcx.struct_span_warn(
current_span,
"failed to find and remove `format_args!` construction for this `panic!`",
);

View File

@ -71,7 +71,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
args: &[OperandRef<'tcx, Self::Value>],
llresult: Self::Value,
_span: Span,
) {
) -> Result<(), rustc_middle::ty::Instance<'tcx>> {
let callee_ty = instance.ty(self.tcx, ParamEnv::reveal_all());
let (def_id, fn_args) = match *callee_ty.kind() {
@ -98,7 +98,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
sym::breakpoint => {
self.abort();
assert!(fn_abi.ret.is_ignore());
return;
return Ok(());
}
sym::volatile_load | sym::unaligned_volatile_load => {
@ -114,7 +114,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
| sym::prefetch_write_instruction => {
// ignore
assert!(fn_abi.ret.is_ignore());
return;
return Ok(());
}
sym::saturating_add => {
@ -342,6 +342,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
.val
.store(self, result);
}
Ok(())
}
fn abort(&mut self) {

View File

@ -20,7 +20,8 @@ use rustc_codegen_ssa::traits::{
AbiBuilderMethods, ArgAbiMethods, BackendTypes, BuilderMethods, CoverageInfoBuilderMethods,
DebugInfoBuilderMethods, HasCodegen, StaticBuilderMethods, TypeMembershipMethods,
};
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed};
use rustc_errors::{Diag,DiagMessage};
use rustc_errors::ErrorGuaranteed;
use rustc_middle::mir::Coverage;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::{
@ -68,33 +69,105 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
pub(crate) fn struct_gep(&mut self, ty: <crate::Builder<'a, 'tcx> as BackendTypes>::Type, ptr: SpirvValue, idx: u64) -> <crate::Builder<'a, 'tcx> as BackendTypes>::Value {
let (offset, result_pointee_type) = match self.lookup_type(ty) {
SpirvType::Adt {
field_offsets,
field_types,
..
} => (field_offsets[idx as usize], field_types[idx as usize]),
SpirvType::Array { element, .. }
| SpirvType::RuntimeArray { element, .. }
| SpirvType::Vector { element, .. }
| SpirvType::Matrix { element, .. } => (
self.lookup_type(element).sizeof(self).unwrap() * idx,
element,
),
SpirvType::InterfaceBlock { inner_type } => {
assert_eq!(idx, 0);
(Size::ZERO, inner_type)
}
other => self.fatal(format!(
"struct_gep not on struct, array, or vector type: {other:?}, index {idx}"
)),
};
let result_type = self.type_ptr_to(result_pointee_type);
// Special-case field accesses through a `pointercast`, to accesss the
// right field in the original type, for the `Logical` addressing model.
let ptr = ptr.strip_ptrcasts();
let original_pointee_ty = match self.lookup_type(ptr.ty) {
SpirvType::Pointer { pointee } => pointee,
other => self.fatal(format!("struct_gep called on non-pointer type: {other:?}")),
};
if let Some((indices, _)) = self.recover_access_chain_from_offset(
original_pointee_ty,
offset,
self.lookup_type(result_pointee_type).sizeof(self),
Some(result_pointee_type),
) {
let original_ptr = ptr.def(self);
let indices = indices
.into_iter()
.map(|idx| self.constant_u32(self.span(), idx).def(self))
.collect::<Vec<_>>();
return self
.emit()
.access_chain(result_type, None, original_ptr, indices)
.unwrap()
.with_type(result_type);
}
// FIXME(eddyb) can we even get to this point, with valid SPIR-V?
// HACK(eddyb) temporary workaround for untyped pointers upstream.
// FIXME(eddyb) replace with untyped memory SPIR-V + `qptr` or similar.
let ptr = self.pointercast(ptr, self.type_ptr_to(ty));
// Important! LLVM, and therefore intel-compute-runtime, require the `getelementptr` instruction (and therefore
// OpAccessChain) on structs to be a constant i32. Not i64! i32.
if idx > u32::MAX as u64 {
self.fatal("struct_gep bigger than u32::MAX");
}
let index_const = self.constant_u32(self.span(), idx as u32).def(self);
self.emit()
.access_chain(
result_type,
None,
ptr.def(self),
[index_const].iter().cloned(),
)
.unwrap()
.with_type(result_type)
}
#[track_caller]
pub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
msg: impl Into<DiagMessage>,
) -> Diag<'_, ErrorGuaranteed> {
if let Some(current_span) = self.current_span {
self.tcx.sess.struct_span_err(current_span, msg)
self.tcx.sess.psess.dcx.struct_span_err(current_span, msg)
} else {
self.tcx.sess.struct_err(msg)
self.tcx.sess.psess.dcx.struct_err(msg)
}
}
#[track_caller]
pub fn err(&self, msg: impl Into<DiagnosticMessage>) {
pub fn err(&self, msg: impl Into<DiagMessage>) {
if let Some(current_span) = self.current_span {
self.tcx.sess.span_err(current_span, msg);
self.tcx.sess.psess.dcx.span_err(current_span, msg);
} else {
self.tcx.sess.err(msg);
self.tcx.sess.psess.dcx.err(msg);
}
}
#[track_caller]
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
pub fn fatal(&self, msg: impl Into<DiagMessage>) -> ! {
if let Some(current_span) = self.current_span {
self.tcx.sess.span_fatal(current_span, msg)
self.tcx.sess.psess.dcx.span_fatal(current_span, msg)
} else {
self.tcx.sess.fatal(msg)
self.tcx.sess.psess.dcx.fatal(msg)
}
}

View File

@ -15,7 +15,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::{bug, ty::Instance};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::asm::{InlineAsmRegClass, InlineAsmRegOrRegClass, SpirVInlineAsmRegClass};
use std::convert::TryFrom;
pub struct InstructionTable {
table: FxHashMap<&'static str, &'static rspirv::grammar::Instruction<'static>>,
@ -51,7 +50,6 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> {
Placeholder { operand_idx: 2, modifier: None, span: src/lib.rs:20:23: 20:31 (#0) }
]
*/
fn codegen_inline_asm(
&mut self,
template: &[InlineAsmTemplatePiece],
@ -59,7 +57,8 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> {
options: InlineAsmOptions,
_line_spans: &[Span],
_instance: Instance<'_>,
_dest_catch_funclet: Option<(Self::BasicBlock, Self::BasicBlock, Option<&Self::Funclet>)>,
_bb1 : Option<Self::BasicBlock>,
_dest_catch_funclet : Option<(Self::BasicBlock, Option<&Self::Funclet>)>,
) {
const SUPPORTED_OPTIONS: InlineAsmOptions = InlineAsmOptions::NORETURN;
let unsupported_options = options & !SUPPORTED_OPTIONS;
@ -101,7 +100,7 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> {
} => {
if let Some(modifier) = modifier {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, format!("asm modifiers are not supported: {modifier}"));
}
let line = tokens.last_mut().unwrap();
@ -305,14 +304,14 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Op::TypePointer => {
let storage_class = inst.operands[0].unwrap_storage_class();
if storage_class != StorageClass::Generic {
self.struct_err("TypePointer in asm! requires `Generic` storage class")
.note(format!(
let mut err = self.struct_err("TypePointer in asm! requires `Generic` storage class")
;err.note(format!(
"`{storage_class:?}` storage class was specified"
))
.help(format!(
));
err.help(format!(
"the storage class will be inferred automatically (e.g. to `{storage_class:?}`)"
))
.emit();
));
err.emit();
}
SpirvType::Pointer {
pointee: inst.operands[1].unwrap_id_ref(),
@ -359,14 +358,14 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
// NOTE(eddyb) allowing the instruction to be added below avoids
// spurious "`noreturn` requires a terminator at the end" errors.
if let Op::Return | Op::ReturnValue = op {
self.struct_err(format!(
let mut err = self.struct_err(format!(
"using `Op{op:?}` to return from within `asm!` is disallowed"
))
.note(
));
err.note(
"resuming execution, without falling through the end \
of the `asm!` block, is always undefined behavior",
)
.emit();
);
err.emit();
}
self.emit()
@ -456,7 +455,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Token::Placeholder(_, span) | Token::Typeof(_, span, _) => {
self.tcx
.sess
.span_err(span, "cannot use a dynamic value as an instruction type");
.psess.dcx.span_err(span, "cannot use a dynamic value as an instruction type");
return;
}
};
@ -582,7 +581,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
));
}
if tokens.next().is_some() {
self.tcx.sess.err(format!(
self.tcx.sess .psess.dcx.err(format!(
"too many operands to instruction: {}",
instruction.class.opname
));
@ -799,6 +798,8 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
_ => {
self.tcx
.sess
.psess
.dcx
.span_err(span, format!("invalid register: {reg}"));
}
}
@ -831,7 +832,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
Token::Typeof(_, span, _) => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "cannot assign to a typeof expression");
None
}
@ -839,10 +840,12 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
InlineAsmOperandRef::In { reg, value: _ } => {
self.check_reg(span, reg);
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "in register cannot be assigned to");
None
}
InlineAsmOperandRef::Label { .. } => todo!(),
InlineAsmOperandRef::Out {
reg,
late: _,
@ -852,7 +855,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.sess.psess.dcx.span_err(span, "missing place for register");
None
}
}
@ -867,26 +870,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.sess.psess.dcx.span_err(span, "missing place for register");
None
}
}
}
InlineAsmOperandRef::Const { string: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "cannot write to const asm argument");
None
}
InlineAsmOperandRef::SymFn { instance: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "cannot write to function asm argument");
None
}
InlineAsmOperandRef::SymStatic { def_id: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "cannot write to static variable asm argument");
None
}
@ -913,6 +916,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
None
}
Token::Typeof(hole, span, kind) => match hole {
InlineAsmOperandRef::Label { .. } => todo!(),
InlineAsmOperandRef::In { reg, value } => {
self.check_reg(span, reg);
let ty = value.immediate().ty;
@ -921,7 +925,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.sess.psess.dcx.span_err(
span,
format!(
"cannot use typeof* on non-pointer type: {}",
@ -943,7 +947,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.sess.psess.dcx.span_err(
span,
format!(
"out register type not pointer: {}",
@ -955,7 +959,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
},
None => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "missing place for out register typeof");
None
}
@ -972,18 +976,18 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
InlineAsmOperandRef::Const { string: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "cannot take the type of a const asm argument");
None
}
InlineAsmOperandRef::SymFn { instance: _ } => {
self.tcx
.sess
.sess.psess.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.sess.psess.dcx.span_err(
span,
"cannot take the type of a static variable asm argument",
);
@ -995,6 +999,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
self.check_reg(span, reg);
Some(value.immediate().def(self))
}
InlineAsmOperandRef::Label { .. } => todo!(),
InlineAsmOperandRef::Out {
reg,
late: _,
@ -1002,7 +1007,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
} => {
self.check_reg(span, reg);
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "out register cannot be used as a value");
None
}
@ -1017,19 +1022,19 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
InlineAsmOperandRef::Const { string: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "const asm argument not supported yet");
None
}
InlineAsmOperandRef::SymFn { instance: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "function asm argument not supported yet");
None
}
InlineAsmOperandRef::SymStatic { def_id: _ } => {
self.tcx
.sess
.sess.psess.dcx
.span_err(span, "static variable asm argument not supported yet");
None
}
@ -1161,13 +1166,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.sess.psess.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.sess.psess.dcx.span_err(
span,
format!("expected a literal, not a type for a {kind:?}"),
);
@ -1363,13 +1368,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.sess.psess.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.sess.psess.dcx.span_err(
span,
format!("expected a literal, not a type for a {kind:?}"),
);

View File

@ -162,11 +162,10 @@ impl SpirvValue {
}
SpirvValueKind::IllegalTypeUsed(id) => {
cx.tcx
.sess
.struct_span_err(span, "Can't use type as a value")
.note(format!("Type: *{}", cx.debug_type(id)))
.emit();
cx
.tcx.sess
.psess.dcx.struct_span_err(span, "Can't use type as a value")
.note(format!("Type: *{}", cx.debug_type(id)));
id
}
@ -367,7 +366,7 @@ impl Eq for DebugFileKey {}
impl Hash for DebugFileKey {
fn hash<H: Hasher>(&self, state: &mut H) {
let Self(sf) = self;
sf.name_hash.hash(state);
sf.name.hash(state);
sf.src_hash.hash(state);
}
}

View File

@ -65,6 +65,8 @@ impl<'tcx> CodegenCx<'tcx> {
_ => self
.tcx
.sess
.psess
.dcx
.fatal(format!("Invalid constant value for bool: {val}")),
},
SpirvType::Integer(128, _) => {
@ -72,7 +74,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.sess.psess.dcx.fatal(format!(
"constant_int invalid on type {}",
other.debug(ty, self)
)),
@ -93,7 +95,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.sess.psess.dcx.fatal(format!(
"constant_float invalid on type {}",
other.debug(ty, self)
)),
@ -214,7 +216,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
size,
align,
field_types: &field_types,
field_offsets: &field_offsets,
field_offsets: field_offsets.as_slice(),
field_names: None,
}
.def(DUMMY_SP, self);
@ -258,13 +260,21 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
_ => self
.tcx
.sess
.psess
.dcx
.fatal(format!("Invalid constant value for bool: {data}")),
},
other => self.tcx.sess.fatal(format!(
other => self.tcx.sess.psess.dcx.fatal(format!(
"scalar_to_backend Primitive::Int not supported on type {}",
other.debug(ty, self)
)),
},
Primitive::F16 => {
// let res = self.constant_f16(DUMMY_SP, f16::from_bits(data as u16));
// assert_eq!(res.ty, ty);
// res
todo!()
}
Primitive::F32 => {
let res = self.constant_f32(DUMMY_SP, f32::from_bits(data as u32));
assert_eq!(res.ty, ty);
@ -275,6 +285,12 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
assert_eq!(res.ty, ty);
res
}
Primitive::F128 => {
// let res = self.constant_float(ty, f128::from_bits(data as u128));
// assert_eq!(res.ty, ty);
// res
todo!()
}
Primitive::Pointer(_) => {
if data == 0 {
self.constant_null(ty)
@ -296,7 +312,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.sess.psess.dcx.fatal(format!(
"GlobalAlloc::Memory type not implemented: {}",
other.debug(ty, self)
)),
@ -316,7 +332,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.sess.psess.dcx.fatal(format!(
"GlobalAlloc::VTable type not implemented: {}",
other.debug(ty, self)
)),
@ -336,6 +352,8 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
} else {
self.tcx
.sess
.psess
.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))
@ -346,8 +364,9 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
} else {
self.tcx
.sess
.fatal("Non-pointer-typed scalar_to_backend Scalar::Ptr not supported");
// unsafe { llvm::LLVMConstPtrToInt(llval, llty) }
.psess
.dcx
.fatal("Non-pointer-typed scalar_to_backend Scalar::Ptr not supported")
}
}
}
@ -448,6 +467,8 @@ impl<'tcx> CodegenCx<'tcx> {
SpirvType::Void => self
.tcx
.sess
.psess
.dcx
.fatal("cannot create const alloc of type void"),
SpirvType::Bool
| SpirvType::Integer(..)
@ -466,6 +487,8 @@ impl<'tcx> CodegenCx<'tcx> {
other => {
self.tcx
.sess
.psess
.dcx
.fatal(format!("invalid size for integer: {other}"));
}
};
@ -477,6 +500,8 @@ impl<'tcx> CodegenCx<'tcx> {
other => {
self.tcx
.sess
.psess
.dcx
.fatal(format!("invalid size for float: {other}"));
}
},
@ -603,25 +628,35 @@ impl<'tcx> CodegenCx<'tcx> {
SpirvType::Function { .. } => self
.tcx
.sess
.psess
.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.sess.psess.dcx.fatal("cannot create a constant image value"),
SpirvType::Sampler => self
.tcx
.sess
.psess
.dcx
.fatal("cannot create a constant sampler value"),
SpirvType::SampledImage { .. } => self
.tcx
.sess
.psess
.dcx
.fatal("cannot create a constant sampled image value"),
SpirvType::InterfaceBlock { .. } => self
.tcx
.sess
.psess
.dcx
.fatal("cannot create a constant interface block value"),
SpirvType::AccelerationStructureKhr => self
.tcx
.sess
.psess
.dcx
.fatal("cannot create a constant acceleration structure"),
SpirvType::RayQueryKhr => self.tcx.sess.fatal("cannot create a constant ray query"),
SpirvType::RayQueryKhr => self.tcx.sess.psess.dcx.fatal("cannot create a constant ray query"),
}
}
}

View File

@ -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.sess.psess.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.sess.psess.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.sess.psess.dcx.err(format!(
"TODO: Linkage type {other:?} not supported yet for function symbol {symbol_name}"
));
None
@ -330,7 +330,7 @@ impl<'tcx> StaticMethods for CodegenCx<'tcx> {
)
}
fn codegen_static(&self, def_id: DefId, _is_mutable: bool) {
fn codegen_static(&self, def_id: DefId,) {
let g = self.get_static(def_id);
let alloc = match self.tcx.eval_static_initializer(def_id) {
@ -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.sess.psess.dcx.fatal(format!(
"global had non-pointer type {}",
other.debug(g.ty, self)
)),

View File

@ -76,6 +76,8 @@ impl<'tcx> CodegenCx<'tcx> {
} else {
self.tcx
.sess
.psess
.dcx
.span_err(span, format!("cannot declare {name} as an entry point"));
return;
};
@ -93,7 +95,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.sess.psess.dcx.span_err(
hir_param.ty_span,
format!(
"entry point parameter type not yet supported \
@ -105,7 +107,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.sess.psess.dcx.span_fatal(
hir_param.ty_span,
format!(
"entry point parameter type not yet supported \
@ -123,7 +125,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.sess.psess.dcx.span_err(
span,
format!(
"entry point should return `()`, not `{}`",
@ -274,7 +276,7 @@ impl<'tcx> CodegenCx<'tcx> {
if is_ref {
Some(StorageClass::UniformConstant)
} else {
self.tcx.sess.span_err(
self.tcx.sess.psess.dcx.span_err(
hir_param.ty_span,
format!(
"entry parameter type must be by-reference: `&{}`",
@ -291,7 +293,7 @@ impl<'tcx> CodegenCx<'tcx> {
let storage_class = storage_class_attr.value;
if !is_ref {
self.tcx.sess.span_fatal(
self.tcx.sess.psess.dcx.span_fatal(
hir_param.ty_span,
format!(
"invalid entry param type `{}` for storage class `{storage_class:?}` \
@ -303,13 +305,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.sess.psess.dcx.span_warn(
storage_class_attr.span,
"redundant storage class attribute, storage class is deduced from type",
),
Some(deduced) => {
self.tcx
.sess
.sess.psess.dcx
.struct_span_err(hir_param.span, "storage class mismatch")
.span_label(
storage_class_attr.span,
@ -324,8 +326,7 @@ impl<'tcx> CodegenCx<'tcx> {
format!(
"remove storage class attribute to use `{deduced:?}` as storage class"
),
)
.emit();
);
}
None => (),
}
@ -338,7 +339,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.sess.psess.dcx.span_fatal(
hir_param.ty_span,
format!(
"invalid entry param type `{}` (expected `{}` or `&mut {1}`)",
@ -355,7 +356,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.sess.psess.dcx.struct_span_err(
hir_param.ty_span,
format!(
"entry-point requires {}...",
@ -395,7 +396,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.sess.psess.dcx.span_err(
hir_param.ty_span,
format!(
"unsupported `#[spirv(spec_constant)]` type `{}` (expected `{}`)",
@ -403,7 +404,7 @@ impl<'tcx> CodegenCx<'tcx> {
),
);
} else if let Some(storage_class) = attrs.storage_class {
self.tcx.sess.span_err(
self.tcx.sess.psess.dcx.span_err(
storage_class.span,
"`#[spirv(spec_constant)]` cannot have a storage class",
);
@ -494,7 +495,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
.sess.psess.dcx
.span_fatal(hir_param.ty_span, "pair type not supported yet")
}
let var_ptr_spirv_type;
@ -518,7 +519,7 @@ impl<'tcx> CodegenCx<'tcx> {
match self.lookup_type(value_spirv_type) {
SpirvType::RuntimeArray { .. } => {}
_ => {
self.tcx.sess.span_err(
self.tcx.sess.psess.dcx.span_err(
hir_param.ty_span,
"only plain slices are supported as unsized types",
);
@ -538,7 +539,7 @@ impl<'tcx> CodegenCx<'tcx> {
// It's OK to use a RuntimeArray<u32> and not have a length parameter, but
// it's just nicer ergonomics to use a slice.
self.tcx
.sess
.sess.psess.dcx
.span_warn(hir_param.ty_span, "use &[T] instead of &RuntimeArray<T>");
}
None
@ -552,7 +553,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.sess.psess.dcx.span_err(
hir_param.ty_span,
"uniform_constant must use &RuntimeArray<T>, not &[T]",
);
@ -560,7 +561,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
_ => {
if is_unsized {
self.tcx.sess.span_err(
self.tcx.sess.psess.dcx.span_err(
hir_param.ty_span,
"only plain slices are supported as unsized types",
);
@ -581,7 +582,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.sess.psess.dcx.span_fatal(
hir_param.ty_span,
format!(
"unsized types are not supported for {}",
@ -644,7 +645,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.sess.psess.dcx.span_fatal(
builtin.span,
format!(
"`#[spirv(spec_constant)]` cannot be `{:?}` builtin",
@ -661,7 +662,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.sess.psess.dcx.span_fatal(
descriptor_set.span,
"`#[spirv(descriptor_set = ...)]` cannot apply to `#[spirv(spec_constant)]`",
);
@ -675,7 +676,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
if let Some(binding) = attrs.binding {
if let Err(SpecConstant { .. }) = storage_class {
self.tcx.sess.span_fatal(
self.tcx.sess.psess.dcx.span_fatal(
binding.span,
"`#[spirv(binding = ...)]` cannot apply to `#[spirv(spec_constant)]`",
);
@ -689,7 +690,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
if let Some(flat) = attrs.flat {
if let Err(SpecConstant { .. }) = storage_class {
self.tcx.sess.span_fatal(
self.tcx.sess.psess.dcx.span_fatal(
flat.span,
"`#[spirv(flat)]` cannot apply to `#[spirv(spec_constant)]`",
);
@ -699,7 +700,7 @@ impl<'tcx> CodegenCx<'tcx> {
}
if let Some(invariant) = attrs.invariant {
if storage_class != Ok(StorageClass::Output) {
self.tcx.sess.span_fatal(
self.tcx.sess.psess.dcx.span_fatal(
invariant.span,
"`#[spirv(invariant)]` is only valid on Output variables",
);
@ -732,17 +733,17 @@ impl<'tcx> CodegenCx<'tcx> {
);
} else if is_subpass_input {
self.tcx
.sess
.sess.psess.dcx
.span_err(hir_param.ty_span, "Missing capability InputAttachment");
} else {
self.tcx.sess.span_err(
self.tcx.sess.psess.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.sess.psess.dcx.span_err(
hir_param.ty_span,
"Image types with dim = SubpassData require #[spirv(input_attachment_index)] decoration",
);
@ -840,7 +841,7 @@ impl<'tcx> CodegenCx<'tcx> {
{
self.tcx
.sess
.span_err(span, "entry-point parameter cannot contain `bool`s");
.psess.dcx.span_err(span, "entry-point parameter cannot contain `bool`s");
}
// Enforce Vulkan validation rules around `Flat` as accurately as possible,
@ -887,7 +888,7 @@ impl<'tcx> CodegenCx<'tcx> {
_ => None,
};
if let Some((span, must_or_cannot)) = flat_mismatch {
self.tcx.sess.span_err(
self.tcx.sess.psess.dcx.span_err(
span,
format!(
"`{execution_model:?}` entry-point `{storage_class:?}` parameter \

View File

@ -90,8 +90,7 @@ impl<'tcx> CodegenCx<'tcx> {
let sym = Symbols::get();
let mut feature_names = tcx
.sess
.target_features
.sess.target_features
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>();
@ -106,7 +105,7 @@ impl<'tcx> CodegenCx<'tcx> {
.map(|s| s.parse())
.collect::<Result<_, String>>()
.unwrap_or_else(|error| {
tcx.sess.err(error);
tcx.sess.psess.dcx.err(error);
Vec::new()
});
@ -269,7 +268,7 @@ 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.psess.dcx.fatal(format!("Unable to parse llvm-args: {err}")),
}
}

View File

@ -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.sess.psess.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.sess.psess.dcx.emit_fatal(Spanned { span, node: err })
} else {
match fn_abi_request {
FnAbiRequest::OfFnPtr { sig, extra_args } => {
@ -107,22 +107,22 @@ impl<'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'tcx> {
}
}
fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64 {
match layout.abi {
Abi::Scalar(_) | Abi::ScalarPair(..) => {
bug!("backend_field_index({:?}): not applicable", layout);
}
_ => {}
}
match layout.fields {
FieldsShape::Primitive | FieldsShape::Union(_) => {
bug!("backend_field_index({:?}): not applicable", layout)
}
FieldsShape::Array { .. } => index as u64,
// note: codegen_llvm implements this as 1+index*2 due to padding fields
FieldsShape::Arbitrary { .. } => layout.fields.memory_index(index) as u64,
}
}
// fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64 {
// match layout.abi {
// Abi::Scalar(_) | Abi::ScalarPair(..) => {
// bug!("backend_field_index({:?}): not applicable", layout);
// }
// _ => {}
// }
// match layout.fields {
// FieldsShape::Primitive | FieldsShape::Union(_) => {
// bug!("backend_field_index({:?}): not applicable", layout)
// }
// FieldsShape::Array { .. } => index as u64,
// // note: codegen_llvm implements this as 1+index*2 due to padding fields
// FieldsShape::Arbitrary { .. } => layout.fields.memory_index(index) as u64,
// }
// }
fn scalar_pair_element_backend_type(
&self,
@ -164,13 +164,18 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
let ptr_size = self.tcx.data_layout.pointer_size.bits() as u32;
SpirvType::Integer(ptr_size, false).def(DUMMY_SP, self)
}
fn type_f16(&self) -> Self::Type {
SpirvType::Float(16).def(DUMMY_SP, self)
}
fn type_f32(&self) -> Self::Type {
SpirvType::Float(32).def(DUMMY_SP, self)
}
fn type_f64(&self) -> Self::Type {
SpirvType::Float(64).def(DUMMY_SP, self)
}
fn type_f128(&self) -> Self::Type {
SpirvType::Float(128).def(DUMMY_SP, self)
}
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type {
SpirvType::Array {
@ -195,7 +200,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
align,
size,
field_types: els,
field_offsets: &field_offsets,
field_offsets: field_offsets.as_slice(),
field_names: None,
}
.def(DUMMY_SP, self)
@ -212,7 +217,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
other => self
.tcx
.sess
.fatal(format!("Invalid float width in type_kind: {other}")),
.psess.dcx.fatal(format!("Invalid float width in type_kind: {other}")),
},
SpirvType::Adt { .. } | SpirvType::InterfaceBlock { .. } => {
TypeKind::Struct
@ -241,7 +246,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.sess.psess.dcx.fatal(format!(
"element_type called on invalid type: {spirv_type:?}"
)),
}
@ -254,7 +259,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
ty => self
.tcx
.sess
.fatal(format!("vector_length called on non-vector type: {ty:?}")),
.psess.dcx.fatal(format!("vector_length called on non-vector type: {ty:?}")),
}
}
@ -264,7 +269,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
ty => self
.tcx
.sess
.fatal(format!("float_width called on non-float type: {ty:?}")),
.psess.dcx.fatal(format!("float_width called on non-float type: {ty:?}")),
}
}
@ -275,7 +280,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
ty => self
.tcx
.sess
.fatal(format!("int_width called on non-integer type: {ty:?}")),
.psess.dcx.fatal(format!("int_width called on non-integer type: {ty:?}")),
}
}

View File

@ -16,7 +16,6 @@
//! [`spirv-tools`]: https://embarkstudios.github.io/rust-gpu/api/spirv_tools
//! [`spirv-tools-sys`]: https://embarkstudios.github.io/rust-gpu/api/spirv_tools_sys
#![feature(rustc_private)]
#![feature(array_methods)]
#![feature(assert_matches)]
#![feature(result_flattening)]
#![feature(lint_reasons)]
@ -39,7 +38,6 @@
compile_error!(
"Either \"use-compiled-tools\" (enabled by default) or \"use-installed-tools\" may be enabled."
);
extern crate rustc_apfloat;
extern crate rustc_arena;
extern crate rustc_ast;
@ -237,8 +235,7 @@ impl CodegenBackend for SpirvCodegenBackend {
Box::new(rustc_codegen_ssa::base::codegen_crate(
Self,
tcx,
tcx.sess
.opts
tcx.sess.opts
.cg
.target_cpu
.clone()
@ -253,15 +250,15 @@ impl CodegenBackend for SpirvCodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
_outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let (codegen_results, work_products) = ongoing_codegen
.downcast::<OngoingCodegen<Self>>()
.expect("Expected OngoingCodegen, found Box<Any>")
.join(sess);
sess.compile_status()?;
// sess.psess.dcx.compile_status().unwrap();
Ok((codegen_results, work_products))
(codegen_results, work_products)
}
fn link(
@ -279,7 +276,7 @@ impl CodegenBackend for SpirvCodegenBackend {
);
drop(timer);
sess.compile_status()?;
// sess.psess.dcx.compile_status()?;
Ok(())
}
}

View File

@ -87,7 +87,7 @@ pub fn link(
);
}
other => {
sess.err(format!("CrateType {other:?} not supported yet"));
sess.psess.dcx.err(format!("CrateType {other:?} not supported yet"));
}
}
match out_filename {
@ -124,7 +124,7 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa
..
} = lib.kind
{
sess.err(format!(
sess.psess.dcx.err(format!(
"adding native library to rlib not supported yet: {}",
lib.name
));
@ -278,7 +278,7 @@ fn post_link_single_module(
(optlevel, false) => format!("optlevel={optlevel:?}"),
(optlevel, true) => format!("optlevel={optlevel:?}, debuginfo=None"),
};
sess.warn(format!(
sess.psess.dcx.warn(format!(
"`spirv-opt` should have ran ({reason}) but was disabled by `--no-spirv-opt`"
));
spv_binary
@ -295,7 +295,7 @@ 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.psess.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();
@ -342,19 +342,30 @@ fn do_spirv_opt(
// TODO: Adds spans here? Not sure how useful with binary, but maybe?
let mut err = match msg.level {
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()
let mut err = sess.psess.dcx.struct_fatal(msg.message);
err.note(format!("module `{}`", filename.display()));
err.emit();
}
Level::Error => {
let mut err = sess.psess.dcx.struct_err(msg.message);
err.note(format!("module `{}`", filename.display()));
err.emit();
},
Level::Warning => {
let mut warn = sess.psess.dcx.struct_warn(msg.message);
warn.note(format!("module `{}`", filename.display()));
warn.emit();
},
Level::Info | Level::Debug => {
let mut note = sess.psess.dcx.struct_note(msg.message);
note.note(format!("module `{}`", filename.display()));
note.emit();
}
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),
};
err.note(format!("module `{}`", filename.display()));
err.emit();
},
Some(options),
);
@ -363,7 +374,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.psess.dcx.struct_warn(e.to_string());
err.note("spirv-opt failed, leaving as unoptimized");
err.note(format!("module `{}`", filename.display()));
err.emit();
@ -383,7 +394,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.psess.dcx.struct_err(e.to_string());
err.note("spirv-val failed");
err.note(format!("module `{}`", filename.display()));
err.emit();
@ -433,7 +444,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.psess.dcx.err("TODO: Linkage::Dynamic not supported yet");
}
}
}
@ -467,7 +478,7 @@ fn add_upstream_native_libraries(
..
} => {}
_ => sess.fatal(format!(
_ => sess.psess.dcx.fatal(format!(
"`NativeLibKind::{:?}` (name={:?}) not supported yet",
lib.kind, lib.name
)),
@ -480,7 +491,7 @@ fn add_upstream_native_libraries(
// (see `compiler/rustc_codegen_ssa/src/back/link.rs`)
fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
match lib.cfg {
Some(ref cfg) => rustc_attr::cfg_matches(cfg, &sess.parse_sess, CRATE_NODE_ID, None),
Some(ref cfg) => rustc_attr::cfg_matches(cfg, sess, CRATE_NODE_ID, None),
None => true,
}
}
@ -600,7 +611,7 @@ fn do_link(
match link_result {
Ok(v) => v,
Err(rustc_errors::ErrorGuaranteed { .. }) => {
sess.abort_if_errors();
sess.psess.dcx.abort_if_errors();
bug!("Linker errored, but no error reported");
}
}

View File

@ -56,7 +56,7 @@ 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.psess.dcx.err(format!("Multiple exports found for {name:?}")));
}
}
let mut any_err = None;
@ -68,7 +68,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.psess.dcx.err(format!("Unresolved symbol {name:?}")));
continue;
}
Some(&x) => x,
@ -183,17 +183,16 @@ fn check_tys_equal(
format_ty(ty_defs, ty, &mut result);
result
}
Err(sess
.struct_err(format!("Types mismatch for {name:?}"))
.note(format!(
Err({let mut err = sess.psess.dcx
.struct_err(format!("Types mismatch for {name:?}"));
err.note(format!(
"import type: {}",
format_ty_(&ty_defs, import_type)
))
.note(format!(
));
err.note(format!(
"export type: {}",
format_ty_(&ty_defs, export_type)
))
.emit())
));err.emit()})
}
}

View File

@ -15,7 +15,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorGuaranteed;
use rustc_session::Session;
use smallvec::SmallVec;
use std::convert::TryInto;
use std::mem::{self, take};
type FunctionMap = FxHashMap<Word, Function>;
@ -117,7 +116,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.psess.dcx.warn(format!(
"`#[inline(never)]` function `{}` needs to be inlined \
because it has illegal argument or return types",
get_name(&names, f)
@ -235,7 +234,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.psess.dcx.err(format!(
"module has recursion, which is not allowed: `{current_name}` calls `{next_name}`"
)));
break;
@ -626,7 +625,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);

View File

@ -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.psess.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
)));
@ -425,11 +425,12 @@ pub fn link(
Err(e) => format!("could not be saved: {e}"),
};
return Err(sess
.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}"))
.emit());
return Err({let mut err = sess.psess.dcx
.struct_err(format!("{e}"));
err.note("while lowering SPIR-V module to SPIR-T (spirt::spv::lower)");
err.note(format!("input SPIR-V module {was_saved_msg}"));
err.emit()
});
}
}
};
@ -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.psess.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()
@ -542,8 +543,8 @@ pub fn link(
if opts.dump_spirt_passes.is_none() {
note.help("re-run with `RUSTGPU_CODEGEN_ARGS=\"--dump-spirt-passes=$PWD\"` for more details");
}
note.note("pretty-printed SPIR-T is preferred when reporting Rust-GPU issues")
.emit();
note.note("pretty-printed SPIR-T is preferred when reporting Rust-GPU issues");
note.emit();
}
// NOTE(eddyb) this is late so that `--dump-spirt-passes` is processed,
@ -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.psess.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.psess.dcx.err(format!(
"unsupported `OpExtInstImport {ext_inst_set:?}`
(expected {expected:?} name - version mismatch?)"
)));

View File

@ -244,13 +244,14 @@ pub fn check_fragment_insts(sess: &Session, module: &Module) -> Result<()> {
.chain(stack)
.collect::<Vec<_>>()
.join("\n");
any_err = Some(
sess.struct_err(format!(
any_err = Some({
let mut err = sess.psess.dcx.struct_err(format!(
"{} cannot be used outside a fragment shader",
inst.class.opname
))
.note(note)
.emit(),
));
err.note(note);
err.emit()
}
);
}
}

View File

@ -58,7 +58,6 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use smallvec::SmallVec;
use std::collections::{BTreeMap, VecDeque};
use std::convert::{TryFrom, TryInto};
use std::ops::{Range, RangeTo};
use std::{fmt, io, iter, mem, slice};

View File

@ -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::{Diag as DiagnosticBuilder, DiagMessage};
use rustc_session::Session;
use rustc_span::{Span, DUMMY_SP};
use smallvec::SmallVec;
@ -420,7 +420,7 @@ 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.psess.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 +463,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.psess.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.psess.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);
}

View File

@ -10,7 +10,6 @@ use spirt::{
TypeCtor, TypeDef, Value,
};
use std::collections::hash_map::Entry;
use std::convert::{TryFrom, TryInto};
use std::hash::Hash;
use std::{iter, slice};

View File

@ -12,7 +12,6 @@ use std::sync::{Arc, Mutex};
// https://github.com/rust-lang/rust/pull/115393 lands.
// We need to construct an emitter as yet another workaround,
// see https://github.com/rust-lang/rust/pull/102992.
extern crate termcolor;
use termcolor::{ColorSpec, WriteColor};
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
@ -101,12 +100,12 @@ fn link_with_linker_opts(
self.0.lock().unwrap().flush()
}
}
impl WriteColor for BufWriter {
impl rustc_errors::WriteColor for BufWriter {
fn supports_color(&self) -> bool {
false
}
fn set_color(&mut self, _spec: &ColorSpec) -> std::io::Result<()> {
fn set_color(&mut self, _spec: &rustc_errors::ColorSpec) -> std::io::Result<()> {
Ok(())
}
@ -132,7 +131,11 @@ fn link_with_linker_opts(
.unwrap();
let sopts =
rustc_session::config::build_session_options(&mut early_error_handler, &matches);
let sysroot = rustc_session::filesearch::materialize_sysroot(sopts.maybe_sysroot.clone());
let target_cfg =
rustc_session::config::build_target_config(&early_error_handler, &sopts, None, &sysroot);
rustc_span::create_session_globals_then(sopts.edition, || {
let mut sess = rustc_session::build_session(
early_error_handler,
@ -151,7 +154,8 @@ fn link_with_linker_opts(
Default::default(),
Default::default(),
Default::default(),
Default::default(),
target_cfg,
sysroot,
rustc_interface::util::rustc_version_str().unwrap_or("unknown"),
Default::default(),
Default::default(),
@ -160,7 +164,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.dcx = {
sess.psess.dcx = {
let fallback_bundle = {
extern crate rustc_error_messages;
rustc_error_messages::fallback_fluent_bundle(
@ -169,10 +173,10 @@ fn link_with_linker_opts(
)
};
let emitter =
rustc_errors::emitter::EmitterWriter::new(Box::new(buf), fallback_bundle)
.sm(Some(sess.parse_sess.clone_source_map()));
rustc_errors::emitter::HumanEmitter::new(Box::new(buf), fallback_bundle)
.sm(Some(sess.psess.clone_source_map()));
rustc_errors::DiagCtxt::with_emitter(Box::new(emitter))
rustc_errors::DiagCtxt::new(Box::new(emitter))
.with_flags(sess.opts.unstable_opts.dcx_flags(true))
};
@ -191,14 +195,14 @@ fn link_with_linker_opts(
),
Default::default(),
);
assert_eq!(sess.has_errors(), res.as_ref().err().copied());
assert_eq!(sess.psess.dcx.has_errors(), res.as_ref().err().copied());
res.map(|res| match res {
LinkResult::SingleModule(m) => *m,
LinkResult::MultipleModules { .. } => unreachable!(),
})
})
})
.flatten()
.unwrap()
.map_err(|_e| {
let mut diags = output.unwrap_to_string();
if let Some(diags_without_trailing_newlines) = diags.strip_suffix("\n\n") {

View File

@ -6,7 +6,8 @@ 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::ErrorGuaranteed;
use rustc_errors::{Diag,DiagMessage};
use rustc_session::Session;
use rustc_span::{Span, DUMMY_SP};
use smallvec::SmallVec;
@ -239,7 +240,7 @@ impl<'a> ZombieReporter<'a> {
fn add_use_note_to_err(
&mut self,
err: &mut DiagnosticBuilder<'a, ErrorGuaranteed>,
err: &mut Diag<'a, ErrorGuaranteed>,
span: Span,
zombie: Zombie<'_>,
zombie_use: &ZombieUse<'_>,
@ -278,7 +279,7 @@ impl<'a> ZombieReporter<'a> {
fn build_errors_keyed_by_leaf_id(
&mut self,
zombie: Zombie<'_>,
) -> FxIndexMap<Word, DiagnosticBuilder<'a, ErrorGuaranteed>> {
) -> FxIndexMap<Word, Diag<'a, ErrorGuaranteed>> {
// 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 +295,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.psess.dcx.struct_span_err(span, reason.to_string()),
);
}
ZombieKind::Uses(zombie_uses) => {

View File

@ -298,7 +298,7 @@ impl SpirvType<'_> {
ref other => cx
.tcx
.sess
.fatal(format!("def_with_id invalid for type {other:?}")),
.psess.dcx.fatal(format!("def_with_id invalid for type {other:?}")),
};
cx.type_cache_def(result, self.tcx_arena_alloc_slices(cx), def_span);
result

View File

@ -545,7 +545,7 @@ fn parse_attr_int_value(arg: &NestedMetaItem) -> Result<u32, ParseAttrError> {
Some(&MetaItemLit {
kind: LitKind::Int(x, LitIntType::Unsuffixed),
..
}) if x <= u32::MAX as u128 => Ok(x as u32),
}) if x.get() <= u32::MAX as u128 => Ok(x.get() as u32),
_ => Err((arg.span, "attribute value must be integer".to_string())),
}
}
@ -563,7 +563,7 @@ fn parse_local_size_attr(arg: &NestedMetaItem) -> Result<[u32; 3], ParseAttrErro
NestedMetaItem::Lit(MetaItemLit {
kind: LitKind::Int(x, LitIntType::Unsuffixed),
..
}) if *x <= u32::MAX as u128 => local_size[idx] = *x as u32,
}) if x.get() <= u32::MAX as u128 => local_size[idx] = x.get() as u32,
_ => return Err((lit.span(), "must be a u32 literal".to_string())),
}
}

View File

@ -1,7 +1,7 @@
use rspirv::spirv::MemoryModel;
use rustc_target::spec::{Cc, LinkerFlavor, PanicStrategy, Target, TargetOptions};
use spirv_tools::TargetEnv;
use rustc_target::spec::TargetMetadata;
const ARCH: &str = "spirv";
pub struct SpirvTarget {
@ -101,6 +101,7 @@ impl SpirvTarget {
data_layout: "e-m:e-p:32:32:32-i64:64-n8:16:32:64".into(),
arch: ARCH.into(),
options: self.init_target_opts(),
metadata: TargetMetadata::default(),
}
}
}

View File

@ -1,7 +1,7 @@
[toolchain]
channel = "nightly-2023-12-21"
channel = "nightly-2024-03-14"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 5ac4c8a63ee305742071ac6dd11817f7c24adce2
# commit_hash = 3cbb93223f33024db464a4df27a13c7cce870173
# 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.