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

[WGSL] Add support for calls with simple built-in types #14076

Conversation

tadeuzagallo
Copy link
Member

@tadeuzagallo tadeuzagallo commented May 19, 2023

e511c23

[WGSL] Add support for calls with simple built-in types
https://bugs.webkit.org/show_bug.cgi?id=257028
rdar://109564906

Reviewed by Myles C. Maxfield.

Allow function calls with simple built-in types (i.e. function-style cast) such
as `f32(x)`. The way we currently handle it is not great, since we treat type
names as keywords in the lexer, but all of this will have to be refactored soon
when we update the parser to solve the template ambiguity. For now, this unblocks
a few more CTS tests to pass.

* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parsePrimaryExpression):

Canonical link: https://commits.webkit.org/264314@main

650d0c5

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@tadeuzagallo tadeuzagallo self-assigned this May 19, 2023
@tadeuzagallo tadeuzagallo added the WebGPU For bugs in WebGPU label May 19, 2023
Comment on lines +624 to +630
static constexpr std::pair<ComparableASCIILiteral, ASCIILiteral> baseTypesMappings[] {
{ "f32", "float"_s },
{ "i32", "int"_s },
{ "u32", "unsigned"_s }
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really the right way to do it? Users can create their own types, and their own types will have these kind of constructors too - but we can't literally list the user-defined types inside our WGSL compiler. I'd imagine both the user-defined type constructors and the primitive type constructors would be handled with the same infrastructure.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is isn't the right way to do it. But as I mentioned in the changelog, our whole definition of CallExpression needs to change, as we currently only allow types as the target, so this will all need to be refactored. I'm thinking that later we'll distinguish whether we're constructing a type or calling a function, and if we're constructing a type we can use the inferred type which would already account for any aliasing.

@tadeuzagallo tadeuzagallo added the merge-queue Applied to send a pull request to merge-queue label May 22, 2023
https://bugs.webkit.org/show_bug.cgi?id=257028
rdar://109564906

Reviewed by Myles C. Maxfield.

Allow function calls with simple built-in types (i.e. function-style cast) such
as `f32(x)`. The way we currently handle it is not great, since we treat type
names as keywords in the lexer, but all of this will have to be refactored soon
when we update the parser to solve the template ambiguity. For now, this unblocks
a few more CTS tests to pass.

* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parsePrimaryExpression):

Canonical link: https://commits.webkit.org/264314@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/WGSL-Add-support-for-calls-with-simple-built-in-types branch from 650d0c5 to e511c23 Compare May 22, 2023 07:13
@webkit-commit-queue
Copy link
Collaborator

Committed 264314@main (e511c23): https://commits.webkit.org/264314@main

Reviewed commits have been landed. Closing PR #14076 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit e511c23 into WebKit:main May 22, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebGPU For bugs in WebGPU
Projects
None yet
4 participants