Bug 193434

Summary: [WHLSL] Implement the loop checker
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, fpizlo, jonlee, justin_fan, rmorisset, saam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch saam: review+

Description Myles C. Maxfield 2019-01-14 21:37:30 PST
[WHLSL] Implement the loop checker
Comment 1 Myles C. Maxfield 2019-01-14 21:38:22 PST
Created attachment 359135 [details]
Patch
Comment 2 Myles C. Maxfield 2019-01-14 22:10:54 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.h:32
> +#include "WHLSLFunctionAttribute.h"
> +#include "WHLSLSemantic.h"
> +#include "WHLSLTypeArgument.h"

These can be deleted.
Comment 3 Myles C. Maxfield 2019-01-14 22:28:25 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

> Source/WebCore/ChangeLog:6
> +        This is a translation of https://github.com/gpuweb/WHLSL/blob/master/Source/LoopChecker.mjs into C++.

Need a "reviewed by" line
Comment 4 Robin Morisset 2019-01-15 10:16:19 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

r=me
I understand that you are translating the reference implementation file by file for simplicity, but I am a bit wary of the distance between both implementations on the one hand and the spec on the other. I guess I will try to update at least the reference implementation later on to follow the structure of the spec (in particular doing all of the type checking and validation in one pass, using the idea of "behaviors" aka types for statements that I used in the spec).

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:53
> +        if (m_loopDepth || m_switchDepth) {

Not sure this part is necessary: I don't think we allow function definitions within the bodies of other functions anyway.
Comment 5 Saam Barati 2019-01-15 12:33:31 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

LGTM

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:44
> +class LoopChecker : public Visitor {

I feel like a comment explaining what this does would be helpful. "findHighZombies" is not the most intuitive name.

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:53
>> +        if (m_loopDepth || m_switchDepth) {
> 
> Not sure this part is necessary: I don't think we allow function definitions within the bodies of other functions anyway.

Perhaps an assert?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:54
> +            setError();

I haven't reviewed other changes, so this is just a general comment, but don't we want error messages here?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:64
> +        ++m_loopDepth;

style: Maybe use:
SetForScope scope(m_loopDepth, m_loopDepth + 1) ?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:72
> +        ++m_loopDepth;

ditto

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:82
> +        WTF::visit(WTF::makeVisitor([&](AST::VariableDeclarationsStatement& variableDeclarationsStatement) {

style: maybe auto&?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:84
> +        }, [&](UniqueRef<AST::Expression>& expression) {

style: maybe auto&?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:92
> +        ++m_loopDepth;

ditto about SetForScope

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:102
> +        ++m_switchDepth;

ditto SetForScope

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:149
> +}
> +
> +}

Should we add the `// namespace X` comments here?
Comment 6 Myles C. Maxfield 2019-01-15 16:23:58 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:54
>> +            setError();
> 
> I haven't reviewed other changes, so this is just a general comment, but don't we want error messages here?

Yep.

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:82
>> +        WTF::visit(WTF::makeVisitor([&](AST::VariableDeclarationsStatement& variableDeclarationsStatement) {
> 
> style: maybe auto&?

Visitor needs to know the parameter types.

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:149
>> +}
> 
> Should we add the `// namespace X` comments here?

I'll do this in a follow-up patch.
Comment 7 Myles C. Maxfield 2019-01-15 16:27:06 PST
Committed r240018: <https://trac.webkit.org/changeset/240018>
Comment 8 Radar WebKit Bug Importer 2019-01-15 16:28:30 PST
<rdar://problem/47301321>
Comment 9 Myles C. Maxfield 2019-01-15 16:33:49 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

>>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:149
>>> +}
>> 
>> Should we add the `// namespace X` comments here?
> 
> I'll do this in a follow-up patch.

https://bugs.webkit.org/show_bug.cgi?id=193471
Comment 10 Saam Barati 2019-01-15 16:45:21 PST
Comment on attachment 359135 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=359135&action=review

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp:64
>> +        ++m_loopDepth;
> 
> style: Maybe use:
> SetForScope scope(m_loopDepth, m_loopDepth + 1) ?

This may have been bad advice. I don't think this matters ATM, but if we encounter an AST node that ++m_XYZ, but doesn't --m_XYZ, then my suggestion of using SetForScope is not equivalent.
Comment 11 Myles C. Maxfield 2019-01-15 19:27:18 PST
Committed r240026: <https://trac.webkit.org/changeset/240026>