WSL should know that constexpr parameters are not lvalues
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 22:36:28 +0000 (22:36 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 22:36:28 +0000 (22:36 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222184 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js
Tools/WebGPUShadingLanguageRI/FuncParameter.js
Tools/WebGPUShadingLanguageRI/Test.js
Tools/WebGPUShadingLanguageRI/VariableDecl.js
Tools/WebGPUShadingLanguageRI/VariableRef.js

index 778efb0..af00092 100644 (file)
@@ -1,3 +1,34 @@
+2017-09-18  Filip Pizlo  <fpizlo@apple.com>
+
+        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  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r222170.
index 7041064..e4404a5 100644 (file)
@@ -37,6 +37,7 @@ class ConstexprTypeParameter extends Value {
     get type() { return this._type; }
     get isConstexpr() { return true; }
     get isUnifiable() { return true; }
+    get varIsLValue() { return false; }
     
     typeVariableUnify(unificationContext, other)
     {
index c022b7f..d0bb1d6 100644 (file)
@@ -37,6 +37,7 @@ class FuncParameter extends Value {
     get origin() { return this._origin; }
     get name() { return this._name; }
     get type() { return this._type; }
+    get varIsLValue() { return true; }
     
     toString()
     {
index 75adf81..91a78a4 100644 (file)
@@ -2625,7 +2625,7 @@ function TEST_simpleLength()
     checkUint(program, callFunction(program, "foo", [], []), 754);
 }
 
-function TEST_nonArrayRefArrayLength()
+function TEST_nonArrayRefArrayLengthSucceed()
 {
     let program = doPrep(`
         uint foo()
@@ -2637,6 +2637,55 @@ function TEST_nonArrayRefArrayLength()
     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(
index 7c3f374..768f8ba 100644 (file)
@@ -38,6 +38,7 @@ class VariableDecl extends Value {
     get name() { return this._name; }
     get type() { return this._type; }
     get initializer() { return this._initializer; }
+    get varIsLValue() { return true; }
     
     toString()
     {
index e194dd0..0075969 100644 (file)
@@ -42,7 +42,7 @@ class VariableRef extends Expression {
     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()