-
Notifications
You must be signed in to change notification settings - Fork 195
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
[wgsl-in] Refactor construction lowering code. #2577
[wgsl-in] Refactor construction lowering code. #2577
Conversation
Components
enum in favor of slice patterns.8b30632
to
b6b0b68
Compare
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.
- [wgsl-in] Unify ConcreteConstructor and ConcreteConstructorHandle.
Replace theConcreteConstructor
andConcreteConstructorHandle
types infront::wgsl::lower::construction
with a single type
Constructor
with a type parameter that determines how it refers to
Naga types.
Nice refactor!
In the single-argument vector construction case, construct
Compose
expressions when the lengths don't match, and leave the problem for
validation to catch;validate_compose
is a better place to invest
time in improving diagnostics (and arguably producess more specific
error messages already).
This used to error with:
error: cannot cast a vec3<f32> to a vec2<f32>
┌─ wgsl:91:26
│
91 │ let test = vec2<f32>(vec3<f32>());
│ ^^^^^^^^^^ cannot cast a vec3<f32> to a vec2<f32>
It now errors with:
Naga module validation failed on test 'access.wgsl': WithSpan { inner: Function { handle: [2], name: "test_matrix_within_array_within_struct_accesses", source: Expression { handle: [71], source: Compose(ComponentCount { given: 3, expected: 2 }) } }, spans: [(Span { start: 1431, end: 2264 }, "naga::Function [2]"), (Span { start: 1921, end: 1943 }, "naga::Expression [71]")] }
I think we should keep this as it was (at least for now) as there are other cases where you'd run into this same error and it would keep things consistent.
- [wgsl-in] Remove
Components
enum in favor of slice patterns.
Removefront::wgsl::lower::construction::Components
, and simply use
slice patterns to decide which Naga code to generate. Supply the type
of the first argument, if available, as anOption
. This is slightly
redundant, as theOption
isSome
if and only if the slice is
non-empty, but in practice it is not too messy, and we can add match
arms to check for misalignment.
The nice thing about the Components
enum was that it worked around rust's limitation on matching on Vec
s. With this change, we are matching on slices and then have to copy the components.
I also found it easier to read the code before (even if it was a bit more lengthy) since there are now 3 things we are matching on inside a tuple + the components being a tuple themselves (containing the handle and the span).
Okay - the intent was to make things clearer. I'll try putting it back. There was a reason I introduced the vector copies, related to my abstract types plan, but I'll see if I can keep them out. I do feel like there was room for improvement in the original |
Replace the `ConcreteConstructor` and `ConcreteConstructorHandle` types in `front::wgsl::lower::construction` with a single type `Constructor` with a type parameter that determines how it refers to Naga types.
b6b0b68
to
787b9bf
Compare
I ended up removing pretty much any changes to |
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.
Thanks, looks good!
(Draft because it depends an a bunch of other stuff.)
[wgsl-in] Unify ConcreteConstructor and ConcreteConstructorHandle.
Replace the
ConcreteConstructor
andConcreteConstructorHandle
types in
front::wgsl::lower::construction
with a single typeConstructor
with a type parameter that determines how it refers toNaga types.
In the single-argument vector construction case, construct
Compose
expressions when the lengths don't match, and leave the problem for
validation to catch;
validate_compose
is a better place to investtime in improving diagnostics (and arguably producess more specific
error messages already).
[wgsl-in] Remove
Components
enum in favor of slice patterns.Remove
front::wgsl::lower::construction::Components
, and simply useslice patterns to decide which Naga code to generate. Supply the type
of the first argument, if available, as an
Option
. This is slightlyredundant, as the
Option
isSome
if and only if the slice isnon-empty, but in practice it is not too messy, and we can add match
arms to check for misalignment.