Diff
Modified: trunk/Tools/ChangeLog (222294 => 222295)
--- trunk/Tools/ChangeLog 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/ChangeLog 2017-09-20 22:41:01 UTC (rev 222295)
@@ -1,3 +1,56 @@
+2017-09-20 Filip Pizlo <[email protected]>
+
+ WSL should not type-check functions in the standard library that it does not use
+ https://bugs.webkit.org/show_bug.cgi?id=177269
+
+ Reviewed by JS Bastien.
+
+ Once we added all of the swizzling operators, the size of the standard library ballooned to the point
+ where it's just not practical to compile anything anymore. If you want to compile
+ "int foo(int x) { return x}" then it will take some ridiculous amount of time (many seconds) because WSL
+ will have to type check all of those swizzling operators.
+
+ This change makes it so that after parsing the whole program, we remove the things that we aren't using.
+ We can make a really good estimate of what we need even before doing any name resolution. In practice,
+ this change removes almost all of the things from Program before we get to the hard work of type
+ checking. That's true because the standard library contains _many_ things and you'd have to try very
+ hard to use all of them.
+
+ This is a 13x speed-up for Test.js. It went from 155 seconds to 12 seconds on my machine.
+
+ * WebGPUShadingLanguageRI/All.js:
+ * WebGPUShadingLanguageRI/ConstexprTypeParameter.js:
+ (ConstexprTypeParameter.prototype.get origin):
+ * WebGPUShadingLanguageRI/Intrinsics.js:
+ * WebGPUShadingLanguageRI/Lexer.js:
+ (Lexer):
+ (Lexer.prototype.get originKind):
+ * WebGPUShadingLanguageRI/LexerToken.js:
+ (LexerToken.prototype.get lexer):
+ (LexerToken.prototype.get origin):
+ (LexerToken.prototype.get originKind):
+ (LexerToken.prototype.get isInternal):
+ * WebGPUShadingLanguageRI/NameContext.js:
+ (isWildcardKind):
+ (NameContext.prototype.add):
+ (NameContext.prototype.get let):
+ (NameContext.prototype.mapFor): Deleted.
+ * WebGPUShadingLanguageRI/NameFinder.js: Added.
+ (NameFinder):
+ (NameFinder.get worklist):
+ * WebGPUShadingLanguageRI/NameResolver.js:
+ (NameResolver.prototype.visitProtocolDecl):
+ * WebGPUShadingLanguageRI/OriginKind.js: Added.
+ (isOriginKind):
+ * WebGPUShadingLanguageRI/Prepare.js:
+ (let.prepare):
+ * WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js: Added.
+ (programWithUnnecessaryThingsRemoved):
+ * WebGPUShadingLanguageRI/Test.html:
+ * WebGPUShadingLanguageRI/Test.js:
+ (doTest):
+ * WebGPUShadingLanguageRI/index.html:
+
2017-09-20 Alex Christensen <[email protected]>
Remove ActionType::CSSDisplayNoneStyleSheet
Modified: trunk/Tools/WebGPUShadingLanguageRI/All.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/All.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/All.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -108,6 +108,7 @@
load("MakeArrayRefExpression.js");
load("MakePtrExpression.js");
load("NameContext.js");
+load("NameFinder.js");
load("NameResolver.js");
load("NativeFunc.js");
load("NativeFuncInstance.js");
@@ -116,10 +117,12 @@
load("NormalUsePropertyResolver.js");
load("NullLiteral.js");
load("NullType.js");
+load("OriginKind.js");
load("OverloadResolutionFailure.js");
load("Parse.js");
load("Prepare.js");
load("Program.js");
+load("ProgramWithUnnecessaryThingsRemoved.js");
load("PropertyResolver.js");
load("Protocol.js");
load("ProtocolDecl.js");
Modified: trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/ConstexprTypeParameter.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -33,6 +33,7 @@
this._type = type;
}
+ get origin() { return this._origin; }
get name() { return this._name; }
get type() { return this._type; }
get isConstexpr() { return true; }
Modified: trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -27,7 +27,7 @@
class Intrinsics {
constructor(nameContext)
{
- this.primitive = new ProtocolDecl(null, "Primitive");
+ this.primitive = new ProtocolDecl({origin: "<internal>", originString: "native", isInternal: true}, "Primitive");
this.primitive.isPrimitive = true;
nameContext.add(this.primitive);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Lexer.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/Lexer.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/Lexer.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -27,6 +27,8 @@
class Lexer {
constructor(origin, originKind, lineNumberOffset, text)
{
+ if (!isOriginKind(originKind))
+ throw new Error("Bad origin kind: " + originKind);
this._origin = origin;
this._originKind = originKind;
this._lineNumberOffset = lineNumberOffset;
@@ -47,6 +49,8 @@
return this._origin + ":" + (this.lineNumber + 1);
}
+ get originKind() { return this._originKind; }
+
lineNumberForIndex(index)
{
let matches = this._text.substring(0, index).match(/\n/g);
Modified: trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/LexerToken.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -33,6 +33,11 @@
this._text = text;
}
+ get lexer()
+ {
+ return this._lexer;
+ }
+
get kind()
{
return this._kind;
@@ -45,9 +50,19 @@
get origin()
{
- return this._lexer.origin;
+ return this.lexer.origin;
}
+ get originKind()
+ {
+ return this.lexer.originKind;
+ }
+
+ get isInternal()
+ {
+ return false;
+ }
+
get index()
{
return this._index;
Modified: trunk/Tools/WebGPUShadingLanguageRI/NameContext.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/NameContext.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/NameContext.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -24,11 +24,11 @@
*/
"use strict";
-const NotFunc = Symbol();
+const Anything = Symbol();
function isWildcardKind(kind)
{
- return kind == NotFunc;
+ return kind == Anything;
}
class NameContext {
@@ -42,24 +42,12 @@
this._program = null;
}
- mapFor(kind)
- {
- switch (kind) {
- case NotFunc:
- case Value:
- case Type:
- case Protocol:
- case Func:
- return this._map;
- default:
- throw new Error("Bad kind: " + kind);
- }
- }
-
add(thing)
{
if (!thing.name)
return;
+ if (!thing.origin)
+ throw new Error("Thing does not have origin: " + thing);
if (thing.isNative && !thing.implementation) {
if (!this._intrinsics)
@@ -88,7 +76,7 @@
get(kind, name)
{
- let result = this.mapFor(kind).get(name);
+ let result = this._map.get(name);
if (!result && this._delegate)
return this._delegate.get(kind, name);
if (result && !isWildcardKind(kind) && result.kind != kind)
@@ -96,6 +84,26 @@
return result;
}
+ underlyingThings(kind, name)
+ {
+ let things = this.get(kind, name);
+ return NameContext.underlyingThings(things);
+ }
+
+ static *underlyingThings(thing)
+ {
+ if (!thing)
+ return;
+ if (thing.kind === Func) {
+ if (!(thing instanceof Array))
+ throw new Error("Func thing is not array: " + thing);
+ for (let func of thing)
+ yield func;
+ return;
+ }
+ yield thing;
+ }
+
resolveFuncOverload(name, typeArguments, argumentTypes, returnType, allowEntryPoint = false)
{
let functions = this.get(Func, name);
Added: trunk/Tools/WebGPUShadingLanguageRI/NameFinder.js (0 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/NameFinder.js (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/NameFinder.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -0,0 +1,94 @@
+/*
+ * 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 NameFinder extends Visitor {
+ constructor()
+ {
+ super();
+ this._set = new Set();
+ this._worklist = [];
+ }
+
+ get set() { return this._set; }
+ get worklist() { return this._worklist; }
+
+ add(name)
+ {
+ if (this._set.has(name))
+ return;
+ this._set.add(name);
+ this._worklist.push(name);
+ }
+
+ visitProtocolRef(node)
+ {
+ this.add(node.name);
+ super.visitProtocolRef(node);
+ }
+
+ visitTypeRef(node)
+ {
+ this.add(node.name);
+ super.visitTypeRef(node);
+ }
+
+ visitVariableRef(node)
+ {
+ this.add(node.name);
+ super.visitVariableRef(node);
+ }
+
+ visitTypeOrVariableRef(node)
+ {
+ this.add(node.name);
+ }
+
+ _handlePropertyAccess(node)
+ {
+ this.add(node.getFuncName);
+ this.add(node.setFuncName);
+ this.add(node.andFuncName);
+ }
+
+ visitDotExpression(node)
+ {
+ this._handlePropertyAccess(node);
+ super.visitDotExpression(node);
+ }
+
+ visitIndexExpression(node)
+ {
+ this._handlePropertyAccess(node);
+ super.visitIndexExpression(node);
+ }
+
+ visitCallExpression(node)
+ {
+ this.add(node.name);
+ super.visitCallExpression(node);
+ }
+}
+
Modified: trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -171,13 +171,15 @@
for (let i = 0; i < typeArguments.length; ++i) {
let typeArgument = typeArguments[i];
if (typeArgument instanceof TypeOrVariableRef) {
- let thing = this._nameContext.get(NotFunc, typeArgument.name);
+ let thing = this._nameContext.get(Anything, typeArgument.name);
if (!thing)
new WTypeError(typeArgument.origin.originString, "Could not find type or variable named " + typeArgument.name);
- if (thing instanceof Value) {
+ if (thing instanceof Value)
typeArguments[i] = new VariableRef(typeArgument.origin, typeArgument.name);
- } else
+ else if (thing instanceof Type)
typeArguments[i] = new TypeRef(typeArgument.origin, typeArgument.name, []);
+ else
+ throw new WTypeError(typeArgument.origin.originString, "Type argument resolved to wrong kind of thing: " + thing.kind);
}
if (typeArgument[i] instanceof Value
Added: trunk/Tools/WebGPUShadingLanguageRI/OriginKind.js (0 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/OriginKind.js (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/OriginKind.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -0,0 +1,39 @@
+/*
+ * 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";
+
+const originKinds = ["native", "user"];
+
+function isOriginKind(originKind)
+{
+ switch (originKind) {
+ case "native":
+ case "user":
+ return true;
+ default:
+ return false;
+ }
+}
+
Modified: trunk/Tools/WebGPUShadingLanguageRI/Prepare.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/Prepare.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/Prepare.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -26,14 +26,18 @@
let prepare = (() => {
let standardProgram;
- return (origin, lineNumberOffset, text) => {
+ return function(origin, lineNumberOffset, text) {
if (!standardProgram) {
standardProgram = new Program();
parse(standardProgram, "/internal/stdlib", "native", 72, standardLibrary);
}
+ if (!arguments.length)
+ return;
+
let program = cloneProgram(standardProgram);
parse(program, origin, "user", lineNumberOffset, text);
+ program = programWithUnnecessaryThingsRemoved(program);
foldConstexprs(program);
let nameResolver = createNameResolver(program);
Added: trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js (0 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/ProgramWithUnnecessaryThingsRemoved.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -0,0 +1,62 @@
+/*
+ * 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";
+
+function programWithUnnecessaryThingsRemoved(program)
+{
+ let nameFinder = new NameFinder();
+
+ // Build our roots.
+ for (let statement of program.topLevelStatements) {
+ if (statement.origin.originKind === "user")
+ nameFinder.add(statement.name);
+ }
+
+ // Unfortunately, we cannot know yet which operator casts we'll need.
+ nameFinder.add("operator cast");
+
+ // We need these even if the program doesn't mention them by name.
+ nameFinder.add("void");
+ nameFinder.add("bool");
+ nameFinder.add("int");
+
+ // Pull in things as necessary.
+ while (nameFinder.worklist.length) {
+ let name = nameFinder.worklist.pop();
+ for (let thing of program.globalNameContext.underlyingThings(Anything, name))
+ thing.visit(nameFinder);
+ }
+
+ 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);
+ }
+ }
+
+ return result;
+}
+
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.html (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.html 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.html 2017-09-20 22:41:01 UTC (rev 222295)
@@ -85,6 +85,7 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""
@@ -93,11 +94,13 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-09-20 22:41:01 UTC (rev 222295)
@@ -4403,6 +4403,11 @@
function* doTest(object)
{
let before = preciseTime();
+
+ print("Compiling standard library...");
+ yield;
+ prepare();
+ print(" OK!");
for (let s in object) {
if (s.startsWith("TEST_") && s.match(filter)) {
Modified: trunk/Tools/WebGPUShadingLanguageRI/index.html (222294 => 222295)
--- trunk/Tools/WebGPUShadingLanguageRI/index.html 2017-09-20 22:27:23 UTC (rev 222294)
+++ trunk/Tools/WebGPUShadingLanguageRI/index.html 2017-09-20 22:41:01 UTC (rev 222295)
@@ -85,6 +85,7 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""
@@ -93,11 +94,13 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
<script src=""