[WHLSL] Educate the property resolver about IndexExpressions
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jun 2019 22:59:40 +0000 (22:59 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jun 2019 22:59:40 +0000 (22:59 +0000)
commitb3fe8786292a872d8cff0deb8af81b680aeabd6f
treea9f7bef9f0fe1439787d96158426fa0077f86282
parent6fe911d6560ea5fff1ee3d5cd7dabaeeb611f202
[WHLSL] Educate the property resolver about IndexExpressions
https://bugs.webkit.org/show_bug.cgi?id=198399

Reviewed by Saam Barati.

Source/WebCore:

This is part one of two patches which will allow buffers to work. This patch
adds support in the property resolver for index expressions. Index expressions
get turned into calls to "getter indexers", "setter indexers", or "ander
indexers". They work almost identically to dot expressions, except there is an
extra "index" expression which gets turned into an extra argument to those
functions.

There's actually a bit of a trick here. Let's say we need to run a getter and
a setter separately (e.g. "foo[3]++;"). The index expression can't be duplicated
for both the getter and the setter (e.g. the functions are
int operator[](Foo, uint) and Foo operator[]=(Foo, uint, int), and we aren't
allowed to execute the index expression multiple times. Consider if that "3"
in the example is actually "bar()" with some side effect. So, we have to run
the index expression once at the correct time, and save its result to a temporary
variable, and then pass in the temporary variable into the getter and setter.

So, if the code says "foo[bar()][baz()] = quux();" the following sequence of
functions get run:

- bar()
- operator[](Foo, uint)
- baz()
- quux()
- operator[]=(OtherType, uint, OtherOtherType)
- operator[]=(Foo, uint, OtherType)

The next patch will modify the WebGPU JavaScript implementation to send buffer
lengths to the shader, and for the shader compiler to correctly unpack this
information and place it inside the array references. That should be everything
that's needed to get buffers to work. After that, hooking up compute should be
fairly trivial.

Tests: webgpu/propertyresolver/ander-abstract-lvalue.html
       webgpu/propertyresolver/ander-lvalue-3-levels.html
       webgpu/propertyresolver/ander-lvalue.html
       webgpu/propertyresolver/ander.html
       webgpu/propertyresolver/getter.html
       webgpu/propertyresolver/indexer-ander-abstract-lvalue.html
       webgpu/propertyresolver/indexer-ander-lvalue-3-levels.html
       webgpu/propertyresolver/indexer-ander-lvalue.html
       webgpu/propertyresolver/indexer-ander.html
       webgpu/propertyresolver/indexer-getter.html
       webgpu/propertyresolver/indexer-setter-abstract-lvalue-3-levels.html
       webgpu/propertyresolver/indexer-setter-abstract-lvalue.html
       webgpu/propertyresolver/indexer-setter-lvalue.html
       webgpu/propertyresolver/indexer-setter.html
       webgpu/propertyresolver/setter-abstract-lvalue-3-levels.html
       webgpu/propertyresolver/setter-abstract-lvalue.html
       webgpu/propertyresolver/setter-lvalue.html

* Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h:
(WebCore::WHLSL::AST::toString):
* Modules/webgpu/WHLSL/AST/WHLSLEntryPointType.h:
(WebCore::WHLSL::AST::toString):
* Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
(WebCore::WHLSL::AST::IndexExpression::takeIndex):
* Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
* Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
(WebCore::WHLSL::Metal::writeNativeFunction):
(WebCore::WHLSL::Metal::convertAddressSpace): Deleted.
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::checkOperatorOverload):
(WebCore::WHLSL::Checker::finishVisiting):
(WebCore::WHLSL::Checker::visit):
* Modules/webgpu/WHLSL/WHLSLInferTypes.h:
* Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
(WebCore::WHLSL::PropertyResolver::visit):
(WebCore::WHLSL::setterCall):
(WebCore::WHLSL::getterCall):
(WebCore::WHLSL::modify):
(WebCore::WHLSL::PropertyResolver::simplifyRightValue):
(WebCore::WHLSL::LeftValueSimplifier::finishVisiting):
(WebCore::WHLSL::LeftValueSimplifier::visit):
* Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:
* Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:
(WebCore::WHLSL::synthesizeStructureAccessors):

LayoutTests:

* webgpu/propertyresolver/ander-abstract-lvalue-expected.html: Added.
* webgpu/propertyresolver/ander-abstract-lvalue.html: Added.
* webgpu/propertyresolver/ander-expected.html: Added.
* webgpu/propertyresolver/ander-lvalue-3-levels-expected.html: Added.
* webgpu/propertyresolver/ander-lvalue-3-levels.html: Added.
* webgpu/propertyresolver/ander-lvalue-expected.html: Added.
* webgpu/propertyresolver/ander-lvalue.html: Added.
* webgpu/propertyresolver/ander.html: Added.
* webgpu/propertyresolver/getter-expected.html: Added.
* webgpu/propertyresolver/getter.html: Added.
* webgpu/propertyresolver/indexer-ander-abstract-lvalue-expected.html: Added.
* webgpu/propertyresolver/indexer-ander-abstract-lvalue.html: Added.
* webgpu/propertyresolver/indexer-ander-expected.html: Added.
* webgpu/propertyresolver/indexer-ander-lvalue-3-levels-expected.html: Added.
* webgpu/propertyresolver/indexer-ander-lvalue-3-levels.html: Added.
* webgpu/propertyresolver/indexer-ander-lvalue-expected.html: Added.
* webgpu/propertyresolver/indexer-ander-lvalue.html: Added.
* webgpu/propertyresolver/indexer-ander.html: Added.
* webgpu/propertyresolver/indexer-getter-expected.html: Added.
* webgpu/propertyresolver/indexer-getter.html: Added.
* webgpu/propertyresolver/indexer-setter-abstract-lvalue-3-levels-expected.html: Added.
* webgpu/propertyresolver/indexer-setter-abstract-lvalue-3-levels.html: Added.
* webgpu/propertyresolver/indexer-setter-abstract-lvalue-expected.html: Added.
* webgpu/propertyresolver/indexer-setter-abstract-lvalue.html: Added.
* webgpu/propertyresolver/indexer-setter-expected.html: Added.
* webgpu/propertyresolver/indexer-setter-lvalue-expected.html: Added.
* webgpu/propertyresolver/indexer-setter-lvalue.html: Added.
* webgpu/propertyresolver/indexer-setter.html: Added.
* webgpu/propertyresolver/setter-abstract-lvalue-3-levels-expected.html: Added.
* webgpu/propertyresolver/setter-abstract-lvalue-3-levels.html: Added.
* webgpu/propertyresolver/setter-abstract-lvalue-expected.html: Added.
* webgpu/propertyresolver/setter-abstract-lvalue.html: Added.
* webgpu/propertyresolver/setter-lvalue-expected.html: Added.
* webgpu/propertyresolver/setter-lvalue.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246385 268f45cc-cd09-0410-ab3c-d52691b4dbfc
46 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/propertyresolver/ander-abstract-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-abstract-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-lvalue-3-levels-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-lvalue-3-levels.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/ander.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/getter-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/getter.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-abstract-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-abstract-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-lvalue-3-levels-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-lvalue-3-levels.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-ander.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-getter-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-getter.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-abstract-lvalue-3-levels-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-abstract-lvalue-3-levels.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-abstract-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-abstract-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/indexer-setter.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-abstract-lvalue-3-levels-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-abstract-lvalue-3-levels.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-abstract-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-abstract-lvalue.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-lvalue-expected.html [new file with mode: 0644]
LayoutTests/webgpu/propertyresolver/setter-lvalue.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEntryPointType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp