Title: [221592] trunk/Tools
Revision
221592
Author
[email protected]
Date
2017-09-04 13:14:08 -0700 (Mon, 04 Sep 2017)

Log Message

Add more tests for null behavior in WSL
https://bugs.webkit.org/show_bug.cgi?id=176318

Reviewed by Myles Maxfield.
        
This adds more tests for the unification behavior of null. In the process, I found a couple
small bugs and fixed them.

* WebGPUShadingLanguageRI/Checker.js:
* WebGPUShadingLanguageRI/FuncInstantiator.js:
(FuncInstantiator.prototype.getUnique.InstantiationSubstitution.prototype.visitCallExpression):
(FuncInstantiator.prototype.getUnique.InstantiationSubstitution):
* WebGPUShadingLanguageRI/Substitution.js:
(Substitution.prototype.visitTypeRef):
* WebGPUShadingLanguageRI/Test.js:
(TEST_passNullAndNotNullFullPoly):
(TEST_passNullAndNotNullFullPolyReverse):
(TEST_nullTypeVariableUnify.recurse):
(TEST_nullTypeVariableUnify.everyOrder):
(TEST_nullTypeVariableUnify.everyPair):
(TEST_nullTypeVariableUnify):
* WebGPUShadingLanguageRI/TypeRef.js:
(TypeRef.wrap):
* WebGPUShadingLanguageRI/TypeVariable.js:
(TypeVariable.prototype.verifyAsArgument):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (221591 => 221592)


--- trunk/Tools/ChangeLog	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/ChangeLog	2017-09-04 20:14:08 UTC (rev 221592)
@@ -1,3 +1,31 @@
+2017-09-03  Filip Pizlo  <[email protected]>
+
+        Add more tests for null behavior in WSL
+        https://bugs.webkit.org/show_bug.cgi?id=176318
+
+        Reviewed by Myles Maxfield.
+        
+        This adds more tests for the unification behavior of null. In the process, I found a couple
+        small bugs and fixed them.
+
+        * WebGPUShadingLanguageRI/Checker.js:
+        * WebGPUShadingLanguageRI/FuncInstantiator.js:
+        (FuncInstantiator.prototype.getUnique.InstantiationSubstitution.prototype.visitCallExpression):
+        (FuncInstantiator.prototype.getUnique.InstantiationSubstitution):
+        * WebGPUShadingLanguageRI/Substitution.js:
+        (Substitution.prototype.visitTypeRef):
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_passNullAndNotNullFullPoly):
+        (TEST_passNullAndNotNullFullPolyReverse):
+        (TEST_nullTypeVariableUnify.recurse):
+        (TEST_nullTypeVariableUnify.everyOrder):
+        (TEST_nullTypeVariableUnify.everyPair):
+        (TEST_nullTypeVariableUnify):
+        * WebGPUShadingLanguageRI/TypeRef.js:
+        (TypeRef.wrap):
+        * WebGPUShadingLanguageRI/TypeVariable.js:
+        (TypeVariable.prototype.verifyAsArgument):
+
 2017-09-04  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r221494 and r221500.

Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -231,7 +231,7 @@
             let newArgument = argument.visit(this);
             if (!newArgument)
                 throw new Error("visitor returned null for " + argument);
-            return newArgument;
+            return TypeRef.wrap(newArgument);
         });
         node.argumentTypes = argumentTypes;
         

Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -64,7 +64,7 @@
                 // We may have to re-resolve the function call, if it was a call to a protocol
                 // signature.
                 if (result.func instanceof ProtocolFuncDecl) {
-                    let overload = thisInstantiator._program.resolveFuncOverload(node.name, node.typeArguments, node.argumentTypes);
+                    let overload = thisInstantiator._program.resolveFuncOverload(result.name, result.typeArguments, result.argumentTypes);
                     if (!overload.func)
                         throw new Error("Could not resolve protocol signature function call during instantiation: " + result.func + (overload.failures.length ? "; tried:\n" + overload.failures.join("\n") : ""));
                     result.resolve(overload);

Modified: trunk/Tools/WebGPUShadingLanguageRI/Substitution.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/Substitution.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/Substitution.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -44,7 +44,8 @@
             return TypeRef.wrap(replacement);
         }
         
-        return super.visitTypeRef(node);
+        let result = super.visitTypeRef(node);
+        return result;
     }
 
     visitVariableRef(node)

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -666,6 +666,115 @@
         (e) => e instanceof WTypeError);
 }
 
+function TEST_passNullAndNotNull()
+{
+    let program = doPrep(`
+        T bar<T:primitive>(device T^ p, device T^)
+        {
+            return ^p;
+        }
+        int foo(device int^ p)
+        {
+            return bar(p, null);
+        }
+    `);
+    let buffer = new EBuffer(1);
+    buffer.set(0, 13);
+    checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(null, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13);
+}
+
+function TEST_passNullAndNotNullFullPoly()
+{
+    let program = doPrep(`
+        T bar<T:primitive>(T p, T)
+        {
+            return p;
+        }
+        int foo(device int^ p)
+        {
+            return ^bar(p, null);
+        }
+    `);
+    let buffer = new EBuffer(1);
+    buffer.set(0, 13);
+    checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(null, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13);
+}
+
+function TEST_passNullAndNotNullFullPolyReverse()
+{
+    let program = doPrep(`
+        T bar<T:primitive>(T, T p)
+        {
+            return p;
+        }
+        int foo(device int^ p)
+        {
+            return ^bar(null, p);
+        }
+    `);
+    let buffer = new EBuffer(1);
+    buffer.set(0, 13);
+    checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(null, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13);
+}
+
+function TEST_nullTypeVariableUnify()
+{
+    let left = new NullType(null);
+    let right = new TypeVariable(null, "T", null);
+    if (left.equals(right))
+        throw new Error("Should not be equal but are: " + left + " and " + right);
+    if (right.equals(left))
+        throw new Error("Should not be equal but are: " + left + " and " + right);
+    
+    function everyOrder(array, callback)
+    {
+        function recurse(array, callback, order)
+        {
+            if (!array.length)
+                return callback.call(null, order);
+            
+            for (let i = 0; i < array.length; ++i) {
+                let nextArray = array.concat();
+                nextArray.splice(i, 1);
+                recurse(nextArray, callback, order.concat([array[i]]));
+            }
+        }
+        
+        recurse(array, callback, []);
+    }
+    
+    function everyPair(things)
+    {
+        let result = [];
+        for (let i = 0; i < things.length; ++i) {
+            for (let j = 0; j < things.length; ++j) {
+                if (i != j)
+                    result.push([things[i], things[j]]);
+            }
+        }
+        return result;
+    }
+    
+    everyOrder(
+        everyPair(["nullType", "variableType", "ptrType"]),
+        order => {
+            let types = {};
+            types.nullType = new NullType(null);
+            types.variableType = new TypeVariable(null, "T", null);
+            types.ptrType = new PtrType(null, "constant", new NativeType(null, "foo_t", true, []));
+            let unificationContext = new UnificationContext([types.variableType]);
+            for (let [leftName, rightName] of order) {
+                let left = types[leftName];
+                let right = types[rightName];
+                let result = left.unify(unificationContext, right);
+                if (!result)
+                    throw new Error("In order " + order + " cannot unify " + left + " with " + right);
+            }
+            if (!unificationContext.verify())
+                throw new Error("In order " + order.map(value => "(" + value + ")") + " cannot verify");
+        });
+}
+
 let filter = /.*/; // run everything by default
 if (this["arguments"]) {
     for (let i = 0; i < arguments.length; i++) {

Modified: trunk/Tools/WebGPUShadingLanguageRI/TypeRef.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/TypeRef.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/TypeRef.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -36,6 +36,8 @@
     
     static wrap(type)
     {
+        if (type instanceof TypeRef && !type.typeArguments)
+            return type;
         let result = new TypeRef(type.origin, type.name, []);
         result.type = type;
         return result;

Modified: trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js (221591 => 221592)


--- trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js	2017-09-04 19:34:24 UTC (rev 221591)
+++ trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js	2017-09-04 20:14:08 UTC (rev 221592)
@@ -72,7 +72,7 @@
         // The thing we get unified with must be a type variable that accepts a broader set of
         // things than we do.
         if (!(realThis instanceof TypeVariable))
-            return true;
+            return false;
         
         if (!this.protocol)
             return !realThis.protocol;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to