-
Notifications
You must be signed in to change notification settings - Fork 42
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
Rusty imports #41
Rusty imports #41
Conversation
- handle quoted strings as part of an identifier - allow only double colons as part of an identifier
fixed
added some further tests to catch regressions. thanks @NiseVoid for testing and providing an import test case. |
I'm on board for this direction! This is going to make a lot of people very happy. |
This looks awesome! I'm hoping to check it out this weekend. |
i've tested properly against the bevy examples as well now (see draft pr linked above), and fixed a couple of minor issues (mainly around reporting errors in import declarations). |
@robtfm One odd thing I found is that when using #import "shaders/foo.wgsl" as foo
fn func() {
let foo = vec3(0.0);
} Now I get this error: error: expected identifier, found '"'
┌─ shaders/glowy.wgsl:47:9
│
47 │ let "foo.wgsl" = vec3(0.0);
│ ^ expected identifier
│
= expected identifier, found '"' But This still works fine: #import "shaders/foo.wgsl"::{somefunc}
fn func() {
let somefunc = vec3(0.0);
} I'm not sure if the #import "shaders/foo.wgsl" as foo
fn func() {
let a = foo::somefunc();
} This does still work currently, just wanted to check that you plan to continue to support this, and if so if it would be possible to avoid the var name issue? |
fixed, thanks. this happens because we (with very limited context) substitute imported identifiers directly. for imported names without quotes, the replacement is harmless - your local variable gets renamed in all the places it is used. with quoted imports the quoted name is not a valid variable name, so it failed. i've special-cased this. there will still be potentially misleading errors if your local variables shadow imported names (either raw module/item names or
yes, definitely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very happy with these changes!
); | ||
|
||
let input = r" | ||
#import a::b c, d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this style should be deprecated. Maybe we should print a warning when we identify these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added this. i guess that also means we should do a major minor version bump. this pr is not technically breaking but existing users of bevy 0.11 with naga_oil 0.9 would get deprecated warning spam from the console if the warning is on by default (which i think it should be).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this should land in naga_oil
0.10. I agree the warning should be on by default.
reworks the import mechanism to support more syntax to make it more rusty, and test for item use before importing to determine which imports are modules and which are items, which allows:
which will call to
part::of::path::remainder::function
existing code should work without changes (unless it uses
#import
ed overrides), see belowallows most imported items to end with
_
and numbers (Naga invariant error is confusing #30). still doesn't allow struct members to end with_
or numbers but it's progress.includes (a reworking of) include ifops in effective defs #39
supercedes don't require full module path in qualifiers #24 and Auto import fully qualified identifiers #25
partly breaks overrides - now overrides will only be applied if the overriding module is added as an additional import in the arguments to
Composer::make_naga_module
orComposer::add_composable_module
. this is necessary to support determining whether imports are modules or items. i think it's a worthwhile trade-off (not sure anybody is using overrides yet)i've spot-checked bevy, will test more thoroughly after some feedback. would very much appreciate tests from people using the crate outside of bevy core - @DGriffin91, @NiseVoid, @Aaron1011