Warn (or error) on a non-pub entrypoint
LegNeato opened this issue · 3 comments
(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.
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 :/
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!
Just wanted to note that I hit this error too, but it was on a public main where I'd followed Clippy's advice to add #[inline]. Of course just removing #[inline] fixed the error.