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

rustup: update to nightly-2023-05-27. #1071

Merged
merged 3 commits into from
Jun 8, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed 🛠
- [PR#1071](https://github.com/EmbarkStudios/rust-gpu/pull/1071) updated toolchain to `nightly-2023-05-27`

## [0.8.0]

### Added ⭐
Expand Down
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");
const REQUIRED_RUST_TOOLCHAIN: &str = r#"[toolchain]
channel = "nightly-2023-04-15"
channel = "nightly-2023-05-27"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
# commit_hash = 84dd17b56a931a631a23dfd5ef2018fd3ef49108"#;
# commit_hash = 1a5f8bce74ee432f7cc3aa131bc3d6920e06de10"#;

fn get_rustc_commit_hash() -> Result<String, Box<dyn Error>> {
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| String::from("rustc"));
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::spirv_type::SpirvType;
use rspirv::spirv::{StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_index::vec::Idx;
use rustc_index::Idx;
use rustc_middle::query::{ExternProviders, Providers};
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{
self, Const, FloatTy, GeneratorSubsts, IntTy, ParamEnv, PolyFnSig, Ty, TyCtxt, TyKind,
Expand Down Expand Up @@ -972,7 +972,7 @@ fn trans_intrinsic_type<'tcx>(
.tcx
.sess
.struct_span_err(span, "#[spirv(matrix)] type fields must all be vectors")
.note(&format!("field type is {}", ty.debug(elem_type, cx)))
.note(format!("field type is {}", ty.debug(elem_type, cx)))
.emit());
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{HirId, MethodKind, Target, CRATE_HIR_ID};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::query::Providers;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_span::{Span, Symbol};
use std::rc::Rc;
Expand Down Expand Up @@ -369,9 +369,9 @@ impl CheckSpirvAttrVisitor<'_> {
.sess
.struct_span_err(
span,
&format!("only one {category} attribute is allowed on a {target}"),
format!("only one {category} attribute is allowed on a {target}"),
)
.span_note(prev_span, &format!("previous {category} attribute"))
.span_note(prev_span, format!("previous {category} attribute"))
.emit();
}
},
Expand Down
25 changes: 21 additions & 4 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rustc_codegen_ssa::traits::{
use rustc_codegen_ssa::MemFlags;
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::ty::Ty;
use rustc_span::Span;
use rustc_target::abi::call::FnAbi;
Expand Down Expand Up @@ -760,9 +761,19 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
then_llbb: Self::BasicBlock,
else_llbb: Self::BasicBlock,
) {
self.emit()
.branch_conditional(cond.def(self), then_llbb, else_llbb, empty())
.unwrap();
let cond = cond.def(self);

// HACK(eddyb) constant-fold branches early on, as the `core` library is
// starting to get a lot of `if cfg!(debug_assertions)` added to it.
match self.builder.lookup_const_by_id(cond) {
Some(SpirvConst::Bool(true)) => self.br(then_llbb),
Some(SpirvConst::Bool(false)) => self.br(else_llbb),
_ => {
self.emit()
.branch_conditional(cond, then_llbb, else_llbb, empty())
.unwrap();
}
}
}

fn switch(
Expand Down Expand Up @@ -840,6 +851,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
fn invoke(
&mut self,
llty: Self::Type,
fn_attrs: Option<&CodegenFnAttrs>,
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
llfn: Self::Value,
args: &[Self::Value],
Expand All @@ -848,7 +860,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
funclet: Option<&Self::Funclet>,
) -> Self::Value {
// Exceptions don't exist, jump directly to then block
let result = self.call(llty, fn_abi, llfn, args, funclet);
let result = self.call(llty, fn_attrs, fn_abi, llfn, args, funclet);
self.emit().branch(then).unwrap();
result
}
Expand Down Expand Up @@ -2095,6 +2107,10 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
todo!()
}

fn filter_landing_pad(&mut self, _pers_fn: Self::Value) -> (Self::Value, Self::Value) {
todo!()
}

fn resume(&mut self, _exn0: Self::Value, _exn1: Self::Value) {
todo!()
}
Expand Down Expand Up @@ -2309,6 +2325,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
fn call(
&mut self,
callee_ty: Self::Type,
_fn_attrs: Option<&CodegenFnAttrs>,
_fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
callee: Self::Value,
args: &[Self::Value],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.debug_type(original_type)
));
if original_type != invalid_type {
err.note(&format!(
err.note(format!(
"due to containing type {}",
self.debug_type(invalid_type)
));
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.debug_type(original_type)
));
if original_type != value.ty {
err.note(&format!("due to containing type {}", value.ty));
err.note(format!("due to containing type {}", value.ty));
}
Err(err.emit())
}
Expand Down
14 changes: 1 addition & 13 deletions crates/rustc_codegen_spirv/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,4 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, 'tcx> {
}
}

impl<'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'tcx> {
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {
// ignore
}

fn typeid_metadata(&self, _typeid: String) -> Self::Value {
todo!()
}

fn set_kcfi_type_metadata(&self, _function: Self::Function, _typeid: u32) {
// ignore
}
}
impl<'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'tcx> {}
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
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!(
.note(format!(
"`{storage_class:?}` storage class was specified"
))
.help(&format!(
.help(format!(
"the storage class will be inferred automatically (e.g. to `{storage_class:?}`)"
))
.emit();
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl SpirvValue {
cx.tcx
.sess
.struct_span_err(span, "Can't use type as a value")
.note(&format!("Type: *{}", cx.debug_type(id)))
.note(format!("Type: *{}", cx.debug_type(id)))
.emit();

id
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn attrs_to_spirv(attrs: &CodegenFnAttrs) -> FunctionControl {
impl<'tcx> CodegenCx<'tcx> {
/// Returns a function if it already exists, or declares a header if it doesn't.
pub fn get_fn_ext(&self, instance: Instance<'tcx>) -> SpirvValue {
assert!(!instance.substs.needs_infer());
assert!(!instance.substs.has_infer());
assert!(!instance.substs.has_escaping_bound_vars());

if let Some(&func) = self.instances.borrow().get(&instance) {
Expand Down
3 changes: 2 additions & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl<'tcx> CodegenCx<'tcx> {
bx.set_span(span);
bx.call(
entry_func.ty,
None,
Some(entry_fn_abi),
entry_func,
&call_args,
Expand Down Expand Up @@ -317,7 +318,7 @@ impl<'tcx> CodegenCx<'tcx> {
)
.span_help(
storage_class_attr.span,
&format!(
format!(
"remove storage class attribute to use `{deduced:?}` as storage class"
),
)
Expand Down
63 changes: 17 additions & 46 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
use rustc_middle::mir::pretty::write_mir_pretty;
use rustc_middle::query;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, query, Instance, InstanceDef, TyCtxt};
use rustc_middle::ty::{self, Instance, InstanceDef, TyCtxt};
use rustc_session::config::{self, OutputFilenames, OutputType};
use rustc_session::Session;
use rustc_span::symbol::{sym, Symbol};
Expand Down Expand Up @@ -137,7 +138,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) = instance.def {
if let InstanceDef::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 All @@ -153,12 +154,12 @@ fn is_blocklisted_fn<'tcx>(
_ => false,
};

if is_debug_fmt_method(def.did) {
if is_debug_fmt_method(def_id) {
return true;
}

if tcx.opt_item_ident(def.did).map(|i| i.name) == Some(sym.fmt_decimal) {
if let Some(parent_def_id) = tcx.opt_parent(def.did) {
if tcx.opt_item_ident(def_id).map(|i| i.name) == Some(sym.fmt_decimal) {
if let Some(parent_def_id) = tcx.opt_parent(def_id) {
if is_debug_fmt_method(parent_def_id) {
return true;
}
Expand Down Expand Up @@ -491,47 +492,17 @@ impl Drop for DumpModuleOnPanic<'_, '_, '_> {
/// This is the entrypoint for a hot plugged `rustc_codegen_spirv`
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
// Override rustc's panic hook with our own to override the ICE error
// message, and direct people to `rust-gpu`.
let _rustc_hook = std::panic::take_hook();
let default_hook = std::panic::take_hook();
{
// NOTE(eddyb) the reason we can get access to the default panic hook,
// is that `std::panic::take_hook` has this phrase in its documentation:
//
// > If no custom hook is registered, the default hook will be returned.
//
// But just in case (races with other threads?), we can do it a few more
// times, and require that we get the same "boxed" ZST every time.
let more_hooks = [
std::panic::take_hook(),
std::panic::take_hook(),
std::panic::take_hook(),
std::panic::take_hook(),
];
assert_eq!(
std::mem::size_of_val(&*default_hook),
0,
"failed to acquire default panic hook using `std::panic::take_hook`, \
or default panic hook not a ZST anymore"
);
#[allow(clippy::vtable_address_comparisons)]
for other_hook in more_hooks {
assert!(
std::ptr::eq(&*default_hook, &*other_hook),
"failed to acquire default panic hook using `std::panic::take_hook`, \
or `std::panic::set_hook` was used on another thread"
);
}
}
std::panic::set_hook(Box::new(move |panic_info| {
default_hook(panic_info);
rustc_driver::report_ice(
panic_info,
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
);
eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION"));
}));
// Tweak rustc's default ICE panic hook, to direct people to `rust-gpu`.
rustc_driver::install_ice_hook(
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
|handler| {
handler.note_without_error(concat!(
"`rust-gpu` version `",
env!("CARGO_PKG_VERSION"),
"`"
));
},
);

Box::new(SpirvCodegenBackend)
}
22 changes: 11 additions & 11 deletions crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ fn post_link_single_module(
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");
err.note(&format!("module `{}`", out_filename.display()));
err.note(&format!("I/O error: {e:#}"));
err.note(format!("module `{}`", out_filename.display()));
err.note(format!("I/O error: {e:#}"));
err.emit();
}

Expand Down Expand Up @@ -324,14 +324,14 @@ fn do_spirv_opt(
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()
sess.struct_err(msg.message).forget_guarantee()
}
Level::Error => sess.struct_err(&msg.message).forget_guarantee(),
Level::Warning => sess.struct_warn(&msg.message),
Level::Info | Level::Debug => sess.struct_note_without_error(&msg.message),
Level::Error => sess.struct_err(msg.message).forget_guarantee(),
Level::Warning => sess.struct_warn(msg.message),
Level::Info | Level::Debug => sess.struct_note_without_error(msg.message),
};

err.note(&format!("module `{}`", filename.display()));
err.note(format!("module `{}`", filename.display()));
err.emit();
},
Some(options),
Expand All @@ -341,9 +341,9 @@ 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.struct_warn(e.to_string());
err.note("spirv-opt failed, leaving as unoptimized");
err.note(&format!("module `{}`", filename.display()));
err.note(format!("module `{}`", filename.display()));
err.emit();
spv_binary
}
Expand All @@ -361,9 +361,9 @@ 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.struct_err(e.to_string());
err.note("spirv-val failed");
err.note(&format!("module `{}`", filename.display()));
err.note(format!("module `{}`", filename.display()));
err.emit();
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_codegen_spirv/src/linker/import_export_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ fn check_tys_equal(
result
}
Err(sess
.struct_err(&format!("Types mismatch for {name:?}"))
.note(&format!(
.struct_err(format!("Types mismatch for {name:?}"))
.note(format!(
"import type: {}",
format_ty_(&ty_defs, import_type)
))
.note(&format!(
.note(format!(
"export type: {}",
format_ty_(&ty_defs, export_type)
))
Expand Down
11 changes: 11 additions & 0 deletions crates/rustc_codegen_spirv/src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ pub fn link(
}

if opts.early_report_zombies {
// HACK(eddyb) `report_and_remove_zombies` is bad at determining whether
// some things are dead (such as whole blocks), and there's no reason to
// *not* run DCE, given SPIR-T exists and makes DCE mandatory, but we're
// still only going to do the minimum necessary ("block ordering").
{
let _timer = sess.timer("link_block_ordering_pass-before-report_and_remove_zombies");
for func in &mut output.functions {
simple_passes::block_ordering_pass(func);
}
}

let _timer = sess.timer("link_report_and_remove_zombies");
zombies::report_and_remove_zombies(sess, opts, &mut output)?;
}
Expand Down
Loading