Title: [221859] trunk/Tools
Revision
221859
Author
[email protected]
Date
2017-09-11 10:18:38 -0700 (Mon, 11 Sep 2017)

Log Message

WSL should be able to handle a simple constexpr type parameter
https://bugs.webkit.org/show_bug.cgi?id=176676

Reviewed by Myles Maxfield.
        
This adds a test that uses a constexpr type parameter, and then fixed enough bugs to get this to work.

* WebGPUShadingLanguageRI/All.js:
* WebGPUShadingLanguageRI/CallExpression.js:
(CallExpression.prototype.resolve):
* WebGPUShadingLanguageRI/CheckWrapped.js: Added.
(checkWrapped):
* WebGPUShadingLanguageRI/Checker.js:
* WebGPUShadingLanguageRI/Evaluator.js:
(Evaluator.prototype.visitCallExpression):
(Evaluator):
* WebGPUShadingLanguageRI/Node.js:
(Node.prototype.substituteToUnification):
(Node.prototype.clone):
(Node):
* WebGPUShadingLanguageRI/Substitution.js:
(Substitution):
(Substitution.prototype.visitVariableRef):
* WebGPUShadingLanguageRI/Test.html:
* WebGPUShadingLanguageRI/Test.js:
(TEST_simpleConstexpr):
* WebGPUShadingLanguageRI/WrapChecker.js: Added.
(WrapChecker):
(WrapChecker.prototype.visitVariableRef):
(WrapChecker.prototype.visitTypeRef):
(WrapChecker.prototype.visitIntLiteral):
(WrapChecker.prototype._foundUnwrapped):
(WrapChecker.visitConstexprTypeParameter):
(WrapChecker.prototype.visitFuncParameter):
(WrapChecker.prototype.visitVariableDecl):
(WrapChecker.prototype.visitStructType):
(WrapChecker.prototype.visitNativeType):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (221858 => 221859)


--- trunk/Tools/ChangeLog	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/ChangeLog	2017-09-11 17:18:38 UTC (rev 221859)
@@ -1,3 +1,43 @@
+2017-09-10  Filip Pizlo  <[email protected]>
+
+        WSL should be able to handle a simple constexpr type parameter
+        https://bugs.webkit.org/show_bug.cgi?id=176676
+
+        Reviewed by Myles Maxfield.
+        
+        This adds a test that uses a constexpr type parameter, and then fixed enough bugs to get this to work.
+
+        * WebGPUShadingLanguageRI/All.js:
+        * WebGPUShadingLanguageRI/CallExpression.js:
+        (CallExpression.prototype.resolve):
+        * WebGPUShadingLanguageRI/CheckWrapped.js: Added.
+        (checkWrapped):
+        * WebGPUShadingLanguageRI/Checker.js:
+        * WebGPUShadingLanguageRI/Evaluator.js:
+        (Evaluator.prototype.visitCallExpression):
+        (Evaluator):
+        * WebGPUShadingLanguageRI/Node.js:
+        (Node.prototype.substituteToUnification):
+        (Node.prototype.clone):
+        (Node):
+        * WebGPUShadingLanguageRI/Substitution.js:
+        (Substitution):
+        (Substitution.prototype.visitVariableRef):
+        * WebGPUShadingLanguageRI/Test.html:
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_simpleConstexpr):
+        * WebGPUShadingLanguageRI/WrapChecker.js: Added.
+        (WrapChecker):
+        (WrapChecker.prototype.visitVariableRef):
+        (WrapChecker.prototype.visitTypeRef):
+        (WrapChecker.prototype.visitIntLiteral):
+        (WrapChecker.prototype._foundUnwrapped):
+        (WrapChecker.visitConstexprTypeParameter):
+        (WrapChecker.prototype.visitFuncParameter):
+        (WrapChecker.prototype.visitVariableDecl):
+        (WrapChecker.prototype.visitStructType):
+        (WrapChecker.prototype.visitNativeType):
+
 2017-09-11  Carlos Alberto Lopez Perez  <[email protected]>
 
         [WPE] Bump freetype version to 2.8.0

Modified: trunk/Tools/WebGPUShadingLanguageRI/All.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -49,6 +49,7 @@
 load("CheckRecursion.js");
 load("CheckReturns.js");
 load("CheckUnreachableCode.js");
+load("CheckWrapped.js");
 load("Checker.js");
 load("CommaExpression.js");
 load("ConstexprTypeParameter.js");
@@ -127,3 +128,5 @@
 load("WTrapError.js");
 load("WTypeError.js");
 load("WhileLoop.js");
+load("WrapChecker.js");
+

Modified: trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -45,7 +45,7 @@
     resolve(overload)
     {
         this.func = overload.func;
-        this.actualTypeArguments = overload.typeArguments.map(TypeRef.wrap);
+        this.actualTypeArguments = overload.typeArguments.map(typeArgument => typeArgument instanceof Type ? TypeRef.wrap(typeArgument) : typeArgument);
         let result = overload.func.returnType.substituteToUnification(
             overload.func.typeParameters, overload.unificationContext);
         if (!result)

Added: trunk/Tools/WebGPUShadingLanguageRI/CheckWrapped.js (0 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/CheckWrapped.js	                        (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/CheckWrapped.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+"use strict";
+
+// FIXME: This doesn't work on Program, so we can't call it from prepare.
+// https://bugs.webkit.org/show_bug.cgi?id=176678
+
+function checkWrapped(node)
+{
+    node.visit(new WrapChecker(node));
+}

Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -268,8 +268,7 @@
 
     visitCallExpression(node)
     {
-        for (let typeArgument of node.typeArguments)
-            typeArgument.visit(this);
+        let typeArgumentTypes = node.typeArguments.map(typeArgument => typeArgument.visit(this));
         let argumentTypes = node.argumentList.map(argument => {
             let newArgument = argument.visit(this);
             if (!newArgument)
@@ -313,6 +312,14 @@
                 throw new WTypeError(node.origin.originString, message);
             }
         }
+        for (let i = 0; i < typeArgumentTypes.length; ++i) {
+            let typeArgumentType = typeArgumentTypes[i];
+            let typeParameter = overload.func.typeParameters[i];
+            if (!(typeParameter instanceof ConstexprTypeParameter))
+                continue;
+            if (!typeParameter.type.equalsWithCommit(typeArgumentType))
+                throw new Error("At " + node.origin.originString + " constexpr type argument and parameter types not equal: argument = " + typeArgumentType + ", parameter = " + typeParameter.type);
+        }
         for (let i = 0; i < argumentTypes.length; ++i) {
             let argumentType = argumentTypes[i];
             let parameterType = overload.func.parameters[i].type.substituteToUnification(

Modified: trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -209,7 +209,8 @@
             let type = node.nativeFuncInstance.parameterTypes[i];
             if (!type || !argument)
                 throw new Error("Cannot get type or argument; i = " + i + ", argument = " + argument + ", type = " + type + "; in " + node);
-            callArguments.push(this._snapshot(type, argument.visit(this)));
+            let argumentValue = argument.visit(this);
+            callArguments.push(this._snapshot(type, argumentValue));
         }
         return node.func.implementation(callArguments, node);
     }

Modified: trunk/Tools/WebGPUShadingLanguageRI/IntLiteralType.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/IntLiteralType.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/IntLiteralType.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -64,7 +64,7 @@
     
     commitUnification(unificationContext)
     {
-        this.type = unificationContext.find(this);
+        this.type = TypeRef.wrap(unificationContext.find(this));
     }
     
     toString()

Modified: trunk/Tools/WebGPUShadingLanguageRI/Node.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Node.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Node.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -103,6 +103,13 @@
     
     substituteToUnification(parameters, unificationContext)
     {
-        return this.substitute(parameters, parameters.map(type => unificationContext.find(type)));
+        return this.substitute(
+            parameters,
+            parameters.map(type => unificationContext.find(type)));
     }
+    
+    clone()
+    {
+        return this.visit(new Rewriter());
+    }
 }

Modified: trunk/Tools/WebGPUShadingLanguageRI/Substitution.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Substitution.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Substitution.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -31,8 +31,11 @@
         if (parameters.length != argumentList.length)
             throw new Error("Parameters and arguments are mismatched");
         this._map = new Map();
-        for (let i = 0; i < parameters.length; ++i)
+        for (let i = 0; i < parameters.length; ++i) {
+            if (argumentList[i] instanceof Value)
+                checkWrapped(argumentList[i]);
             this._map.set(parameters[i], argumentList[i]);
+        }
     }
     
     visitTypeRef(node)
@@ -41,6 +44,11 @@
         if (replacement) {
             if (node.typeArguments.length)
                 throw new Error("Unexpected type arguments on type variable");
+            // When we substitute types, we simply wrap them in a ref. We do this because when we work with
+            // types, we often point to types directly.
+            // FIXME: What if we end of wrapping something like PtrType(TypeVariable)? Won't that then prevent
+            // further substitution?
+            // https://bugs.webkit.org/show_bug.cgi?id=176677
             return TypeRef.wrap(replacement);
         }
         
@@ -51,8 +59,12 @@
     visitVariableRef(node)
     {
         let replacement = this._map.get(node.variable);
-        if (replacement)
-            return VariableRef.wrap(replacement);
+        if (replacement) {
+            // FIXME: What if we end up getting passed a ConstexprTypeParameter? Won't that prevent further
+            // substitution?
+            // https://bugs.webkit.org/show_bug.cgi?id=176677
+            return replacement.clone();
+        }
         
         return super.visitVariableRef(node);
     }

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.html (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.html	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.html	2017-09-11 17:18:38 UTC (rev 221859)
@@ -25,6 +25,7 @@
 <script src=""
 <script src=""
 <script src=""
+<script src=""
 <script src=""
 <script src=""
 <script src=""
@@ -103,6 +104,7 @@
 <script src=""
 <script src=""
 <script src=""
+<script src=""
 
 <script src=""
 

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (221858 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-11 17:09:53 UTC (rev 221858)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -1423,6 +1423,21 @@
     `);
 }
 
+function TEST_simpleConstexpr()
+{
+    let program = doPrep(`
+        int foo<int a>(int b)
+        {
+            return a + b;
+        }
+        int bar(int b)
+        {
+            return foo<42>(b);
+        }
+    `);
+    checkInt(program, callFunction(program, "bar", [], [makeInt(program, 58)]), 58 + 42);
+}
+
 function TEST_break()
 {
     let program = doPrep(`

Added: trunk/Tools/WebGPUShadingLanguageRI/WrapChecker.js (0 => 221859)


--- trunk/Tools/WebGPUShadingLanguageRI/WrapChecker.js	                        (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/WrapChecker.js	2017-09-11 17:18:38 UTC (rev 221859)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+"use strict";
+
+class WrapChecker extends Visitor {
+    constructor(node)
+    {
+        super();
+        this._startNode = node;
+    }
+    
+    visitVariableRef(node)
+    {
+    }
+    
+    visitTypeRef(node)
+    {
+    }
+    
+    _foundUnwrapped(node)
+    {
+        throw new Error("Found unwrapped " + node.constructor.name + " at " + node.origin.originString + ": " + node + "\nWhile visiting " + this._startNode.constructor.name + " at " + this._startNode.origin.originString + ": " + this._startNode);
+    }
+    
+    visitConstexprTypeParameter(node)
+    {
+        this._foundUnwrapped(node);
+    }
+    
+    visitFuncParameter(node)
+    {
+        this._foundUnwrapped(node);
+    }
+    
+    visitVariableDecl(node)
+    {
+        this._foundUnwrapped(node);
+    }
+    
+    visitStructType(node)
+    {
+        this._foundUnwrapped(node);
+    }
+    
+    visitNativeType(node)
+    {
+        this._foundUnwrapped(node);
+    }
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to