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

Warn (or error) on a non-pub entrypoint #155

Open
LegNeato opened this issue Nov 23, 2024 · 2 comments
Open

Warn (or error) on a non-pub entrypoint #155

LegNeato opened this issue Nov 23, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@LegNeato
Copy link
Collaborator

(originally filed at EmbarkStudios/rust-gpu#1140)

When setting #[spirv(fragment)] on a non-pub function, rust-gpu errors with an obtuse error:

error: error:0:0 - No OpEntryPoint instruction was found. This is only allowed if the Linkage capability is being used.

This case should be detected and warned or even made an error if it is not supported. Further, the error message should be fixed as suggested in EmbarkStudios/rust-gpu#1139.

@LegNeato LegNeato added the enhancement New feature or request label Nov 23, 2024
@LegNeato
Copy link
Collaborator Author

From discord eddyb says:

to add context to this, it's silly like this because specifically the #[spirv(...)] attributes that denote an entry-point are only processed when that function is codegen'd. this also means you can probably cause it to be monomorphized more than once if you do weird things with calling it from other functions :/

@zanciks
Copy link
Contributor

zanciks commented Nov 27, 2024

Hi! Interested in helping here, but looking for some guidance if possible, because I'm a bit unsure.
Looking at where #[spirv()] is defined, crates/spirv-std/macros/src/lib.rs, it seems like the only thing that we really have to add is something like

let input = syn::parse_macro_input!(item as ItemFn);

if !matches!(input.vis, Visibility::Public(_)) {
        panic!("The `spirv` macro can only be applied to public functions.");
}

error: custom attribute panicked
 --> src/main.rs:5:1
  |
5 | #[spirv(fragment)]
  | ^^^^^^^^^^^^^^^^^^
  |
  = help: message: The `spirv` macro can only be applied to public functions.

right? However, if warning is preferred over panic, then we might want to wait until this feature is stable.

If this is fine, I can get a PR in today, but unsure if this is exactly what is wanted here. Thanks in advance for any feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants