Title: [221740] trunk/Tools
Revision
221740
Author
[email protected]
Date
2017-09-07 10:53:50 -0700 (Thu, 07 Sep 2017)

Log Message

[WSL] Rationalize how protocol inheritance deals with type parameters
https://bugs.webkit.org/show_bug.cgi?id=176334

Reviewed by Mark Lam.
        
This adds a bunch of tests for structs, protocols, and functions interacting in interesting
ways. The most complex of these tests triggers the case where the protocol contains a function
with one type parameter and the real function has more than one. This should give a WTypeError,
and now it does.
        
* WebGPUShadingLanguageRI/ProtocolDecl.js:
(ProtocolDecl.prototype.hasHeir): Fix the handling of a mismatch of number of type parameters by actually passing the type parameters and then correctly handling the error.
* WebGPUShadingLanguageRI/Test.js: Add a bunch of tests for this case and a lot of other protocol cases.
(TEST_protocolMonoSigPolyDef):
(TEST_protocolPolySigPolyDef):
(TEST_protocolDoublePolySigDoublePolyDef):
(TEST_protocolDoublePolySigDoublePolyDefExplicit):
(TEST_protocolMonoPolySigDoublePolyDefExplicit):
* WebGPUShadingLanguageRI/TypeVariable.js:
(TypeVariable.prototype.get origin): This wasn't implemented before, which made error reporting harder.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (221739 => 221740)


--- trunk/Tools/ChangeLog	2017-09-07 17:20:42 UTC (rev 221739)
+++ trunk/Tools/ChangeLog	2017-09-07 17:53:50 UTC (rev 221740)
@@ -1,3 +1,26 @@
+2017-09-07  Filip Pizlo  <[email protected]>
+
+        [WSL] Rationalize how protocol inheritance deals with type parameters
+        https://bugs.webkit.org/show_bug.cgi?id=176334
+
+        Reviewed by Mark Lam.
+        
+        This adds a bunch of tests for structs, protocols, and functions interacting in interesting
+        ways. The most complex of these tests triggers the case where the protocol contains a function
+        with one type parameter and the real function has more than one. This should give a WTypeError,
+        and now it does.
+        
+        * WebGPUShadingLanguageRI/ProtocolDecl.js:
+        (ProtocolDecl.prototype.hasHeir): Fix the handling of a mismatch of number of type parameters by actually passing the type parameters and then correctly handling the error.
+        * WebGPUShadingLanguageRI/Test.js: Add a bunch of tests for this case and a lot of other protocol cases.
+        (TEST_protocolMonoSigPolyDef):
+        (TEST_protocolPolySigPolyDef):
+        (TEST_protocolDoublePolySigDoublePolyDef):
+        (TEST_protocolDoublePolySigDoublePolyDefExplicit):
+        (TEST_protocolMonoPolySigDoublePolyDefExplicit):
+        * WebGPUShadingLanguageRI/TypeVariable.js:
+        (TypeVariable.prototype.get origin): This wasn't implemented before, which made error reporting harder.
+
 2017-09-07  Per Arne Vollan  <[email protected]>
 
         [Win] Dashboard test is failing.

Modified: trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js (221739 => 221740)


--- trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js	2017-09-07 17:20:42 UTC (rev 221739)
+++ trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js	2017-09-07 17:53:50 UTC (rev 221740)
@@ -90,8 +90,8 @@
         let signatures = this.signatures;
         for (let signature of signatures) {
             signature = signature.visit(substitution);
-            let overload = this.program.resolveFuncOverload(signature.name, [], signature.parameterTypes);
-            if (!overload)
+            let overload = this.program.resolveFuncOverload(signature.name, signature.typeParameters, signature.parameterTypes);
+            if (!overload.func)
                 return false;
             
             let substitutedReturnType = overload.func.returnType.substituteToUnification(

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (221739 => 221740)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-07 17:20:42 UTC (rev 221739)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-07 17:53:50 UTC (rev 221740)
@@ -989,6 +989,146 @@
     checkBool(program, callFunction(program, "foo", [], [makeBool(program, false)]), false);
 }
 
+function TEST_protocolMonoSigPolyDef()
+{
+    let program = doPrep(`
+        struct IntAnd<T> {
+            int first;
+            T second;
+        }
+        IntAnd<T> intAnd<T>(int first, T second)
+        {
+            IntAnd<T> result;
+            result.first = first;
+            result.second = second;
+            return result;
+        }
+        protocol IntAndable {
+            IntAnd<int> intAnd(IntAndable, int);
+        }
+        int foo<T:IntAndable>(T first, int second)
+        {
+            IntAnd<int> result = intAnd(first, second);
+            return result.first + result.second;
+        }
+    `);
+    checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12)]), 54 + 12);
+}
+
+function TEST_protocolPolySigPolyDef()
+{
+    let program = doPrep(`
+        struct IntAnd<T> {
+            int first;
+            T second;
+        }
+        IntAnd<T> intAnd<T>(int first, T second)
+        {
+            IntAnd<T> result;
+            result.first = first;
+            result.second = second;
+            return result;
+        }
+        protocol IntAndable {
+            IntAnd<T> intAnd<T>(IntAndable, T);
+        }
+        int foo<T:IntAndable>(T first, int second)
+        {
+            IntAnd<int> result = intAnd(first, second);
+            return result.first + result.second;
+        }
+    `);
+    checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12)]), 54 + 12);
+}
+
+function TEST_protocolDoublePolySigDoublePolyDef()
+{
+    let program = doPrep(`
+        struct IntAnd<T, U> {
+            int first;
+            T second;
+            U third;
+        }
+        IntAnd<T, U> intAnd<T, U>(int first, T second, U third)
+        {
+            IntAnd<T, U> result;
+            result.first = first;
+            result.second = second;
+            result.third = third;
+            return result;
+        }
+        protocol IntAndable {
+            IntAnd<T, U> intAnd<T, U>(IntAndable, T, U);
+        }
+        int foo<T:IntAndable>(T first, int second, int third)
+        {
+            IntAnd<int, int> result = intAnd(first, second, third);
+            return result.first + result.second + result.third;
+        }
+    `);
+    checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]), 54 + 12 + 39);
+}
+
+function TEST_protocolDoublePolySigDoublePolyDefExplicit()
+{
+    let program = doPrep(`
+        struct IntAnd<T, U> {
+            int first;
+            T second;
+            U third;
+        }
+        IntAnd<T, U> intAnd<T, U>(int first, T second, U third)
+        {
+            IntAnd<T, U> result;
+            result.first = first;
+            result.second = second;
+            result.third = third;
+            return result;
+        }
+        protocol IntAndable {
+            IntAnd<T, U> intAnd<T, U>(IntAndable, T, U);
+        }
+        int foo<T:IntAndable>(T first, int second, int third)
+        {
+            IntAnd<int, int> result = intAnd<int, int>(first, second, third);
+            return result.first + result.second + result.third;
+        }
+    `);
+    checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]), 54 + 12 + 39);
+}
+
+function TEST_protocolMonoPolySigDoublePolyDefExplicit()
+{
+    checkFail(
+        () => {
+            let program = doPrep(`
+                struct IntAnd<T, U> {
+                    int first;
+                    T second;
+                    U third;
+                }
+                IntAnd<T, U> intAnd<T, U>(int first, T second, U third)
+                {
+                    IntAnd<T, U> result;
+                    result.first = first;
+                    result.second = second;
+                    result.third = third;
+                    return result;
+                }
+                protocol IntAndable {
+                    IntAnd<T, int> intAnd<T>(IntAndable, T, int);
+                }
+                int foo<T:IntAndable>(T first, int second, int third)
+                {
+                    IntAnd<int, int> result = intAnd<int>(first, second, third);
+                    return result.first + result.second + result.third;
+                }
+            `);
+            callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]);
+        },
+        (e) => e instanceof WTypeError);
+}
+
 let filter = /.*/; // run everything by default
 if (this["arguments"]) {
     for (let i = 0; i < arguments.length; i++) {

Modified: trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js (221739 => 221740)


--- trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js	2017-09-07 17:20:42 UTC (rev 221739)
+++ trunk/Tools/WebGPUShadingLanguageRI/TypeVariable.js	2017-09-07 17:53:50 UTC (rev 221740)
@@ -33,6 +33,7 @@
         this._protocol = protocol;
     }
     
+    get origin() { return this._origin; }
     get name() { return this._name; }
     get protocol() { return this._protocol; }
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to