Title: [222351] trunk/Tools
Revision
222351
Author
fpi...@apple.com
Date
2017-09-21 14:35:47 -0700 (Thu, 21 Sep 2017)

Log Message

WSL should have some post-instantiation type checking
https://bugs.webkit.org/show_bug.cgi?id=177303

Reviewed by Keith Miller.
        
This patch removes the Primitive protocol! Yay!
        
The Primitive protocol was an attempt to handle the fact that Metal wouldn't allow us to point a
non-thread pointer at data structures that have pointers. This type checking rule interacts badly with
generics. I was able to get it to mostly work by making Primitive into a dynamic protocol - a type
belongs to it if it happens to be isPrimitive.
        
But that was a mistake, since it makes it hard to create pointers that are generic over address space.
Also, it's not an appropriate rule for targeting SPIR-V logical mode. That rule will be different, and
possibly more complicated.
        
All of these kinds of rules are easier to implement of we run them after instantiation, since then they
don't get in the way of generics. That's what this patch does.
        
This means that we get all of the same type checking power as before, and we still can catch the errors
that Metal requires us to check for. It's easier to do those checks now.
        
Finally, this removes the shader type checker's incomplete reimplementation of isPrimitive (which was
called NonNumericSearcher). The shader type checker calls isPrimitive now.

* WebGPUShadingLanguageRI/AddressSpace.js:
(needsPrimitiveProtocol): Deleted.
(protocolSuffix): Deleted.
* WebGPUShadingLanguageRI/All.js:
* WebGPUShadingLanguageRI/Checker.js:
(Checker.prototype._checkShaderType):
(Checker.prototype._checkShaderType.NonNumericSearcher): Deleted.
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitArrayRefType): Deleted.
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitPtrType): Deleted.
(Checker.prototype.visitReferenceType): Deleted.
* WebGPUShadingLanguageRI/FuncInstantiator.js:
(FuncInstantiator.prototype.getUnique.Instantiate.prototype.visitFuncDef):
* WebGPUShadingLanguageRI/Inline.js:
(_inlineFunction):
* WebGPUShadingLanguageRI/Intrinsics.js:
(Intrinsics):
* WebGPUShadingLanguageRI/LateChecker.js: Added.
(LateChecker):
(LateChecker.prototype.visitReferenceType):
(LateChecker.prototype._checkShaderType):
(LateChecker.prototype.visitFuncDef):
* WebGPUShadingLanguageRI/LexerToken.js:
(LexerToken.prototype.get isInternal): Deleted.
* WebGPUShadingLanguageRI/NativeType.js:
(NativeType):
(NativeType.prototype.get name):
(NativeType.prototype.get isPrimitive):
(NativeType.prototype.set isPrimitive):
(NativeType.prototype.toString):
* WebGPUShadingLanguageRI/Parse.js:
(parseNative):
* WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js:
(programWithUnnecessaryThingsRemoved):
* WebGPUShadingLanguageRI/ProtocolDecl.js:
* WebGPUShadingLanguageRI/ReferenceType.js:
(ReferenceType.prototype.get elementType):
(ReferenceType.prototype.get isPrimitive): Deleted.
* WebGPUShadingLanguageRI/StandardLibrary.js:
* WebGPUShadingLanguageRI/StatementCloner.js:
(StatementCloner.prototype.visitNativeType):
* WebGPUShadingLanguageRI/SynthesizeStructAccessors.js:
(synthesizeStructAccessors):
* WebGPUShadingLanguageRI/Test.js:
(TEST_passNullAndNotNullFullPoly):
(TEST_passNullAndNotNullFullPolyReverse):
(TEST_nullTypeVariableUnify):
(TEST_chainStructNewlyValid):
(TEST_chainStructDevice):
(TEST_chainStructInvalid): Deleted.
* WebGPUShadingLanguageRI/Type.js:
(Type.prototype.get isPrimitive):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (222350 => 222351)


--- trunk/Tools/ChangeLog	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/ChangeLog	2017-09-21 21:35:47 UTC (rev 222351)
@@ -1,3 +1,82 @@
+2017-09-21  Filip Pizlo  <fpi...@apple.com>
+
+        WSL should have some post-instantiation type checking
+        https://bugs.webkit.org/show_bug.cgi?id=177303
+
+        Reviewed by Keith Miller.
+        
+        This patch removes the Primitive protocol! Yay!
+        
+        The Primitive protocol was an attempt to handle the fact that Metal wouldn't allow us to point a
+        non-thread pointer at data structures that have pointers. This type checking rule interacts badly with
+        generics. I was able to get it to mostly work by making Primitive into a dynamic protocol - a type
+        belongs to it if it happens to be isPrimitive.
+        
+        But that was a mistake, since it makes it hard to create pointers that are generic over address space.
+        Also, it's not an appropriate rule for targeting SPIR-V logical mode. That rule will be different, and
+        possibly more complicated.
+        
+        All of these kinds of rules are easier to implement of we run them after instantiation, since then they
+        don't get in the way of generics. That's what this patch does.
+        
+        This means that we get all of the same type checking power as before, and we still can catch the errors
+        that Metal requires us to check for. It's easier to do those checks now.
+        
+        Finally, this removes the shader type checker's incomplete reimplementation of isPrimitive (which was
+        called NonNumericSearcher). The shader type checker calls isPrimitive now.
+
+        * WebGPUShadingLanguageRI/AddressSpace.js:
+        (needsPrimitiveProtocol): Deleted.
+        (protocolSuffix): Deleted.
+        * WebGPUShadingLanguageRI/All.js:
+        * WebGPUShadingLanguageRI/Checker.js:
+        (Checker.prototype._checkShaderType):
+        (Checker.prototype._checkShaderType.NonNumericSearcher): Deleted.
+        (Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitArrayRefType): Deleted.
+        (Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitPtrType): Deleted.
+        (Checker.prototype.visitReferenceType): Deleted.
+        * WebGPUShadingLanguageRI/FuncInstantiator.js:
+        (FuncInstantiator.prototype.getUnique.Instantiate.prototype.visitFuncDef):
+        * WebGPUShadingLanguageRI/Inline.js:
+        (_inlineFunction):
+        * WebGPUShadingLanguageRI/Intrinsics.js:
+        (Intrinsics):
+        * WebGPUShadingLanguageRI/LateChecker.js: Added.
+        (LateChecker):
+        (LateChecker.prototype.visitReferenceType):
+        (LateChecker.prototype._checkShaderType):
+        (LateChecker.prototype.visitFuncDef):
+        * WebGPUShadingLanguageRI/LexerToken.js:
+        (LexerToken.prototype.get isInternal): Deleted.
+        * WebGPUShadingLanguageRI/NativeType.js:
+        (NativeType):
+        (NativeType.prototype.get name):
+        (NativeType.prototype.get isPrimitive):
+        (NativeType.prototype.set isPrimitive):
+        (NativeType.prototype.toString):
+        * WebGPUShadingLanguageRI/Parse.js:
+        (parseNative):
+        * WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js:
+        (programWithUnnecessaryThingsRemoved):
+        * WebGPUShadingLanguageRI/ProtocolDecl.js:
+        * WebGPUShadingLanguageRI/ReferenceType.js:
+        (ReferenceType.prototype.get elementType):
+        (ReferenceType.prototype.get isPrimitive): Deleted.
+        * WebGPUShadingLanguageRI/StandardLibrary.js:
+        * WebGPUShadingLanguageRI/StatementCloner.js:
+        (StatementCloner.prototype.visitNativeType):
+        * WebGPUShadingLanguageRI/SynthesizeStructAccessors.js:
+        (synthesizeStructAccessors):
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_passNullAndNotNullFullPoly):
+        (TEST_passNullAndNotNullFullPolyReverse):
+        (TEST_nullTypeVariableUnify):
+        (TEST_chainStructNewlyValid):
+        (TEST_chainStructDevice):
+        (TEST_chainStructInvalid): Deleted.
+        * WebGPUShadingLanguageRI/Type.js:
+        (Type.prototype.get isPrimitive):
+
 2017-09-21  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed, temporarily disable new API tests introduced in r222308 until they pass on El Capitan

Modified: trunk/Tools/WebGPUShadingLanguageRI/AddressSpace.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/AddressSpace.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/AddressSpace.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -39,16 +39,6 @@
     }
 }
 
-function needsPrimitiveProtocol(addressSpace)
-{
-    return addressSpace != "thread";
-}
-
-function protocolSuffix(addressSpace)
-{
-    return needsPrimitiveProtocol(addressSpace) ? ":Primitive" : "";
-}
-
 function validateAddressSpace(addressSpace)
 {
     if (!isAddressSpace(addressSpace))

Modified: trunk/Tools/WebGPUShadingLanguageRI/All.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -100,6 +100,7 @@
 load("IntLiteral.js");
 load("IntLiteralType.js");
 load("Intrinsics.js");
+load("LateChecker.js");
 load("Lexer.js");
 load("LexerToken.js");
 load("LiteralTypeChecker.js");

Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -62,62 +62,20 @@
         if (node.typeParameters.length != 0)
             throw new WTypeError(node.origin.originString, "Entry point " + node.name + " must not have type arguments.");
         let shaderFunc = node;
-        class NonNumericSearcher extends Visitor {
-            constructor(name)
-            {
-                super();
-                this._name = name;
-            }
-            visitArrayRefType(node)
-            {
-                throw new WTypeError(node.origin.originString, shaderFunc.name + " must transitively only have numeric types.");
-            }
-            visitPtrType(node)
-            {
-                throw new WTypeError(node.origin.originString, shaderFunc.name + " must transitively only have numeric types.");
-            }
-            visitTypeRef(node)
-            {
-                super.visitTypeRef(node);
-                node.type.visit(this);
-            }
-        }
         switch (node.shaderType) {
         case "vertex":
             if (this._vertexEntryPoints.has(node.name))
                 throw new WTypeError(node.origin.originString, "Duplicate vertex entry point name " + node.name);
             this._vertexEntryPoints.add(node.name);
-            if (!(node.returnType.type instanceof StructType))
-                throw new WTypeError(node.origin.originString, "Vertex shader " + node.name + " must return a struct.");
-            for (let parameter of node.parameters) {
-                if (parameter.type.type instanceof StructType)
-                    parameter.type.visit(new NonNumericSearcher(node.name));
-                else if (!(parameter.type.type instanceof ArrayRefType))
-                    throw new WTypeError(node.origin.originString, node.name + " accepts a parameter " + parameter.name + " which isn't a struct and isn't an ArrayRef.");
-            }
-            node.returnType.type.visit(new NonNumericSearcher);
             break;
         case "fragment":
             if (this._fragmentEntryPoints.has(node.name))
                 throw new WTypeError(node.origin.originString, "Duplicate fragment entry point name " + node.name);
             this._fragmentEntryPoints.add(node.name);
-            if (!(node.returnType.type instanceof StructType))
-                throw new WTypeError(node.origin.originString, "Fragment shader " + node.name + " must return a struct.");
-            for (let parameter of node.parameters) {
-                if (parameter.name == "stageIn") {
-                    if (!(parameter.type.type instanceof StructType))
-                        throw new WTypeError(node.origin.originString, "Fragment entry points' stageIn parameter (of " + node.name + ") must be a struct type.");
-                    parameter.type.visit(new NonNumericSearcher(node.name));
-                } else {
-                    if (!(parameter.type.type instanceof ArrayRefType))
-                        throw new WTypeError(node.origin.originString, "Fragment entry point's " + parameter.name + " parameter is not an array reference.");
-                }
-            }
-            node.returnType.type.visit(new NonNumericSearcher);
             break;
         }
     }
-    
+
     visitFuncDef(node)
     {
         if (node.shaderType)
@@ -220,18 +178,6 @@
         this._checkTypeArguments(node.origin, node.type.typeParameters, node.typeArguments);
     }
     
-    visitReferenceType(node)
-    {
-        node.elementType.visit(this);
-        
-        if (node.addressSpace == "thread")
-            return;
-        
-        let instantiatedType = node.elementType.instantiatedType;
-        if (!instantiatedType.isPrimitive)
-            throw new WTypeError(node.origin.originString, "Illegal pointer to non-primitive type: " + node.elementType + " (instantiated to " + node.elementType.instantiatedType + ")");
-    }
-    
     visitArrayType(node)
     {
         node.elementType.visit(this);

Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -102,7 +102,8 @@
                     func.returnType.visit(substitution).visit(instantiateImmediates),
                     [], // We're instantiated so we no longer take type parameters.
                     func.parameters.map(parameter => parameter.visit(substitution).visit(instantiateImmediates)),
-                    func.body.visit(substitution).visit(instantiateImmediates));
+                    func.body.visit(substitution).visit(instantiateImmediates),
+                    func.isCast, func.shaderType);
             }
             
             visitNativeFunc(func)

Modified: trunk/Tools/WebGPUShadingLanguageRI/Inline.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Inline.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Inline.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -43,6 +43,8 @@
     if (func.inlined || func.isNative)
         return;
     
+    func.visit(new LateChecker());
+    
     // This is the precise time when we can build EBuffers in order to get them to be uniqued by
     // type instantiation but nothing else.
     func.visit(new StructLayoutBuilder());

Modified: trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -27,10 +27,6 @@
 class Intrinsics {
     constructor(nameContext)
     {
-        this.primitive = new ProtocolDecl({origin: "<internal>", originString: "native", isInternal: true}, "Primitive");
-        this.primitive.isPrimitive = true;
-        nameContext.add(this.primitive);
-        
         this._map = new Map();
 
         // NOTE: Intrinsic resolution happens before type name resolution, so the strings we use here
@@ -39,7 +35,7 @@
         // use "int" here, since we don't yet know that they are the same type.
         
         this._map.set(
-            "native Primitive type void<>",
+            "native typedef void<>",
             type => {
                 this.void = type;
                 type.size = 0;
@@ -61,9 +57,10 @@
         }
 
         this._map.set(
-            "native Primitive type int32<>",
+            "native typedef int32<>",
             type => {
                 this.int32 = type;
+                type.isPrimitive = true;
                 type.isInt = true;
                 type.isNumber = true;
                 type.isSigned = true;
@@ -85,9 +82,10 @@
             });
 
         this._map.set(
-            "native Primitive type uint32<>",
+            "native typedef uint32<>",
             type => {
                 this.uint32 = type;
+                type.isPrimitive = true;
                 type.isInt = true;
                 type.isNumber = true;
                 type.isSigned = false;
@@ -107,7 +105,7 @@
             });
 
         this._map.set(
-            "native Primitive type uint8<>",
+            "native typedef uint8<>",
             type => {
                 this.uint8 = type;
                 type.isInt = true;
@@ -129,9 +127,10 @@
             });
 
         this._map.set(
-            "native Primitive type float<>",
+            "native typedef float<>",
             type => {
                 this.float = type;
+                type.isPrimitive = true;
                 type.size = 1;
                 type.isFloating = true;
                 type.isNumber = true;
@@ -144,9 +143,10 @@
             });
 
         this._map.set(
-            "native Primitive type double<>",
+            "native typedef double<>",
             type => {
                 this.double = type;
+                type.isPrimitive = true;
                 type.size = 1;
                 type.isFloating = true;
                 type.isNumber = true;
@@ -159,9 +159,10 @@
             });
 
         this._map.set(
-            "native Primitive type bool<>",
+            "native typedef bool<>",
             type => {
                 this.bool = type;
+                type.isPrimitive = true;
                 type.size = 1;
                 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, false);
             });
@@ -557,7 +558,7 @@
         
         for (let addressSpace of addressSpaces) {
             this._map.set(
-                `native T^ ${addressSpace} operator&[]<T${protocolSuffix(addressSpace)}>(T[] ${addressSpace},uint)`,
+                `native T^ ${addressSpace} operator&[]<T>(T[] ${addressSpace},uint)`,
                 func => {
                     func.implementation = ([ref, index], node) => {
                         ref = ref.loadValue();
@@ -571,7 +572,7 @@
                 });
 
             this._map.set(
-                `native uint operator.length<T${protocolSuffix(addressSpace)}>(T[] ${addressSpace})`,
+                `native uint operator.length<T>(T[] ${addressSpace})`,
                 func => {
                     func.implementation = ([ref], node) => {
                         ref = ref.loadValue();

Added: trunk/Tools/WebGPUShadingLanguageRI/LateChecker.js (0 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/LateChecker.js	                        (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/LateChecker.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -0,0 +1,79 @@
+/*
+ * 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 LateChecker extends Visitor {
+    visitReferenceType(node)
+    {
+        if (node.addressSpace == "thread")
+            return;
+        
+        if (!node.elementType.isPrimitive)
+            throw new WTypeError(node.origin.originString, "Illegal pointer to non-primitive type: " + node.elementType);
+    }
+    
+    _checkShaderType(node)
+    {
+        let assertPrimitive = type => {
+            if (!type.isPrimitive)
+                throw new WTypeError(node.origin.originString, "Shader signature cannot include non-primitive type: " + type);
+        }
+        assertPrimitive(node.returnType);
+        if (!(node.returnType.type instanceof StructType))
+            throw new WTypeError(node.origin.originString, "Vertex shader " + node.name + " must return a struct.");
+        switch (node.shaderType) {
+        case "vertex":
+            for (let parameter of node.parameters) {
+                if (parameter.type.type instanceof StructType)
+                    assertPrimitive(parameter.type);
+                else if (!(parameter.type.type instanceof ArrayRefType))
+                    throw new WTypeError(node.origin.originString, node.name + " accepts a parameter " + parameter.name + " which isn't a struct and isn't an ArrayRef.");
+            }
+            break;
+        case "fragment":
+            for (let parameter of node.parameters) {
+                if (parameter.name == "stageIn") {
+                    if (!(parameter.type.type instanceof StructType))
+                        throw new WTypeError(node.origin.originString, "Fragment entry points' stageIn parameter (of " + node.name + ") must be a struct type.");
+                    assertPrimitive(parameter.type);
+                } else {
+                    if (!(parameter.type.type instanceof ArrayRefType))
+                        throw new WTypeError(node.origin.originString, "Fragment entry point's " + parameter.name + " parameter is not an array reference.");
+                }
+            }
+            break;
+        default:
+            throw new Error("Bad shader type: " + node.shaderType);
+        }
+    }
+    
+    visitFuncDef(node)
+    {
+        if (node.shaderType)
+            this._checkShaderType(node);
+        super.visitFuncDef(node);
+    }
+}
+

Modified: trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -58,11 +58,6 @@
         return this.lexer.originKind;
     }
     
-    get isInternal()
-    {
-        return false;
-    }
-    
     get index()
     {
         return this._index;

Modified: trunk/Tools/WebGPUShadingLanguageRI/NativeType.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/NativeType.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/NativeType.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -25,21 +25,22 @@
 "use strict";
 
 class NativeType extends Type {
-    constructor(origin, name, isPrimitive, typeParameters)
+    constructor(origin, name, typeParameters)
     {
+        if (!(typeParameters instanceof Array))
+            throw new Error("type parameters not array: " + typeParameters);
         super();
         this._origin = origin;
         this._name = name;
-        this._isPrimitive = isPrimitive;
         this._typeParameters = typeParameters;
         this._isNumber = false;
         this._isInt = false;
         this._isFloating = false;
+        this._isPrimitive = false;
     }
     
     get origin() { return this._origin; }
     get name() { return this._name; }
-    get isPrimitive() { return this._isPrimitive; }
     get typeParameters() { return this._typeParameters; }
     get isNative() { return true; }
     
@@ -50,6 +51,8 @@
     set isInt(value) { this._isInt = value; }
     get isFloating() { return this._isFloating; }
     set isFloating(value) { this._isFloating = value; }
+    get isPrimitive() { return this._isPrimitive; }
+    set isPrimitive(value) { this._isPrimitive = value; }
     
     instantiate(typeArguments)
     {
@@ -62,7 +65,7 @@
     
     toString()
     {
-        return "native " + (this.isPrimitive ? "Primitive " : "") + "type " + this.name + "<" + this.typeParameters + ">";
+        return "native typedef " + this.name + "<" + this.typeParameters + ">";
     }
 }
 

Modified: trunk/Tools/WebGPUShadingLanguageRI/Parse.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -955,18 +955,11 @@
     function parseNative()
     {
         let origin = consume("native");
-        let isType = lexer.backtrackingScope(() => {
-            if (tryConsume("typedef"))
-                return "normal";
-            consume("Primitive");
-            consume("typedef");
-            return "primitive";
-        });
-        if (isType) {
+        if (tryConsume("typedef")) {
             let name = consumeKind("identifier");
             let parameters = parseTypeParameters();
             consume(";");
-            return new NativeType(origin, name.text, isType == "primitive", parameters);
+            return new NativeType(origin, name.text, parameters);
         }
         return parseNativeFunc();
     }

Modified: trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -51,10 +51,8 @@
     
     let result = new Program();
     for (let name of nameFinder.set) {
-        for (let thing of program.globalNameContext.underlyingThings(Anything, name)) {
-            if (!thing.origin.isInternal)
-                result.add(thing);
-        }
+        for (let thing of program.globalNameContext.underlyingThings(Anything, name))
+            result.add(thing);
     }
     
     return result;

Modified: trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/ProtocolDecl.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -32,7 +32,6 @@
         this._signatures = [];
         this._signatureMap = new Map();
         this._typeVariable = new TypeVariable(origin, name, null);
-        this.isPrimitive = false;
     }
     
     addExtends(protocol)

Modified: trunk/Tools/WebGPUShadingLanguageRI/ReferenceType.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/ReferenceType.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/ReferenceType.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -39,7 +39,6 @@
     get origin() { return this._origin; }
     get addressSpace() { return this._addressSpace; }
     get elementType() { return this._elementType; }
-    get isPrimitive() { return false; }
 
     get size() { return 1; }
 

Modified: trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -43,21 +43,20 @@
 // NOTE: The next line is line 72, and we rely on this in Prepare.js.
 let standardLibrary = `
 // This is the WSL standard library. Implementations of all of these things are in
-// Intrinsics.js. The only thing that gets defined before we get here is the Primitive
-// protocol.
+// Intrinsics.js.
 
 // Need to bootstrap void first.
-native Primitive typedef void;
+native typedef void;
 
-native Primitive typedef uint8;
-native Primitive typedef int32;
-native Primitive typedef uint32;
-native Primitive typedef bool;
+native typedef uint8;
+native typedef int32;
+native typedef uint32;
+native typedef bool;
 typedef int = int32;
 typedef uint = uint32;
 
-native Primitive typedef float;
-native Primitive typedef double;
+native typedef float;
+native typedef double;
 
 native operator int32(uint32);
 native operator int32(uint8);
@@ -378,14 +377,14 @@
 }
 
 native thread T^ operator&[]<T>(thread T[], uint);
-native threadgroup T^ operator&[]<T:Primitive>(threadgroup T[], uint);
-native device T^ operator&[]<T:Primitive>(device T[], uint);
-native constant T^ operator&[]<T:Primitive>(constant T[], uint);
+native threadgroup T^ operator&[]<T>(threadgroup T[], uint);
+native device T^ operator&[]<T>(device T[], uint);
+native constant T^ operator&[]<T>(constant T[], uint);
 
 native uint operator.length<T>(thread T[]);
-native uint operator.length<T:Primitive>(threadgroup T[]);
-native uint operator.length<T:Primitive>(device T[]);
-native uint operator.length<T:Primitive>(constant T[]);
+native uint operator.length<T>(threadgroup T[]);
+native uint operator.length<T>(device T[]);
+native uint operator.length<T>(constant T[]);
 
 uint operator.length<T, uint length>(T[length])
 {

Modified: trunk/Tools/WebGPUShadingLanguageRI/StatementCloner.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/StatementCloner.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/StatementCloner.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -53,8 +53,7 @@
     visitNativeType(node)
     {
         return new NativeType(
-            node.origin, node.name, node.isPrimitive,
-            node.typeParameters.map(typeParameter => typeParameter.visit(this)));
+            node.origin, node.name, node.typeParameters.map(typeParameter => typeParameter.visit(this)));
     }
     
     visitTypeDef(node)

Modified: trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -154,11 +154,9 @@
             }
             
             setupAnder("thread");
-            if (type.instantiate().isPrimitive) {
-                setupAnder("threadgroup");
-                setupAnder("device");
-                setupAnder("constant");
-            }
+            setupAnder("threadgroup");
+            setupAnder("device");
+            setupAnder("constant");
         }
     }
 }

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -968,7 +968,7 @@
 function TEST_passNullAndNotNull()
 {
     let program = doPrep(`
-        T bar<T:Primitive>(device T^ p, device T^)
+        T bar<T>(device T^ p, device T^)
         {
             return ^p;
         }
@@ -985,7 +985,7 @@
 function TEST_passNullAndNotNullFullPoly()
 {
     let program = doPrep(`
-        T bar<T:Primitive>(T p, T)
+        T bar<T>(T p, T)
         {
             return p;
         }
@@ -1002,7 +1002,7 @@
 function TEST_passNullAndNotNullFullPolyReverse()
 {
     let program = doPrep(`
-        T bar<T:Primitive>(T, T p)
+        T bar<T>(T, T p)
         {
             return p;
         }
@@ -1060,7 +1060,7 @@
             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, []));
+            types.ptrType = new PtrType(null, "constant", new NativeType(null, "foo_t", []));
             let unificationContext = new UnificationContext([types.variableType]);
             for (let [leftName, rightName] of order) {
                 let left = types[leftName];
@@ -2032,28 +2032,29 @@
     checkInt(program, callFunction(program, "bar", [], [makeInt(program, 4657)]), 4657);
 }
 
-function TEST_chainStructInvalid()
+function TEST_chainStructNewlyValid()
 {
-    checkFail(
-        () => doPrep(`
-            struct Foo<T> {
-                T f;
-            }
-            struct Bar<T> {
-                Foo<device T^> f;
-            }
-            int foo(thread Bar<int>^ x)
-            {
-                return ^x->f.f;
-            }
-            int bar(device int^ a)
-            {
-                Bar<int> x;
-                x.f.f = a;
-                return foo(&x);
-            }
-        `),
-        (e) => e instanceof WTypeError);
+    let program = doPrep(`
+        struct Foo<T> {
+            T f;
+        }
+        struct Bar<T> {
+            Foo<device T^> f;
+        }
+        int foo(thread Bar<int>^ x)
+        {
+            return ^x->f.f;
+        }
+        int bar(device int^ a)
+        {
+            Bar<int> x;
+            x.f.f = a;
+            return foo(&x);
+        }
+    `);
+    let buffer = new EBuffer(1);
+    buffer.set(0, 78453);
+    checkInt(program, callFunction(program, "bar", [], [TypedValue.box(new PtrType(null, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 78453);
 }
 
 function TEST_chainStructDevice()
@@ -2062,7 +2063,7 @@
         struct Foo<T> {
             T f;
         }
-        struct Bar<T:Primitive> {
+        struct Bar<T> {
             Foo<device T^> f;
         }
         int foo(thread Bar<int>^ x)

Modified: trunk/Tools/WebGPUShadingLanguageRI/Type.js (222350 => 222351)


--- trunk/Tools/WebGPUShadingLanguageRI/Type.js	2017-09-21 21:11:03 UTC (rev 222350)
+++ trunk/Tools/WebGPUShadingLanguageRI/Type.js	2017-09-21 21:35:47 UTC (rev 222351)
@@ -33,6 +33,7 @@
     get isNumber() { return false; }
     get isInt() { return false; }
     get isFloating() { return false; }
+    get isPrimitive() { return false; }
     
     inherits(protocol)
     {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to