Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to nightly-2024.06.20 #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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-2024-04-24"
channel = "nightly-2024-06-20"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 244da22fabd9fa677bbd0ac601a88e5ca6917526"#;
# commit_hash = d8a38b00024cd7156dea4ce8fd8ae113a2745e7f"#;

fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));
Expand Down
19 changes: 12 additions & 7 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{
self, Const, CoroutineArgs, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind, UintTy,
self, Const, CoroutineArgs, CoroutineArgsExt, FloatTy, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt,
TyKind, UintTy,
};
use rustc_middle::{bug, span_bug};
use rustc_span::def_id::DefId;
use rustc_span::DUMMY_SP;
use rustc_span::{Span, Symbol};
use rustc_target::abi::call::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use rustc_target::abi::{
Abi, Align, FieldsShape, LayoutS, Primitive, Scalar, Size, TagEncoding, VariantIdx, Variants,
Abi, Align, FieldsShape, Float, LayoutS, Primitive, Scalar, Size, TagEncoding, VariantIdx,
Variants,
};
use rustc_target::spec::abi::Abi as SpecAbi;
use std::cell::RefCell;
Expand Down Expand Up @@ -504,10 +506,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::Float(Float::F16) => SpirvType::Float(16).def(span, cx),
Primitive::Float(Float::F32) => SpirvType::Float(32).def(span, cx),
Primitive::Float(Float::F64) => SpirvType::Float(64).def(span, cx),
Primitive::Float(Float::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
Expand Down Expand Up @@ -866,7 +868,10 @@ fn trans_intrinsic_type<'tcx>(
cx: &CodegenCx<'tcx>,
const_: Const<'tcx>,
) -> Result<P, ErrorGuaranteed> {
assert!(const_.ty().is_integral());
assert!(
matches!(const_.kind(), ty::ConstKind::Value(ty, _) if ty.is_integral()),
"Expected an integral type"
);
let value = const_.eval_bits(cx.tcx, ParamEnv::reveal_all());
match P::from_u128(value) {
Some(v) => Ok(v),
Expand Down
21 changes: 13 additions & 8 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let exit_bb = self.append_sibling_block("memset_exit");

let count = self.udiv(size_bytes, size_elem_const);
let index = self.alloca(count.ty, zero_align);
let index = self.alloca(Size::from_bits(32), zero_align);
self.store(zero, index, zero_align);
self.br(header_bb);

Expand Down Expand Up @@ -1412,10 +1412,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
fn to_immediate_scalar(&mut self, val: Self::Value, _scalar: Scalar) -> Self::Value {
val
}
fn alloca(&mut self, _size: Size, _align: Align) -> Self::Value {
// Define a u32 type for the allocation.
let u32_type = SpirvType::Integer(32, false).def(rustc_span::DUMMY_SP, self.cx);

fn alloca(&mut self, ty: Self::Type, _align: Align) -> Self::Value {
let ptr_ty = self.type_ptr_to(ty);
// "All OpVariable instructions in a function must be the first instructions in the first block."
// Define a pointer to the u32 type.
let ptr_ty = SpirvType::Pointer { pointee: u32_type }.def(rustc_span::DUMMY_SP, self.cx);

// "All OpVariable instructions in a function must be the first instructions in
// the first block."
let mut builder = self.emit();
builder.select_block(Some(0)).unwrap();
let index = {
Expand Down Expand Up @@ -1446,7 +1451,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
result_id.with_type(ptr_ty)
}

fn byte_array_alloca(&mut self, _len: Self::Value, _align: Align) -> Self::Value {
fn dynamic_alloca(&mut self, _len: Self::Value, _align: Align) -> Self::Value {
self.fatal("array alloca not supported yet")
}

Expand Down Expand Up @@ -3171,10 +3176,10 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
let debug_printf_fmt = match (spec, scalar) {
// FIXME(eddyb) support more of these,
// potentially recursing to print ADTs.
(' ' | '?', Some(Int(I32, false))) => "%u",
(' ' | '?', Some(Int(_i32, false))) => "%u",
('x', Some(Int(I32, false))) => "%x",
(' ' | '?', Some(Int(I32, true))) => "%i",
(' ' | '?', Some(F32)) => "%f",
(' ' | '?', Some(Int(_i32, true))) => "%i",
(' ' | '?', Some(_f32)) => "%f",

_ => "",
};
Expand Down
16 changes: 8 additions & 8 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::bug;
use rustc_middle::mir::interpret::{alloc_range, ConstAllocation, GlobalAlloc, Scalar};
use rustc_middle::ty::layout::LayoutOf;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{self, AddressSpace, HasDataLayout, Integer, Primitive, Size};
use rustc_target::abi::{self, AddressSpace, Float, HasDataLayout, Integer, Primitive, Size};

impl<'tcx> CodegenCx<'tcx> {
pub fn def_constant(&self, ty: Word, val: SpirvConst<'_, 'tcx>) -> SpirvValue {
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
match scalar {
Scalar::Int(int) => {
assert_eq!(int.size(), layout.primitive().size(self));
let data = int.assert_uint(int.size());
let data = int.to_uint(int.size());

match layout.primitive() {
Primitive::Int(int_size, int_signedness) => match self.lookup_type(ty) {
Expand All @@ -273,21 +273,21 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
other.debug(ty, self)
)),
},
Primitive::F16 => self
Primitive::Float(Float::F16) => self
.tcx
.dcx()
.fatal("scalar_to_backend Primitive::F16 not supported"),
Primitive::F32 => {
Primitive::Float(Float::F32) => {
let res = self.constant_f32(DUMMY_SP, f32::from_bits(data as u32));
assert_eq!(res.ty, ty);
res
}
Primitive::F64 => {
Primitive::Float(Float::F64) => {
let res = self.constant_f64(DUMMY_SP, f64::from_bits(data as u64));
assert_eq!(res.ty, ty);
res
}
Primitive::F128 => self
Primitive::Float(Float::F128) => self
.tcx
.dcx()
.fatal("scalar_to_backend Primitive::F128 not supported"),
Expand Down Expand Up @@ -488,8 +488,8 @@ impl<'tcx> CodegenCx<'tcx> {
Primitive::Int(integer, int_signedness)
}
SpirvType::Float(float_size) => match float_size {
32 => Primitive::F32,
64 => Primitive::F64,
32 => Primitive::Float(Float::F32),
64 => Primitive::Float(Float::F64),
other => {
self.tcx
.dcx()
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'tcx> CodegenCx<'tcx> {
let body = self
.tcx
.hir()
.body(self.tcx.hir().body_owned_by(fn_local_def_id));
.body(self.tcx.hir().body_owned_by(fn_local_def_id).id());
body.params
};
for (arg_abi, hir_param) in fn_abi.args.iter().zip(hir_params) {
Expand Down
40 changes: 21 additions & 19 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#![feature(assert_matches)]
#![feature(result_flattening)]
#![feature(lint_reasons)]
#![feature(lazy_cell)]
// crate-specific exceptions:
#![allow(
unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd
Expand Down Expand Up @@ -98,13 +97,13 @@ use rustc_codegen_ssa::traits::{
};
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, ModuleKind};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::{DiagCtxt, ErrorGuaranteed, FatalError};
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::mir::mono::{MonoItem, MonoItemData};
use rustc_middle::mir::pretty::write_mir_pretty;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, Instance, InstanceDef, TyCtxt};
use rustc_middle::ty::{self, Instance, InstanceKind, TyCtxt};
use rustc_session::config::{self, OutputFilenames, OutputType};
use rustc_session::Session;
use rustc_span::symbol::{sym, Symbol};
Expand All @@ -120,7 +119,7 @@ fn dump_mir(tcx: TyCtxt<'_>, mono_items: &[(MonoItem<'_>, MonoItemData)], path:
let mut file = File::create(path).unwrap();
for &(mono_item, _) in mono_items {
if let MonoItem::Fn(instance) = mono_item {
if matches!(instance.def, InstanceDef::Item(_)) {
if matches!(instance.def, InstanceKind::Item(_)) {
let mut mir = Cursor::new(Vec::new());
if write_mir_pretty(tcx, Some(instance.def_id()), &mut mir).is_ok() {
writeln!(file, "{}", String::from_utf8(mir.into_inner()).unwrap()).unwrap();
Expand All @@ -136,7 +135,7 @@ fn is_blocklisted_fn<'tcx>(
instance: Instance<'tcx>,
) -> bool {
// TODO: These sometimes have a constant value of an enum variant with a hole
if let InstanceDef::Item(def_id) = instance.def {
if let InstanceKind::Item(def_id) = instance.def {
if let Some(debug_trait_def_id) = tcx.get_diagnostic_item(sym::Debug) {
// Helper for detecting `<_ as core::fmt::Debug>::fmt` (in impls).
let is_debug_fmt_method = |def_id| match tcx.opt_associated_item(def_id) {
Expand Down Expand Up @@ -185,6 +184,9 @@ impl ThinBufferMethods for SpirvThinBuffer {
fn data(&self) -> &[u8] {
spirv_tools::binary::from_binary(&self.0)
}
fn thin_link_data(&self) -> &[u8] {
unimplemented!();
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -277,7 +279,7 @@ impl WriteBackendMethods for SpirvCodegenBackend {

fn run_link(
_cgcx: &CodegenContext<Self>,
_diag_handler: &DiagCtxt,
_diag_handler: DiagCtxtHandle<'_>,
_modules: Vec<ModuleCodegen<Self::Module>>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
todo!()
Expand Down Expand Up @@ -309,7 +311,7 @@ impl WriteBackendMethods for SpirvCodegenBackend {

unsafe fn optimize(
_: &CodegenContext<Self>,
_: &DiagCtxt,
_: DiagCtxtHandle<'_>,
_: &ModuleCodegen<Self::Module>,
_: &ModuleConfig,
) -> Result<(), FatalError> {
Expand Down Expand Up @@ -340,7 +342,7 @@ impl WriteBackendMethods for SpirvCodegenBackend {

unsafe fn codegen(
cgcx: &CodegenContext<Self>,
_diag_handler: &DiagCtxt,
_diag_handler: DiagCtxtHandle<'_>,
module: ModuleCodegen<Self::Module>,
_config: &ModuleConfig,
) -> Result<CompiledModule, FatalError> {
Expand All @@ -364,7 +366,10 @@ impl WriteBackendMethods for SpirvCodegenBackend {
})
}

fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
fn prepare_thin(
module: ModuleCodegen<Self::Module>,
_want_summary: bool,
) -> (String, Self::ThinBuffer) {
(module.name, SpirvThinBuffer(module.module_llvm))
}

Expand Down Expand Up @@ -482,16 +487,13 @@ impl Drop for DumpModuleOnPanic<'_, '_, '_> {
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
// Tweak rustc's default ICE panic hook, to direct people to `rust-gpu`.
rustc_driver::install_ice_hook(
"https://github.com/rust-gpu/rust-gpu/issues/new",
|handler| {
handler.note(concat!(
"`rust-gpu` version `",
env!("CARGO_PKG_VERSION"),
"`"
));
},
);
rustc_driver::install_ice_hook("https://github.com/rust-gpu/rust-gpu/issues/new", |dcx| {
dcx.handle().note(concat!(
"`rust-gpu` version `",
env!("CARGO_PKG_VERSION"),
"`"
));
});

Box::new(SpirvCodegenBackend)
}
9 changes: 8 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{link, LinkResult};
use rspirv::dr::{Loader, Module};
use rustc_errors::registry::Registry;
use rustc_session::config::{Input, OutputFilenames, OutputTypes};
use rustc_session::parse::ParseSess;
use rustc_session::CompilerIO;
use rustc_span::FileName;
use std::io::Write;
Expand Down Expand Up @@ -169,7 +170,11 @@ 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.psess.dcx = {
// HACK(legneato): This can be simplified to use `set_dcx()` when updating
// to a rustc version containing
// https://github.com/rust-lang/rust/commit/bde1f4dd57abd8e86dd7d7b325640558c4437d1f.
let source_map = sess.psess.clone_source_map();
let dcx = {
let fallback_bundle = {
extern crate rustc_error_messages;
rustc_error_messages::fallback_fluent_bundle(
Expand All @@ -185,6 +190,8 @@ fn link_with_linker_opts(
.with_flags(sess.opts.unstable_opts.dcx_flags(true))
};

sess.psess = ParseSess::with_dcx(dcx, source_map);

let res = link(
&sess,
modules,
Expand Down
3 changes: 3 additions & 0 deletions examples/runners/ash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" }
spirv-builder = { workspace = true, default-features = false }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }

[target.'cfg(target_os = "macos")'.dependencies]
ash-molten = { version = "0.13.1", features = ["pre-built"] }
3 changes: 3 additions & 0 deletions examples/runners/wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ clap = { version = "4", features = ["derive"] }
strum = { version = "0.25.0", default-features = false, features = ["std", "derive"] }
bytemuck = "1.6.3"

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }

[target.'cfg(not(any(target_os = "android", target_arch = "wasm32")))'.dependencies]
env_logger = "0.11.0"
spirv-builder = { workspace = true, features = ["watch"] }
Expand Down
3 changes: 3 additions & 0 deletions examples/shaders/compute-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ crate-type = ["dylib", "lib"]
[dependencies]
spirv-std = { workspace = true }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }

[target.'cfg(not(target_arch = "spirv"))'.dependencies]
rayon = "1.5"
3 changes: 3 additions & 0 deletions examples/shaders/mouse-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ crate-type = ["dylib"]
[dependencies]
shared = { path = "../../shaders/shared" }
spirv-std = { workspace = true }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
3 changes: 3 additions & 0 deletions examples/shaders/reduce/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ crate-type = ["dylib", "lib"]

[dependencies]
spirv-std = { workspace = true }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
3 changes: 3 additions & 0 deletions examples/shaders/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ repository.workspace = true
[dependencies]
spirv-std = { workspace = true }
bytemuck = { version = "1.18.0", features = ["derive"] }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
3 changes: 3 additions & 0 deletions examples/shaders/simplest-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ crate-type = ["dylib"]
[dependencies]
spirv-std = { workspace = true }
shared = { path = "../shared" }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
3 changes: 3 additions & 0 deletions examples/shaders/sky-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ crate-type = ["lib", "dylib"]
[dependencies]
shared = { path = "../../shaders/shared" }
spirv-std = { workspace = true }

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
channel = "nightly-2024-04-24"
channel = "nightly-2024-06-20"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = 244da22fabd9fa677bbd0ac601a88e5ca6917526
# commit_hash = d8a38b00024cd7156dea4ce8fd8ae113a2745e7f

# 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.
Loading