Skip to content

Warn when something derives Debug #751

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

Closed
SiebenCorgie opened this issue Sep 12, 2021 · 5 comments
Closed

Warn when something derives Debug #751

SiebenCorgie opened this issue Sep 12, 2021 · 5 comments
Labels
s: wontfix This will not be worked on t: enhancement A new feature or improvement to an existing one.

Comments

@SiebenCorgie
Copy link
Contributor

When a struct derives the Debug trait, compilation fails with a strange error. For instance this struct

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct GpuCamera2d {
    pub location: [f32; 2],
    pub extent: [f32; 2],
    pub pad1: [f32; 3],
    pub rotation: f32,
}

Fails with the error:

     Compiling shared v0.1.0 (/../../shared)
  error: Cannot cast between pointer types
     --> /.../.../nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/array/mod.rs:219:9
      |
  219 |         Index::index(self as &[T], index)
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[f32; 2]
      = note: to: *[f32]

  error: Cannot cast between pointer types
     --> /.../.../nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/array/mod.rs:219:9
      |
  219 |         Index::index(self as &[T], index)
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[f32; 3]
      = note: to: *[f32]

  error: could not compile `shared` due to 2 previous errors

While the error is probably expected, I still searched for a while until I found the error. It would probably be nice to have an error like "Debug not supported".

@SiebenCorgie SiebenCorgie added the t: enhancement A new feature or improvement to an existing one. label Sep 12, 2021
@khyperia
Copy link
Contributor

Unfortunately, this is a really difficult problem to solve (... as is everything else that we haven't fixed yet 😛). The issue is that rust-gpu never sees anything like #[derive(Debug)], but instead a heap of rust code that looks exactly like the user wrote it, with no way to tell from what macro it was generated from, or even if it's generated at all. All it sees is some super wacky code that definitely won't work on the GPU, and so the only thing it can do is error on the bad code. Because of this, unfortunately, this issue will likely not be fixed any time soon.

This issue is mentioned in #744.

@XAMPPRocky
Copy link
Member

XAMPPRocky commented Sep 13, 2021

You could warn on any std::fmt usage, since that's what the Debug code generates and I don't think anything else in that module will work currently anyway.

@khyperia
Copy link
Contributor

Unfortunately it's not that simple. We need to consider all sorts of edge cases - for example, saying "you can't use #[derive(Debug)]" when directly referencing something in std::fmt is incorrect, confusing, and misleading.

@XAMPPRocky
Copy link
Member

We need to consider all sorts of edge cases - for example, saying "you can't use #[derive(Debug)]" when directly referencing something in std::fmt is incorrect, confusing, and misleading.

Right, that's how you phrase the warning, if the detection algorithm is coarse, so is the error message. FWIW I think something like the following would be enough, but you could be smarter about the message with a blocklist of all the std::fmt items to say which specific item is being used.

warning: Usage of std::fmt. This module will not compile on GPU platforms, remove or add #[cfg(not(target_arch="spirv")] to any std::fmt item, such as Debug, Display, format!, or write!.

@oisyn oisyn added the s: wontfix This will not be worked on label Nov 16, 2022
@oisyn
Copy link
Contributor

oisyn commented Nov 16, 2022

Closing this as a won't fix for now. I'll keep it in #744 as a reference.

@oisyn oisyn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: wontfix This will not be worked on t: enhancement A new feature or improvement to an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants