Bug 189326

Summary: [WHLSL] The interpreter should evaluate arguments right-to-left
Product: WebKit Reporter: Thomas Denney <tdenney>
Component: WebGPUAssignee: Thomas Denney <tdenney>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: achristensen, dino, jonlee, mmaxfield, tdenney, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 189360    
Bug Blocks: 176199, 188402, 189202    
Attachments:
Description Flags
Patch
none
Patch
none
WIP none

Description Thomas Denney 2018-09-05 16:17:52 PDT
In order to be consistent with C, the arguments of function calls should be evaluated right-to-left. C doesn’t define an evaluation order for operators (like +) but because we treat them as “native functions” we should strictly evaluate them right-to-left.
Comment 1 Thomas Denney 2018-09-05 16:21:52 PDT
Created attachment 348978 [details]
Patch
Comment 2 Thomas Denney 2018-09-05 17:12:43 PDT
Created attachment 348982 [details]
Patch
Comment 3 Alex Christensen 2018-09-05 18:20:20 PDT
Comment on attachment 348982 [details]
Patch

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

This order is not determined in C or C++, but it is commonly evaluated in a consistent order for reasons.  See https://en.cppreference.com/w/c/language/eval_order
I think it would be great if WHLSL had a defined order, but don't claim it's to be consistent with C.

> Tools/ChangeLog:8
> +        The behavior of the interpreter now matches the behavior of the compiler

What compiler are you talking about?  It's possible the behavior of that compiler is unspecified but it happens to be right-to-left in all the cases you've checked.
Comment 4 Myles C. Maxfield 2018-09-05 19:12:39 PDT
Comment on attachment 348982 [details]
Patch

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

> Tools/WebGPUShadingLanguageRI/Test.js:7637
> +        int foo() { return *bar(10) + *bar(20); }
> +
> +        thread int* bar(int value)
> +        {
> +            int x = value;
> +            return &x;
> +        }

I don't think we should commit a test that is fundamentally wrong.
Comment 5 Thomas Denney 2018-09-05 19:26:10 PDT
(In reply to Alex Christensen from comment #3)
> Comment on attachment 348982 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=348982&action=review
> 
> This order is not determined in C or C++, but it is commonly evaluated in a
> consistent order for reasons.  See
> https://en.cppreference.com/w/c/language/eval_order
> I think it would be great if WHLSL had a defined order, but don't claim it's
> to be consistent with C.
> 
> > Tools/ChangeLog:8
> > +        The behavior of the interpreter now matches the behavior of the compiler
> 
> What compiler are you talking about?  It's possible the behavior of that
> compiler is unspecified but it happens to be right-to-left in all the cases
> you've checked.

The WHLSL -> Metal code generation generates code so that the arguments are explicitly evaluated right-to-left before the function call and are then passed separately.
Comment 6 Thomas Denney 2018-09-06 11:24:10 PDT
Created attachment 349046 [details]
WIP
Comment 7 Thomas Denney 2018-09-10 16:22:43 PDT
The most recent patch of https://bugs.webkit.org/show_bug.cgi?id=188641 resolves this, and it would only be a two line change to that patch to resolve this bug.

*** This bug has been marked as a duplicate of bug 188641 ***
Comment 8 Radar WebKit Bug Importer 2018-09-12 18:41:25 PDT
<rdar://problem/44402790>
Comment 9 Myles C. Maxfield 2018-10-13 14:35:40 PDT
Migrated to https://github.com/gpuweb/WHLSL/issues/42