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

Migration from register_attr to register_tool #926

Merged
merged 22 commits into from
Oct 19, 2022
Merged

Migration from register_attr to register_tool #926

merged 22 commits into from
Oct 19, 2022

Conversation

oisyn
Copy link
Contributor

@oisyn oisyn commented Oct 14, 2022

We need this because the remove_attr feature was removed from the Rust nightly early September

@oisyn oisyn requested a review from repi October 14, 2022 13:09
@expenses

This comment was marked as resolved.

@oisyn oisyn marked this pull request as draft October 14, 2022 13:35
@oisyn

This comment was marked as resolved.

Copy link
Contributor

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: [# everywhere should be replaced with #[.
(the # is the attribute syntax, [ is merely a "container" - this is similar to how some languages have @foo and @bar(123) attributes but that @ is # in Rust and brackets exist to disambiguate something like #[allow(overflowing_literals)] (x + 200i8) which without the brackets would me ambiguous as to whether the parens are attached to allow - the languages that don't need that tend to be very limited in where you can apply attributes - anyway Rust can look like languages with [foo] attribute syntax but AFAIK it's closer to the @foo languages despite the aesthetics...)

@oisyn

This comment was marked as resolved.

@oisyn oisyn changed the title Moved from [#spirv(..)] to [#rust_gpu::spirv(..)] Moved from #[spirv(..)] to #[rust_gpu::spirv(..)] Oct 14, 2022
tests/src/main.rs Outdated Show resolved Hide resolved
@repi repi removed their request for review October 14, 2022 14:38
Copy link
Member

@fu5ha fu5ha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look this over exhaustively but the gist of the change is a 👍 from me

eddyb
eddyb previously requested changes Oct 17, 2022
crates/rustc_codegen_spirv/src/symbols.rs Outdated Show resolved Hide resolved
tests/ui/storage_class/runtime_descriptor_array.rs Outdated Show resolved Hide resolved
tests/ui/spirv-attr/invalid-target.rs Outdated Show resolved Hide resolved
tests/ui/lang/f32/signum.rs Outdated Show resolved Hide resolved
tests/src/main.rs Outdated Show resolved Hide resolved
crates/spirv-std/shared/src/lib.rs Show resolved Hide resolved
crates/spirv-builder/src/lib.rs Outdated Show resolved Hide resolved
crates/spirv-std/macros/src/lib.rs Outdated Show resolved Hide resolved
crates/spirv-std/macros/src/lib.rs Show resolved Hide resolved
crates/spirv-std/macros/src/lib.rs Show resolved Hide resolved
@oisyn oisyn changed the title Moved from #[spirv(..)] to #[rust_gpu::spirv(..)] Migrated from register_attr to register_tool Oct 18, 2022
@oisyn oisyn changed the title Migrated from register_attr to register_tool Migration from register_attr to register_tool Oct 18, 2022
@oisyn oisyn marked this pull request as ready for review October 19, 2022 07:45
@oisyn oisyn enabled auto-merge (squash) October 19, 2022 07:49
@oisyn oisyn disabled auto-merge October 19, 2022 08:17
@oisyn oisyn marked this pull request as draft October 19, 2022 08:21
@oisyn
Copy link
Contributor Author

oisyn commented Oct 19, 2022

Waiting for #929 first

oisyn pushed a commit that referenced this pull request Oct 19, 2022
This PR adds the commented out use spirv_std::spirv; to invalid-target.rs in preparation for #926
- We now always apply a proc_macro_attribute `spirv` that emits target-conditional `rust_gpu::spirv` attributes.
- Moved `no_std`, `feature(register_tool)` and `register_tool(rust_gpu)` to `SpirvBuilder`'s standard compile options
- Included `use spirv_std::spirv` in all tests
- Added `no_std`, `feature(register_tool)` and `register_tool(spirv)` to test dep compiler options
* Rearranged attrbute code parsing, added error for `#[rust_gpu::*]` cases where `*` is not `spirv`
* Removed `no_std` from standard rust-gpu crate attributes, readded it to `spirv-std`/`spirv-std-types`
* Removed (now useless) `register_tool(rust_gpu)` from examples
* Blessed one changed test
@oisyn oisyn marked this pull request as ready for review October 19, 2022 09:11
@oisyn oisyn enabled auto-merge (squash) October 19, 2022 09:16
@oisyn oisyn merged commit c3a9b9f into main Oct 19, 2022
@oisyn oisyn deleted the attr-to-tool branch October 19, 2022 09:50
Copy link
Contributor

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the only files I didn't check off as "viewed":

$$('.js-reviewed-checkbox').filter(x=>!x.checked).map(x=>x.parentNode.parentNode.path.value).join('\n')
tests/ui/arch/all.rs
tests/ui/arch/any.rs
tests/ui/arch/convert_u_to_acceleration_structure_khr.rs
tests/ui/arch/demote_to_helper_invocation.rs
tests/ui/arch/emit_stream_vertex.rs
tests/ui/arch/emit_vertex.rs
tests/ui/arch/end_primitive.rs
tests/ui/arch/end_stream_primitive.rs
tests/ui/arch/execute_callable.rs
tests/ui/arch/ignore_intersection_khr.rs
tests/ui/arch/kill.rs
tests/ui/arch/report_intersection_khr.rs
tests/ui/arch/terminate_ray_khr.rs
tests/ui/arch/trace_ray_khr.rs
tests/ui/image/issue_527.rs

But looks like GH decided to merge it anyway? :/

EDIT: those ended up being fixed by:

CHANGELOG.md Show resolved Hide resolved
tests/ui/spirv-attr/invalid-target.rs Show resolved Hide resolved
crates/rustc_codegen_spirv/src/symbols.rs Show resolved Hide resolved
@@ -93,8 +91,9 @@
//! Core functions, traits, and more that make up a "standard library" for SPIR-V for use in
//! rust-gpu.

#[cfg_attr(not(target_arch = "spirv"), macro_use)]
#[macro_use]
pub extern crate spirv_std_macros as macros;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked my previous comment asking about the pub here as resolved, but I don't remember what the explanation was, sorry - it's just that spirv_std::macros::... is used elsewhere, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I did this because the things in spirv-std now need spirv_std::spirv to be visible for all platforms. This way I didn't need to write use spirv_std::spirv; in every single file.

docs/src/migration-to-register-tool.md Show resolved Hide resolved
docs/src/migration-to-register-tool.md Show resolved Hide resolved
docs/src/migration-to-register-tool.md Show resolved Hide resolved

please remove the conditional attribute.

For this macro attribute to work correctly, it is important that `spirv` is visible in the global score and you use it like you used it before: `#[spirv(..)]`. An attempt to scope the attribute (such as `#[spirv_std::spirv(..)]`) will confuse the macro and likely fail.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to expand on this much more but to be clear this only applies to weird "leaf" things like function args, fields, etc. (which are replaced while transforming a larger thing that triggered the proc macro as usual).
Whole-definition attributes (e.g. the whole entry-point or a whole struct) will just work through normal name resolution.

Funny thing about that btw, if you only need it for a leaf, you need to do:

#[spirv()]
fn foo(
    #[spirv(ray_tracing_weirdness)] x: T,
) {}

(with the whole-fn one only serving to handle the inner ones lol - again, I don't think we have to mention this, since we don't have that many attributes to begin with, and so far such a usecase doesn't exist AFAIK, but I wanted to expand on it "for the record" so to speak)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do end up having a case where this applies (I don't think we do currently?), I'd suggest supporting #[spirv] without the parens.

Copy link
Contributor

@eddyb eddyb Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest supporting #[spirv] without the parens.

I don't think we have a say in the matter (i.e. both should work), and you likely can't tell them apart (since that's the proc macro, not the tool module one).

docs/src/migration-to-register-tool.md Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants