Title: [222184] trunk/Tools
Revision
222184
Author
[email protected]
Date
2017-09-18 15:36:28 -0700 (Mon, 18 Sep 2017)

Log Message

WSL should know that constexpr parameters are not lvalues
https://bugs.webkit.org/show_bug.cgi?id=177104

Reviewed by Saam Barati.
        
This should be an error:
        
    void foo<int x>()
    {
        x = 42;
    }
        
Previously, it wasn't, because VariableRef always thought that it was an LValue. This patch
teaches the type checker that not all VariableRefs are LValues.

* WebGPUShadingLanguageRI/ConstexprTypeParameter.js:
(ConstexprTypeParameter.prototype.get varIsLValue):
* WebGPUShadingLanguageRI/FuncParameter.js:
(FuncParameter.prototype.get varIsLValue):
* WebGPUShadingLanguageRI/Test.js:
(TEST_nonArrayRefArrayLengthSucceed):
(TEST_nonArrayRefArrayLengthFail):
(TEST_nonArrayRefArrayLength): Deleted.
(TEST_assignLength): Deleted.
* WebGPUShadingLanguageRI/VariableDecl.js:
(VariableDecl.prototype.get varIsLValue):
* WebGPUShadingLanguageRI/VariableRef.js:
(VariableRef.prototype.get isLValue):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (222183 => 222184)


--- trunk/Tools/ChangeLog	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/ChangeLog	2017-09-18 22:36:28 UTC (rev 222184)
@@ -1,3 +1,34 @@
+2017-09-18  Filip Pizlo  <[email protected]>
+
+        WSL should know that constexpr parameters are not lvalues
+        https://bugs.webkit.org/show_bug.cgi?id=177104
+
+        Reviewed by Saam Barati.
+        
+        This should be an error:
+        
+            void foo<int x>()
+            {
+                x = 42;
+            }
+        
+        Previously, it wasn't, because VariableRef always thought that it was an LValue. This patch
+        teaches the type checker that not all VariableRefs are LValues.
+
+        * WebGPUShadingLanguageRI/ConstexprTypeParameter.js:
+        (ConstexprTypeParameter.prototype.get varIsLValue):
+        * WebGPUShadingLanguageRI/FuncParameter.js:
+        (FuncParameter.prototype.get varIsLValue):
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_nonArrayRefArrayLengthSucceed):
+        (TEST_nonArrayRefArrayLengthFail):
+        (TEST_nonArrayRefArrayLength): Deleted.
+        (TEST_assignLength): Deleted.
+        * WebGPUShadingLanguageRI/VariableDecl.js:
+        (VariableDecl.prototype.get varIsLValue):
+        * WebGPUShadingLanguageRI/VariableRef.js:
+        (VariableRef.prototype.get isLValue):
+
 2017-09-18  Ryan Haddad  <[email protected]>
 
         Unreviewed, rolling out r222170.

Modified: trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js (222183 => 222184)


--- trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js	2017-09-18 22:36:28 UTC (rev 222184)
@@ -37,6 +37,7 @@
     get type() { return this._type; }
     get isConstexpr() { return true; }
     get isUnifiable() { return true; }
+    get varIsLValue() { return false; }
     
     typeVariableUnify(unificationContext, other)
     {

Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncParameter.js (222183 => 222184)


--- trunk/Tools/WebGPUShadingLanguageRI/FuncParameter.js	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncParameter.js	2017-09-18 22:36:28 UTC (rev 222184)
@@ -37,6 +37,7 @@
     get origin() { return this._origin; }
     get name() { return this._name; }
     get type() { return this._type; }
+    get varIsLValue() { return true; }
     
     toString()
     {

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222183 => 222184)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 22:36:28 UTC (rev 222184)
@@ -2625,7 +2625,7 @@
     checkUint(program, callFunction(program, "foo", [], []), 754);
 }
 
-function TEST_nonArrayRefArrayLength()
+function TEST_nonArrayRefArrayLengthSucceed()
 {
     let program = doPrep(`
         uint foo()
@@ -2637,6 +2637,55 @@
     checkUint(program, callFunction(program, "foo", [], []), 754);
 }
 
+function TEST_nonArrayRefArrayLengthFail()
+{
+    checkFail(
+        () => doPrep(`
+            thread uint^ lengthPtr()
+            {
+                int[42] array;
+                return &(array.length);
+            }
+        `),
+        e => e instanceof WTypeError);
+}
+
+function TEST_constexprIsNotLValuePtr()
+{
+    checkFail(
+        () => doPrep(`
+            thread int^ foo<int x>()
+            {
+                return &x;
+            }
+        `),
+        e => e instanceof WTypeError);
+}
+
+function TEST_constexprIsNotLValueAssign()
+{
+    checkFail(
+        () => doPrep(`
+            void foo<int x>()
+            {
+                x = 42;
+            }
+        `),
+        e => e instanceof WTypeError);
+}
+
+function TEST_constexprIsNotLValueRMW()
+{
+    checkFail(
+        () => doPrep(`
+            void foo<int x>()
+            {
+                x += 42;
+            }
+        `),
+        e => e instanceof WTypeError);
+}
+
 function TEST_assignLength()
 {
     checkFail(

Modified: trunk/Tools/WebGPUShadingLanguageRI/VariableDecl.js (222183 => 222184)


--- trunk/Tools/WebGPUShadingLanguageRI/VariableDecl.js	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/WebGPUShadingLanguageRI/VariableDecl.js	2017-09-18 22:36:28 UTC (rev 222184)
@@ -38,6 +38,7 @@
     get name() { return this._name; }
     get type() { return this._type; }
     get initializer() { return this._initializer; }
+    get varIsLValue() { return true; }
     
     toString()
     {

Modified: trunk/Tools/WebGPUShadingLanguageRI/VariableRef.js (222183 => 222184)


--- trunk/Tools/WebGPUShadingLanguageRI/VariableRef.js	2017-09-18 22:35:38 UTC (rev 222183)
+++ trunk/Tools/WebGPUShadingLanguageRI/VariableRef.js	2017-09-18 22:36:28 UTC (rev 222184)
@@ -42,7 +42,7 @@
     get name() { return this._name; }
     get isConstexpr() { return this.variable.isConstexpr; }
     get unifyNode() { return this.variable.unifyNode; } // This only makes sense when this is a constexpr.
-    get isLValue() { return true; }
+    get isLValue() { return this.variable.varIsLValue; }
     get addressSpace() { return "thread"; }
     
     toString()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to