Log Message
[WHLSL] Call expressions shouldn't have type arguments https://bugs.webkit.org/show_bug.cgi?id=188770
Reviewed by Filip Pizlo. Call expressions only had type arguments for casts, becuase native types can have type arguments. However, instead of putting those type arguments on the CallExpression, we should parse the casted type as a real type and not as an identifier, which puts the type arguments in the TypeRef. Test: casts * WebGPUShadingLanguageRI/CallExpression.js: (CallExpression): (CallExpression.prototype.get name): (CallExpression.resolve): (CallExpression.prototype.get typeArguments): Deleted. (CallExpression.prototype.becomeCast): Deleted. * WebGPUShadingLanguageRI/NameResolver.js: (NameResolver.prototype.visitCallExpression): * WebGPUShadingLanguageRI/Parse.js: (parseConstexpr): (parseTypeDef): (parseLeftOperatorCall): (parseCallExpression.let.parseArguments): (parsePossiblePrefix): (parsePossibleRelationalEquality): (parseLeftLogicalExpression): (parseIfStatement): (parseWhile): (parseFor): (parseDo): * WebGPUShadingLanguageRI/RemoveTypeArguments.js: * WebGPUShadingLanguageRI/Rewriter.js: (Rewriter.prototype.visitCallExpression):
Modified Paths
- trunk/Tools/ChangeLog
- trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js
- trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js
- trunk/Tools/WebGPUShadingLanguageRI/Parse.js
- trunk/Tools/WebGPUShadingLanguageRI/RemoveTypeArguments.js
- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js
- trunk/Tools/WebGPUShadingLanguageRI/Test.js
Diff
Modified: trunk/Tools/ChangeLog (235143 => 235144)
--- trunk/Tools/ChangeLog 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/ChangeLog 2018-08-21 23:28:35 UTC (rev 235144)
@@ -1,3 +1,40 @@
+2018-08-21 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ [WHLSL] Call expressions shouldn't have type arguments
+ https://bugs.webkit.org/show_bug.cgi?id=188770
+
+ Reviewed by Filip Pizlo.
+
+ Call expressions only had type arguments for casts, becuase native types can have type arguments.
+ However, instead of putting those type arguments on the CallExpression, we should parse the casted
+ type as a real type and not as an identifier, which puts the type arguments in the TypeRef.
+
+ Test: casts
+
+ * WebGPUShadingLanguageRI/CallExpression.js:
+ (CallExpression):
+ (CallExpression.prototype.get name):
+ (CallExpression.resolve):
+ (CallExpression.prototype.get typeArguments): Deleted.
+ (CallExpression.prototype.becomeCast): Deleted.
+ * WebGPUShadingLanguageRI/NameResolver.js:
+ (NameResolver.prototype.visitCallExpression):
+ * WebGPUShadingLanguageRI/Parse.js:
+ (parseConstexpr):
+ (parseTypeDef):
+ (parseLeftOperatorCall):
+ (parseCallExpression.let.parseArguments):
+ (parsePossiblePrefix):
+ (parsePossibleRelationalEquality):
+ (parseLeftLogicalExpression):
+ (parseIfStatement):
+ (parseWhile):
+ (parseFor):
+ (parseDo):
+ * WebGPUShadingLanguageRI/RemoveTypeArguments.js:
+ * WebGPUShadingLanguageRI/Rewriter.js:
+ (Rewriter.prototype.visitCallExpression):
+
2018-08-21 Alex Christensen <achristen...@webkit.org>
Translate WebKit.LimitTitleSize API test into ObjC
Modified: trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/CallExpression.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -25,11 +25,10 @@
"use strict";
class CallExpression extends _expression_ {
- constructor(origin, name, typeArguments, argumentList)
+ constructor(origin, name, argumentList)
{
super(origin);
this._name = name;
- this._typeArguments = typeArguments;
this._argumentList = argumentList;
this.func = null;
this._isCast = false;
@@ -37,7 +36,6 @@
}
get name() { return this._name; }
- get typeArguments() { return this._typeArguments; }
get argumentList() { return this._argumentList; }
get isCast() { return this._isCast; }
get returnType() { return this._returnType; }
@@ -44,7 +42,7 @@
static resolve(origin, possibleOverloads, name, argumentList, argumentTypes, returnType, program)
{
- let call = new CallExpression(origin, name, [], argumentList);
+ let call = new CallExpression(origin, name, argumentList);
call.argumentTypes = argumentTypes.map(argument => argument.visit(new AutoWrapper()));
call.possibleOverloads = possibleOverloads;
if (returnType)
@@ -164,14 +162,6 @@
return result;
}
- becomeCast(returnType)
- {
- this._returnType = new TypeRef(this.origin, this.name);
- this._returnType.type = returnType;
- this._name = "operator cast";
- this._isCast = true;
- }
-
setCastData(returnType)
{
this._returnType = returnType;
Modified: trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -198,15 +198,13 @@
let funcs = this._nameContext.get(Func, node.name);
if (funcs)
node.possibleOverloads = funcs;
- else {
- let type = this._nameContext.get(Type, node.name);
- if (!type)
- throw new WTypeError(node.origin.originString, "Cannot find any function or type named \"" + node.name + "\"");
- node.becomeCast(type);
+ else if (node.name != "operator cast"){
+ node.setCastData(new TypeRef(node.origin, node.name));
node.possibleOverloads = this._nameContext.get(Func, "operator cast");
- if (!node.possibleOverloads)
- throw new WTypeError(node.origin.originString, "Cannot find any operator cast implementations in cast to " + type);
}
+
+ if (!node.possibleOverloads)
+ throw new WTypeError(node.origin.originString, "Cannot find any possible overloads for " + node);
super.visitCallExpression(node);
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Parse.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/Parse.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/Parse.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -188,7 +188,7 @@
{
let token;
if (token = tryConsume("-"))
- return new CallExpression(token, "operator" + token.text, [], [parseTerm()]);
+ return new CallExpression(token, "operator" + token.text, [parseTerm()]);
let left = parseTerm();
if (token = tryConsume("."))
left = new DotExpression(token, left, consumeKind("identifier").text);
@@ -285,7 +285,7 @@
let origin = consume("typedef");
let name = consumeKind("identifier").text;
consume("=");
- let type = parseType(true);
+ let type = parseType();
consume(";");
return new TypeDef(origin, name, type);
}
@@ -304,33 +304,50 @@
return genericParseLeft(
texts, nextParser,
(token, left, right) =>
- new CallExpression(token, "operator" + token.text, [], [left, right]));
+ new CallExpression(token, "operator" + token.text, [left, right]));
}
function parseCallExpression()
{
- let name = consumeKind("identifier");
- let typeArguments = parseTypeArguments();
- consume("(");
- let argumentList = [];
- while (!test(")")) {
- let argument = parsePossibleAssignment();
- argumentList.push(argument);
- if (!tryConsume(","))
- break;
+ let parseArguments = function(origin, callName) {
+ let argumentList = [];
+ while (!test(")")) {
+ let argument = parsePossibleAssignment();
+ argumentList.push(argument);
+ if (!tryConsume(","))
+ break;
+ }
+ consume(")");
+ return new CallExpression(origin, callName, argumentList);
}
- consume(")");
- let result = new CallExpression(name, name.text, typeArguments, argumentList);
- return result;
+
+ let name = lexer.backtrackingScope(() => {
+ let name = consumeKind("identifier");
+ consume("(");
+ return name;
+ });
+
+ if (name) {
+ let result = parseArguments(name, name.text);
+ return result;
+ } else {
+ let returnType = parseType();
+ consume("(");
+ let result = parseArguments(returnType.origin, "operator cast");
+ result.setCastData(returnType);
+ return result;
+ }
}
function isCallExpression()
{
return lexer.testScope(() => {
- consumeKind("identifier");
- parseTypeArguments();
- consume("(");
- });
+ consumeKind("identifier");
+ consume("(");
+ }) || lexer.testScope(() => {
+ parseType();
+ consume("(");
+ });
}
function emitIncrement(token, old, extraArg)
@@ -346,7 +363,7 @@
if (name == "operator")
throw new Error("Invalid name: " + name);
- return new CallExpression(token, name, [], args);
+ return new CallExpression(token, name, args);
}
function finishParsingPostIncrement(token, left)
@@ -419,7 +436,7 @@
if (test("++", "--"))
return parsePreIncrement();
if (token = tryConsume("+", "-", "~"))
- return new CallExpression(token, "operator" + token.text, [], [parsePossiblePrefix()]);
+ return new CallExpression(token, "operator" + token.text, [parsePossiblePrefix()]);
if (token = tryConsume("*"))
return new DereferenceExpression(token, parsePossiblePrefix());
if (token = tryConsume("&"))
@@ -428,7 +445,7 @@
return new MakeArrayRefExpression(token, parsePossiblePrefix());
if (token = tryConsume("!")) {
let remainder = parsePossiblePrefix();
- return new LogicalNot(token, new CallExpression(remainder.origin, "bool", [], [remainder]));
+ return new LogicalNot(token, new CallExpression(remainder.origin, "bool", [remainder]));
}
return parsePossibleSuffix();
}
@@ -458,7 +475,7 @@
return genericParseLeft(
["==", "!="], parsePossibleRelationalInequality,
(token, left, right) => {
- let result = new CallExpression(token, "operator==", [], [left, right]);
+ let result = new CallExpression(token, "operator==", [left, right]);
if (token.text == "!=")
result = new LogicalNot(token, result);
return result;
@@ -484,7 +501,7 @@
{
return genericParseLeft(
texts, nextParser,
- (token, left, right) => new LogicalExpression(token, token.text, new CallExpression(left.origin, "bool", [], [left]), new CallExpression(right.origin, "bool", [], [right])));
+ (token, left, right) => new LogicalExpression(token, token.text, new CallExpression(left.origin, "bool", [left]), new CallExpression(right.origin, "bool", [right])));
}
function parsePossibleLogicalAnd()
@@ -621,7 +638,7 @@
let elseBody;
if (tryConsume("else"))
elseBody = parseStatement();
- return new IfStatement(origin, new CallExpression(conditional.origin, "bool", [], [conditional]), body, elseBody);
+ return new IfStatement(origin, new CallExpression(conditional.origin, "bool", [conditional]), body, elseBody);
}
function parseWhile()
@@ -631,7 +648,7 @@
let conditional = parseExpression();
consume(")");
let body = parseStatement();
- return new WhileLoop(origin, new CallExpression(conditional.origin, "bool", [], [conditional]), body);
+ return new WhileLoop(origin, new CallExpression(conditional.origin, "bool", [conditional]), body);
}
function parseFor()
@@ -652,7 +669,7 @@
else {
condition = parseExpression();
consume(";");
- condition = new CallExpression(condition.origin, "bool", [], [condition]);
+ condition = new CallExpression(condition.origin, "bool", [condition]);
}
let increment;
if (tryConsume(")"))
@@ -673,7 +690,7 @@
consume("(");
let conditional = parseExpression();
consume(")");
- return new DoWhileLoop(origin, body, new CallExpression(conditional.origin, "bool", [], [conditional]));
+ return new DoWhileLoop(origin, body, new CallExpression(conditional.origin, "bool", [conditional]));
}
function parseVariableDecls()
Modified: trunk/Tools/WebGPUShadingLanguageRI/RemoveTypeArguments.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/RemoveTypeArguments.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/RemoveTypeArguments.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -59,15 +59,7 @@
node._name = RemoveTypeArguments.resolveNameAndArguments(node);
node._typeArguments = null;
}
-
- visitCallExpression(node)
- {
- node._name = RemoveTypeArguments.resolveNameAndArguments(node);
- if (!node._name || !node._name.length)
- throw new Error("lazy");
- node._typeArguments = null;
- }
}
program.visit(new RemoveTypeArguments());
-}
\ No newline at end of file
+}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -298,7 +298,7 @@
visitCallExpression(node)
{
let result = new CallExpression(
- node.origin, node.name, null,
+ node.origin, node.name,
node.argumentList.map(argument => Node.visit(argument, this)));
return this.processDerivedCallData(node, result);
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (235143 => 235144)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-08-21 22:41:11 UTC (rev 235143)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-08-21 23:28:35 UTC (rev 235144)
@@ -5197,6 +5197,50 @@
checkInt(program, callFunction(program, "foo", []), 354);
}
+tests.casts = function()
+{
+ let program = doPrep(`
+ struct Foo {
+ int x;
+ }
+ struct Bar {
+ int y;
+ }
+ operator Bar(Foo foo) {
+ Bar b;
+ b.y = foo.x + 7;
+ return b;
+ }
+ int baz(int z) {
+ Foo foo;
+ foo.x = z;
+ Bar b = Bar(foo);
+ return b.y;
+ }
+ `);
+ checkInt(program, callFunction(program, "baz", [makeInt(program, 6)]), 13);
+ program = doPrep(`
+ struct Foo {
+ int x;
+ }
+ struct Bar {
+ int y;
+ }
+ operator thread Bar*(thread Foo* foo) {
+ Bar b;
+ b.y = (*foo).x + 8;
+ return &b;
+ }
+ int baz(int z) {
+ Foo foo;
+ foo.x = z;
+ thread Bar* b = thread Bar*(&foo);
+ return (*b).y;
+ }
+ `);
+ checkInt(program, callFunction(program, "baz", [makeInt(program, 6)]), 14);
+}
+
okToTest = true;
let testFilter = /.*/; // run everything by default
_______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes