Skip to content

[wgsl-in] Implement template list discovery and handle all type resolution in the lowerer - #8386

Merged
teoxoy merged 48 commits into
gfx-rs:trunkfrom
teoxoy:tld
Jan 28, 2026
Merged

[wgsl-in] Implement template list discovery and handle all type resolution in the lowerer#8386
teoxoy merged 48 commits into
gfx-rs:trunkfrom
teoxoy:tld

Conversation

@teoxoy

@teoxoy teoxoy commented Oct 20, 2025

Copy link
Copy Markdown
Member

Connections
Resolves #4501.
Resolves #4406.
Resolves #4405.

Description
Almost all commits prior to implement template list discovery are refactors to get the frontend to look more similar to the spec and to make the needed changes easier to implement (most notably making the Tokenizer no longer impl Clone).

The template list discovery implementation differs from the spec only in structure (not in behavior) since we can do it lazily after tokenization.

The last 3 substantial commits move all type resolution to the lowerer since all identifiers that are part of types need to be resolved the same as all other identifiers.

Testing
Changed existing tests and added new ones.

Squash or Rebase?
Rebase.

@teoxoy
teoxoy force-pushed the tld branch 2 times, most recently from 9c99aa1 to d4b4df4 Compare October 20, 2025 16:36
@ErichDonGubler ErichDonGubler self-assigned this Oct 20, 2025
@jimblandy

Copy link
Copy Markdown
Member

I can take review here - I've been looking into this for a long time.

@jimblandy

Copy link
Copy Markdown
Member

@teoxoy It seems like a bunch of these early commits would be fine as independent cleanup PRs, like 42338ff and 4adede5.

Comment thread naga/src/front/wgsl/error.rs Outdated
@jimblandy

jimblandy commented Oct 21, 2025

Copy link
Copy Markdown
Member

So far I've reviewed the following commits and they all look fine:

527cf31a1 | * rename `function_call_or_assignment_statement` to `func_call_or_variable_updating_statement`
16c2777ba | * rename `function_statement` to `func_call_statement`
086c0e4c3 | * remove `lexer.clone()`
fe63d0753 | * rename `postfix` to `component_or_swizzle_specifier`
47108f674 | * update `lhs_expression` to be in line with the spec
75fbca1ed | * remove `peek_ident_with_span`
ed6a03205 | * remove `next_scalar_generic`
e99eb0149 | * rename `general_expression` to `expression`
54fe3ca2e | * rename `assignment_statement` to `variable_updating_statement`
4adede577 | * [wgsl] rename `type_decl` to `type_specifier`
42338fff3 | * add `optionally_typed_ident` fn

@teoxoy
teoxoy force-pushed the tld branch 3 times, most recently from 5f4abe6 to 13a9c1b Compare October 22, 2025 12:30
@teoxoy

teoxoy commented Oct 22, 2025

Copy link
Copy Markdown
Member Author

I removed the last commit that was adding a CTS test since it wasn't passing due to unrelated reasons and pushed 2 more commits to fix the issues CI surfaced.

@teoxoy

teoxoy commented Oct 22, 2025

Copy link
Copy Markdown
Member Author

@teoxoy It seems like a bunch of these early commits would be fine as independent cleanup PRs, like 42338ff and 4adede5.

They could but that would be lots of separate PRs to file and orchestrate since I think some of them depend on others. I could open a PR just with the refactor commits but then this PR would need to depend on that new one. Let me know.

@jimblandy jimblandy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the refactoring changes up to 4ebbc67df * implement template list discovery look good. I think there's a bug in the TLD code itself.

Comment thread naga/src/front/wgsl/parse/mod.rs
Comment thread naga/src/front/wgsl/parse/mod.rs Outdated
Comment thread naga/tests/naga/wgsl_errors.rs Outdated
Comment thread naga/src/front/wgsl/parse/lexer.rs
@andyleiserson

Copy link
Copy Markdown
Contributor

I pushed a version of this that is rebased on top of #7339 to https://github.com/andyleiserson/wgpu/commits/tld-rebased. The last commit resolves a semantic merge conflict with #7339. There were also merge conflicts with trunk in 314ba9b and cf9e111 that I resolved, and there is a merge conflict with #8545 that I was less sure how to handle (that change adds enable extension checks that need to be relocated somewhere else following the template list discovery changes).

@teoxoy

teoxoy commented Nov 26, 2025

Copy link
Copy Markdown
Member Author

@andyleiserson thanks for tracking the changes! I pushed a fully rebased version.

@teoxoy
teoxoy force-pushed the tld branch 2 times, most recently from d10766f to 5b76532 Compare November 27, 2025 15:56
@teoxoy
teoxoy requested a review from jimblandy November 27, 2025 16:01
@jimblandy

Copy link
Copy Markdown
Member

I pushed two very minor tweaks from today's reviewing.

@teoxoy

teoxoy commented Jan 7, 2026

Copy link
Copy Markdown
Member Author

The first one looks good but the 2nd one assumes that those statements always end with a semicolon. Off the top of my head they are also used in the for loop header.

@jimblandy

Copy link
Copy Markdown
Member

I pushed two very minor tweaks from today's reviewing.

The first one looks good but the 2nd one assumes that those statements always end with a semicolon. Off the top of my head they are also used in the for loop header.

Okay, right - I fixed these.

Pushed a few more, and some tweaks, please take a look.

@jimblandy

Copy link
Copy Markdown
Member

The template list discovery commit looks good to me.

Comment thread naga/src/front/wgsl/parse/lexer.rs Outdated
teoxoy and others added 2 commits January 27, 2026 12:29
This improves errors making them more general where appropriate.
In `naga::front::wgsl::parse::Parser::component_or_swizzle_specifier`,
since `span_start` sounds like the start of a span, rename that
argument to `expr_start`, since it is the span of the start of the
expression that ends with the component or swizzle specifier.
@jimblandy

Copy link
Copy Markdown
Member

@teoxoy Before we merge this, could you take a quick look at the way cooperative matrix types and functions are handled? I think just looking at the tip should be fine, no need to sort through all the commits.

@jimblandy

Copy link
Copy Markdown
Member

I just gave all the cooperative stuff a quick look, and I didn't notice anything that looked like it was doing things the old way.

  • The only occurrences of the names of the coop_mat types are in conv::map_predeclared_type.
  • Those map the types to a variant of TypeGenerator, like all our other builtin type generators.
  • The only occurrences of the names of the coop functions are in Lowerer::call, where they belong.
  • The only occurrences of ir::TypeInner::CooperativeMatrix in the WGSL front end are:
    • where we parse the types
    • where we check the types of the arguments to the coop functions
    • where we decline to perform automatic conversions on the inner scalars

jimblandy and others added 13 commits January 27, 2026 14:21
Avoid adding entries to `ExpressionContext::unresolved` for
identifiers that `ExpressionContext::ident_expr` has already
processed.

At the moment, there is no way these could cause a bug: they only
occur after we've recognized a call/construction expression, and those
can never refer to function-local definitions, so the string in
question is certain to have already been added to `unresolved` by
`ExpressionContext::ident_expr`. But they're redundant, and if Naga
ever supported nested functions or local type aliases, these could end
up adding extraneous dependencies.
The name `scalar` suggests that it returns a scalar value, and
`scalar_ty` is analogous to `ty`.
- Clarify that various `foo_statement` functions on `Parser` do not
  consume the statement's final `;`.

- Various other doc fixes throughout.
Use `if let`, `let else`, and `Option` methods to reduce nesting and
clarify success paths.
Rather than passing `call_impl` an `ignore_builtin_identifiers` flag
and plumbing that through from its points of use, extend
`Namer::namespace` to suspend the `builtin_identifiers` table, as it
does for `unique` already. The resulting behavior is the same.
Adjust some methods of `TemplateListIter` to ensure that the typical
complete control flow through the function follows the outermost
nesting level.
Rename `naga::front::wgsl::error::Error::MissingTemplateArg::arg` to
`description`, to make it a little more specific.
@jimblandy

Copy link
Copy Markdown
Member

Since you marked this as "rebase", I consolidated my "doc fix" commits a bit, to keep the history cleaner.

@jimblandy

Copy link
Copy Markdown
Member

I have got to stop fiddling with this PR

@teoxoy

teoxoy commented Jan 28, 2026

Copy link
Copy Markdown
Member Author

The cooperative matrix stuff looks good to me; as you mentioned it looks to me like we handle them the same way as the other predeclared types & builtin functions.

@teoxoy

teoxoy commented Jan 28, 2026

Copy link
Copy Markdown
Member Author

Let's land this 🎉

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.

Implement WGSL template list discovery Allow shadowing of predeclared types and built-in functions [wgsl-in] Remove some texture types

4 participants