Skip to content

Commit

Permalink
Update to nightly-2024-06-20.
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Oct 14, 2024
1 parent c3b732d commit 9dccbd0
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 37 deletions.
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-05-20"
channel = "nightly-2024-06-20"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = d84b9037541f45dc2c52a41d723265af211c0497"#;
# 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
8 changes: 6 additions & 2 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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;
Expand Down Expand Up @@ -867,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(Size::from_bytes(size_bytes.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: Size, _align: Align) -> Self::Value {
let ptr_ty = self.type_ptr_to(ty.bits_usize() as u32);
// "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 dynamic_alloca(&mut self, _size: 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
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
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 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
2 changes: 1 addition & 1 deletion examples/shaders/compute-shader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "spirv", no_std)]
// HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds.
//#![deny(warnings)]
#![deny(warnings)]

use glam::UVec3;
use spirv_std::{glam, spirv};
Expand Down
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-05-20"
channel = "nightly-2024-06-20"
components = ["rust-src", "rustc-dev", "llvm-tools"]
# commit_hash = d84b9037541f45dc2c52a41d723265af211c0497
# 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.

0 comments on commit 9dccbd0

Please sign in to comment.