-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Builtin function database, for automatic conversions #6833
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
Conversation
70f557d
to
6ed3edb
Compare
acd6a5c
to
fa9f489
Compare
e17f45e
to
6f2345c
Compare
669b817
to
107b177
Compare
89e3ef9
to
acb245f
Compare
acb245f
to
4b0303d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
4b0303d
to
0218277
Compare
55026f3
to
d5f7caf
Compare
This comment was marked as resolved.
This comment was marked as resolved.
d5f7caf
to
e9c2aaa
Compare
5753066
to
e7f8127
Compare
@ErichDonGubler @andyleiserson Okay, I believe I've addressed all comments with the current text of this PR. I've left some comments unresolved where I pushed back on the suggestion; please mark them resolved if you're okay with that. |
c887b92
to
98899c8
Compare
I'd overlooked this comment earlier. I've added these tests now. |
131184f
to
6b55a0b
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.
AFTER MANY EXHAUSTING HOURS OF EPIC WORK BY THE JIM
Here's yer green checkmark. ✨✅😀👍🏻✨
@andyleiserson, I presume your feedback is satisfied. If so, could you please indicate, and optionally rebase-and-merge? |
6b55a0b
to
fce1ef4
Compare
I've squashed all the changes that should have been squashed, so this can be landed with a rebase. If you want to see the last few revisions as separate commits, they're at https://github.com/jimblandy/wgpu/commits/naga-function-database-final-revisions/ |
Make the associated function `TypeInner::automatically_converts_to` available outside the WGSL front end by moving it into the `proc::type_methods` module.
Add a new module, `naga::common::predeclared`, which implements a new `struct_name` method on `naga::ir::PredeclaredType`, to produce the name of the struct type corresponding to that `PredeclaredType` value. Use this new method in `naga::front::type_gen`.
In the implementation of `TryToWgsl` for `Scalar`, order types within each representation from smallest to largest. This is just a cleanup; the change has no effect on behavior.
Define two new types in `naga::common`, `DiagnosticDisplay` and `DiagnosticDebug`, that allow Naga IR types to be formatted using `core::fmt::Display` and `core::fmt::Debug`. In `naga::common::wgsl`, add supporting implementations of `TypeContext` for `GlobalCtx` and `UniqueArena<Type>`
In `naga::front::wgsl::lower`, add a new method, `ExpressionContext::is_const`, for looking up the constness of a given expression. Change existing code to use it.
Define a new helper function on `naga::ir::TypeInner`, `scalar_for_conversions`, that returns the leaf scalar of a type as relevant for WGSL-style automatic conversions. Specifically, this means that, unlike `TypeInner::scalar`, arrays are considered to have leaf scalars if their elements do.
Introduce traits to add `for_debug` methods to Naga IR types that can be formatted with `core::fmt::Debug`, given adequate context.
Define a new trait, `proc::builtins::OverloadSet`, for types that represent a Naga IR builtin function's set of overloads. The `OverloadSet` trait includes operations needed to validate calls, choose automatic type conversions, and generate diagnostics. Add a new function, `ir::MathFunction::overloads`, which returns the given `MathFunction`'s set of overloads as an `impl OverloadSet` value. Use this in the WGSL front end, the validator, and the typifier. To support `MathFunction::overloads`, provide two implementations of `OverloadSet`: - `List` is flexible but verbose. - `Regular` is concise but more restrictive. Some snapshot output is affected because `TypeResolution::Handle` values turn into `TypeResolution::Value`, since the function database constructs the return type directly. To work around gfx-rs#7405, avoid offering abstract-typed overloads of some functions. This addresses gfx-rs#6443 for `MathFunction`, although that issue covers other categories of operations as well.
fce1ef4
to
93aa210
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.
LGTM as well, excited to see this land!
Depends on #7406.
Rebase without squashing.
Define a new trait,
proc::builtins::OverloadSet
, for types that represent a Naga IR builtin function's set of overloads. TheOverloadSet
trait includes operations needed to validate calls, choose automatic type conversions, and generate diagnostics.Add a new function,
ir::MathFunction::overloads
, which returns the givenMathFunction
's set of overloads as animpl OverloadSet
value. Use this in the WGSL front end, the validator, and the typifier.To support
MathFunction::overloads
, provide two implementations ofOverloadSet
:List
is flexible but verbose.Regular
is concise but more restrictive.Some snapshot output is affected because
TypeResolution::Handle
values turn intoTypeResolution::Value
, since the function database constructs the return type directly.This addresses #6443 for
MathFunction
, although that issue covers other categories of operations as well.Remaining work:
concrete_only
.