Commit 09674b92 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

WIP: [parser] Fix arrow function name inferring

This is a reland of part of
https://chromium-review.googlesource.com/c/v8/v8/+/1397664.

It drops the explicit fni_.Infer() call after parsing arrow functions. We'll
want to avoid inferring if the arrow function is an argument to a function
call.

It also avoids adding the single argument of "name => " to the inferred name.

Bug: chromium:916975
Change-Id: I96a934408113483d73eba14073fe21e8cfe2ada6
Reviewed-on: https://chromium-review.googlesource.com/c/1397665
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58613}
parent a76d560e
......@@ -1667,9 +1667,7 @@ ParserBase<Impl>::ParsePrimaryExpression() {
parsing_scope.ValidateDeclaration();
FunctionState function_state(&function_state_, &scope_,
next_arrow_function_info_.scope);
InferName infer = kind == FunctionKind::kArrowFunction ? InferName::kYes
: InferName::kNo;
return impl()->ExpressionFromIdentifier(name, beg_pos, infer);
return impl()->ExpressionFromIdentifier(name, beg_pos, InferName::kNo);
}
IdentifierT name = ParseAndClassifyIdentifier(token);
......@@ -2621,8 +2619,6 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() {
expression = ParseArrowFunctionLiteral(parameters);
fni_.Infer();
return expression;
}
......
......@@ -42,7 +42,7 @@ userFunction (test.js:1:36)
-- inner async --
runWithRegular (utils.js:2:12)
inner (test.js:2:28)
runWithRegular (utils.js:21:4)
(anonymous) (utils.js:21:4)
<external stack>
EmptyName
......@@ -88,7 +88,7 @@ userFunction (test.js:1:36)
-- <empty> --
runWithEmptyName (utils.js:6:12)
inner (test.js:2:28)
runWithRegular (utils.js:21:4)
(anonymous) (utils.js:21:4)
<external stack>
EmptyStack
......@@ -147,6 +147,6 @@ userFunction (test.js:1:36)
External
userFunction (test.js:1:36)
runWithRegular (utils.js:21:4)
(anonymous) (utils.js:21:4)
<external stack>
......@@ -80,11 +80,11 @@ thenableJob2 (test.js:64:57)
Running test: testSetTimeouts
foo1 (test.js:10:2)
setTimeout (test.js:72:25)
(anonymous) (test.js:72:25)
-- setTimeout --
setTimeout (test.js:72:6)
(anonymous) (test.js:72:6)
-- setTimeout --
setTimeout (test.js:71:4)
(anonymous) (test.js:71:4)
-- setTimeout --
setTimeouts (test.js:70:2)
(anonymous) (expr.js:0:0)
......
......@@ -101,11 +101,11 @@ foo1 (test.js:156:4)
complex (test.js:202:5)
(anonymous) (testComplex.js:0:0)
p.then (test.js:207:8)
(anonymous) (test.js:207:8)
-- Promise.then --
p.then (test.js:206:8)
(anonymous) (test.js:206:8)
-- Promise.then --
setTimeout (test.js:205:6)
(anonymous) (test.js:205:6)
-- setTimeout --
complex (test.js:204:2)
(anonymous) (testComplex.js:0:0)
......
Tests super long async stacks.
callWithAsyncStack (expr.js:0:26)
(anonymous) (expr.js:0:26)
callWithAsyncStack (utils.js:3:4)
call1 (wrapper.js:0:20)
--Promise.then--
......
......@@ -213,12 +213,12 @@ f1 (test.js:4:36)
return await Promise.resolve(2);#
}
f1.then.x (test.js:10:27)
(anonymous) (test.js:10:27)
await f1();
await f1().then(x => x #* 2);
await [1].map(x => Promise.resolve(x))[0];
f1.then.x (test.js:10:30)
(anonymous) (test.js:10:30)
await f1();
await f1().then(x => x * 2#);
await [1].map(x => Promise.resolve(x))[0];
......@@ -228,13 +228,13 @@ f2 (test.js:11:4)
#await [1].map(x => Promise.resolve(x))[0];
await Promise.resolve().then(x => x * 2);
map.x (test.js:11:31)
(anonymous) (test.js:11:31)
f2 (test.js:11:14)
await f1().then(x => x * 2);
await [1].map(x => Promise.#resolve(x))[0];
await Promise.resolve().then(x => x * 2);
map.x (test.js:11:41)
(anonymous) (test.js:11:41)
f2 (test.js:11:14)
await f1().then(x => x * 2);
await [1].map(x => Promise.resolve(x)#)[0];
......
......@@ -153,32 +153,32 @@ asyncF (test.js:17:13)
return r;#
})();
Promise.resolve.then.then.x (test.js:4:64)
(anonymous) (test.js:4:64)
var arr1 = [1];
var promise = Promise.resolve(1).then(x => x * 2).then(x => x #/ 2);
Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve.then.then.x (test.js:4:67)
(anonymous) (test.js:4:67)
var arr1 = [1];
var promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2#);
Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve.then.then.x (test.js:5:50)
(anonymous) (test.js:5:50)
var promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve(1).then(x => x * 2).then(x => x #/ 2);
promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve.then.then.x (test.js:5:53)
(anonymous) (test.js:5:53)
var promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve(1).then(x => x * 2).then(x => x / 2#);
promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2);
Promise.resolve.then.then.x (test.js:6:60)
(anonymous) (test.js:6:60)
Promise.resolve(1).then(x => x * 2).then(x => x / 2);
promise = Promise.resolve(1).then(x => x * 2).then(x => x #/ 2);
var a = 1;
Promise.resolve.then.then.x (test.js:6:63)
(anonymous) (test.js:6:63)
Promise.resolve(1).then(x => x * 2).then(x => x / 2);
promise = Promise.resolve(1).then(x => x * 2).then(x => x / 2#);
var a = 1;
......
......@@ -81,10 +81,10 @@ function foo2() { Promise.resolve().then(() => 42) }
paused in foo1
function foo1() { Promise.resolve().then(() => 42) ^}
function foo2() { Promise.resolve().then(() => 42) }
paused in Promise.resolve.then
paused in
function foo1() { Promise.resolve().then(() => ^42) }
function foo2() { Promise.resolve().then(() => 42) }
paused in Promise.resolve.then
paused in
function foo1() { Promise.resolve().then(() => 42^) }
function foo2() { Promise.resolve().then(() => 42) }
......@@ -148,22 +148,22 @@ debugger; function foo3() { Promise.resolve().then(() => 42) }
function foo4() { Promise.resolve().then(() => 42) };
foo3();
foo4();^
paused in Promise.resolve.then
paused in
debugger; function foo3() { Promise.resolve().then(() => ^42) }
function foo4() { Promise.resolve().then(() => 42) };
foo3();
foo4();
paused in Promise.resolve.then
paused in
debugger; function foo3() { Promise.resolve().then(() => 42^) }
function foo4() { Promise.resolve().then(() => 42) };
foo3();
foo4();
paused in Promise.resolve.then
paused in
debugger; function foo3() { Promise.resolve().then(() => 42) }
function foo4() { Promise.resolve().then(() => ^42) };
foo3();
foo4();
paused in Promise.resolve.then
paused in
debugger; function foo3() { Promise.resolve().then(() => 42) }
function foo4() { Promise.resolve().then(() => 42^) };
foo3();
......@@ -247,19 +247,19 @@ paused in foo6
function foo5() { Promise.resolve().then(() => 42) }
function foo6() { Promise.resolve().then(() => 42) ^}
paused in Promise.resolve.then
paused in
function foo5() { Promise.resolve().then(() => ^42) }
function foo6() { Promise.resolve().then(() => 42) }
paused in Promise.resolve.then
paused in
function foo5() { Promise.resolve().then(() => 42^) }
function foo6() { Promise.resolve().then(() => 42) }
paused in Promise.resolve.then
paused in
function foo5() { Promise.resolve().then(() => 42) }
function foo6() { Promise.resolve().then(() => ^42) }
paused in Promise.resolve.then
paused in
function foo5() { Promise.resolve().then(() => 42) }
function foo6() { Promise.resolve().then(() => 42^) }
......
......@@ -46,7 +46,7 @@ Running test: testConsoleTraceWithEmptySync
callFrames : [
[0] : {
columnNumber : 66
functionName : Promise.then
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......
......@@ -23,7 +23,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -40,7 +40,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -58,7 +58,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -114,7 +114,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -131,7 +131,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -149,7 +149,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -205,7 +205,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -222,7 +222,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -240,7 +240,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -296,7 +296,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -313,7 +313,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -331,7 +331,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -387,7 +387,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -404,7 +404,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -422,7 +422,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -478,7 +478,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -495,7 +495,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......@@ -513,7 +513,7 @@ Run expression 'console.trace()' with async chain len: 3
}
[1] : {
columnNumber : 33
functionName : Promise.resolve.then
functionName :
lineNumber : 5
scriptId : <scriptId>
url :
......
......@@ -16,7 +16,7 @@ Debugger.scriptParsed.stackTrace should contain only one frame
callFrames : [
[0] : {
columnNumber : 17
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......
......@@ -3,11 +3,11 @@ Test for Debugger.stepInto with breakOnAsyncCall.
Running test: testSetTimeout
(anonymous) (test.js:0:0)
asyncCallStackTraceId is set
setTimeout (test.js:0:17)
(anonymous) (test.js:0:17)
asyncCallStackTraceId is empty
Running test: testPromiseThen
(anonymous) (test.js:0:2)
asyncCallStackTraceId is set
p.then (test.js:0:13)
(anonymous) (test.js:0:13)
asyncCallStackTraceId is empty
......@@ -14,7 +14,7 @@ Tests that microtasks run before the Runtime.evaluate response is sent
callFrames : [
[0] : {
columnNumber : 37
functionName : Promise.resolve.then
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......
......@@ -6,16 +6,16 @@ Check that exceptionThrown is supported by test runner.
columnNumber : 2
exception : {
className : Error
description : Error at setTimeout (<anonymous>:2:9)
description : Error at <anonymous>:2:9
objectId : <objectId>
preview : {
description : Error at setTimeout (<anonymous>:2:9)
description : Error at <anonymous>:2:9
overflow : false
properties : [
[0] : {
name : stack
type : string
value : Error at setTimeout (<anonymous>:2:9)
value : Error at <anonymous>:2:9
}
]
subtype : error
......@@ -31,7 +31,7 @@ Check that exceptionThrown is supported by test runner.
callFrames : [
[0] : {
columnNumber : 8
functionName : setTimeout
functionName :
lineNumber : 1
scriptId : <scriptId>
url :
......@@ -99,7 +99,7 @@ Check that exceptionThrown is supported by test runner.
callFrames : [
[0] : {
columnNumber : 2
functionName : setTimeout
functionName :
lineNumber : 1
scriptId : <scriptId>
url :
......
......@@ -125,7 +125,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 25
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -151,7 +151,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 25
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -178,7 +178,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 25
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -204,7 +204,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 25
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......
......@@ -19,7 +19,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 19
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -48,7 +48,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 19
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -78,7 +78,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 19
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -107,7 +107,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 19
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -137,7 +137,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 40
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -166,7 +166,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 40
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -215,7 +215,7 @@ From session 1
callFrames : [
[0] : {
columnNumber : 40
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......@@ -244,7 +244,7 @@ From session 2
callFrames : [
[0] : {
columnNumber : 40
functionName : setTimeout
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
......
......@@ -7,4 +7,4 @@ Error
Error: Reject with callback
at concatenateErrors (test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER})
at _ (test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER})
at test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER}
......@@ -6,7 +6,7 @@ Error
at *%(basename)s:9:1
Error: Error in reject handler
at _ *%(basename)s:11:17)
at promise.then.result (test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER})
at *%(basename)s:11:17
at test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER}
......@@ -6,8 +6,8 @@ Error
at *%(basename)s:9:1
Error: Error in resolve handler
at _ *%(basename)s:10:39)
at promise.then.result (test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER})
at *%(basename)s:10:39
at test/mjsunit/mjsunit.js:{NUMBER}:{NUMBER}
RuntimeError: unreachable
at main (wasm-function[0]:1)
at pair (*%(basename)s:16:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at *%(basename)s:16:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at main (wasm-function[0]:1)
at pair (test/message/wasm-function-name-async.js:16:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at test/message/wasm-function-name-async.js:16:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at test-module.main (wasm-function[0]:1)
at pair (*%(basename)s:17:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at *%(basename)s:17:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at test-module.main (wasm-function[0]:1)
at pair (test/message/wasm-module-and-function-name-async.js:17:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at test/message/wasm-module-and-function-name-async.js:17:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at test-module (wasm-function[0]:1)
at pair (*%(basename)s:19:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at *%(basename)s:19:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at test-module (wasm-function[0]:1)
at pair (test/message/wasm-module-name-async.js:19:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at test/message/wasm-module-name-async.js:19:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at wasm-function[0]:1
at pair (*%(basename)s:18:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at *%(basename)s:18:27
at test/mjsunit/mjsunit.js:*
RuntimeError: unreachable
at wasm-function[0]:1
at pair (test/message/wasm-no-name-async.js:18:27)
at promise.then.result (test/mjsunit/mjsunit.js:*)
at test/message/wasm-no-name-async.js:18:27
at test/mjsunit/mjsunit.js:*
......@@ -81,21 +81,19 @@ async function runTests() {
try { await reject(); } catch (e) { throw new Error("FAIL"); }
} }).c4, ["c4"]);
// TODO(caitp): We should infer anonymous async functions as the empty
// string, not as the name of a function they're passed as a parameter to.
await test(async x => { throw new Error("FAIL") },
["test", "test", "runTests"]);
["test", "runTests"]);
await test(async() => { throw new Error("FAIL") },
["test", "test", "runTests"]);
["test", "runTests"]);
await test(async(a) => { throw new Error("FAIL") },
["test", "test", "runTests"]);
["test", "runTests"]);
await test(async(a, b) => { throw new Error("FAIL") },
["test", "test", "runTests"]);
["test", "runTests"]);
await test(async x => { await 1; throw new Error("FAIL") }, ["test"]);
await test(async() => { await 1; throw new Error("FAIL") }, ["test"]);
await test(async(a) => { await 1; throw new Error("FAIL") }, ["test"]);
await test(async(a, b) => { await 1; throw new Error("FAIL") }, ["test"]);
await test(async x => { await 1; throw new Error("FAIL") }, []);
await test(async() => { await 1; throw new Error("FAIL") }, []);
await test(async(a) => { await 1; throw new Error("FAIL") }, []);
await test(async(a, b) => { await 1; throw new Error("FAIL") }, []);
await test(async x => {
await 1;
......@@ -104,7 +102,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async() => {
await 1;
......@@ -113,7 +111,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async(a) => {
await 1;
......@@ -122,7 +120,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async(a, b) => {
await 1;
......@@ -131,7 +129,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async x => {
await 1;
......@@ -140,7 +138,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async() => {
await 1;
......@@ -149,7 +147,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async(a) => {
await 1;
......@@ -158,7 +156,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
await test(async(a, b) => {
await 1;
......@@ -167,7 +165,7 @@ async function runTests() {
} catch (e) {
throw new Error("FAIL");
}
}, ["test"]);
}, []);
}
runTests().catch(e => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment