Skip to content

Commit 4f67353

Browse files
committed
Various fixes and cleanup
While working on other patches that ended up not being applicable, I've gathered these changes unrelated to the irrelevant patch. So, submitting them as a seperate change, since the bigger change isn't going in.
1 parent 4dcb501 commit 4f67353

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

crates/rustc_codegen_spirv/src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,20 @@ fn get_env_dump_dir(env_var: &str) -> Option<PathBuf> {
621621
/// This is the entrypoint for a hot plugged `rustc_codegen_spirv`
622622
#[no_mangle]
623623
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
624-
// Override rustc's panic hook with our own to override the ICE error
625-
// message, and direct people to `rust-gpu`.
626-
std::panic::set_hook(Box::new(|panic_info| {
627-
rustc_driver::report_ice(
628-
panic_info,
629-
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
630-
);
631-
eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION"));
632-
}));
624+
// Setting the hook nukes the backtrace, so give developers an escape hatch to see the crash,
625+
// even if the message is wrong.
626+
// TODO: Figure out a way to print both the backtrace and override the bug report URL.
627+
if env::var_os("NO_PANIC_HOOK").is_none() {
628+
// Override rustc's panic hook with our own to override the ICE error
629+
// message, and direct people to `rust-gpu`.
630+
std::panic::set_hook(Box::new(|panic_info| {
631+
rustc_driver::report_ice(
632+
panic_info,
633+
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
634+
);
635+
eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION"));
636+
}));
637+
}
633638

634639
Box::new(SpirvCodegenBackend)
635640
}

crates/rustc_codegen_spirv/src/linker/dce.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ pub fn collect_roots(module: &Module) -> FxHashSet<Word> {
2525
rooted
2626
}
2727

28+
// Exactly the same as Function::all_inst_iter, except return type is `impl DoubleEndedIterator`
29+
// instead of `impl Iterator`
30+
fn all_inst_iter(func: &Function) -> impl DoubleEndedIterator<Item = &Instruction> {
31+
func.def
32+
.iter()
33+
.chain(func.parameters.iter())
34+
.chain(
35+
func.blocks
36+
.iter()
37+
.flat_map(|b| b.label.iter().chain(b.instructions.iter())),
38+
)
39+
.chain(func.end.iter())
40+
}
41+
2842
fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
2943
let mut any = false;
3044
for inst in module.global_inst_iter() {
@@ -40,18 +54,7 @@ fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
4054
// earlier insts, by reversing the iteration order, we're more likely to root the
4155
// entire relevant function at once.
4256
// See https://github.com/EmbarkStudios/rust-gpu/pull/691#discussion_r681477091
43-
for inst in func
44-
.end
45-
.iter()
46-
.chain(
47-
func.blocks
48-
.iter()
49-
.rev()
50-
.flat_map(|b| b.instructions.iter().rev().chain(b.label.iter())),
51-
)
52-
.chain(func.parameters.iter().rev())
53-
.chain(func.def.iter())
54-
{
57+
for inst in all_inst_iter(func).rev() {
5558
if !instruction_is_pure(inst) {
5659
any |= root(inst, rooted);
5760
} else if let Some(id) = inst.result_id {
@@ -111,13 +114,13 @@ fn kill_unrooted(module: &mut Module, rooted: &FxHashSet<Word>) {
111114
module
112115
.functions
113116
.retain(|f| is_rooted(f.def.as_ref().unwrap(), rooted));
114-
module.functions.iter_mut().for_each(|fun| {
115-
fun.blocks.iter_mut().for_each(|block| {
117+
for fun in &mut module.functions {
118+
for block in &mut fun.blocks {
116119
block
117120
.instructions
118121
.retain(|inst| !instruction_is_pure(inst) || is_rooted(inst, rooted));
119-
});
120-
});
122+
}
123+
}
121124
}
122125

123126
pub fn dce_phi(func: &mut Function) {

tests/ui/image/gather.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn main(
2020
#[cfg(not(any(
2121
target_env = "vulkan1.0",
2222
target_env = "vulkan1.1",
23+
target_env = "vulkan1.1spv1.4",
2324
target_env = "vulkan1.2"
2425
)))]
2526
#[spirv(fragment)]

0 commit comments

Comments
 (0)