Commit 8f8b5f8c authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[es2018] Consistently use AsyncReturnStatement in async functions.

The Parser desugaring didn't use the AsyncReturnStatement consistently
to return from async functions (aka resolve the .promise with the return
value and return the .promise from the async function). Instead the
Parser essentially had a copy of the BytecodeGenerator functionality.

This change unifies the handling of returns from async functions.

Bug: v8:7522, v8:8238
Change-Id: Ib00a60aee30d541b84835d9cc83e9937b7a39e26
Reviewed-on: https://chromium-review.googlesource.com/c/1269036Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56453}
parent 762bf214
......@@ -2926,19 +2926,6 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
return result;
}
Expression* Parser::BuildResolvePromise(Expression* value, int pos) {
// %ResolvePromise(.promise, value), .promise
ZonePtrList<Expression>* args =
new (zone()) ZonePtrList<Expression>(2, zone());
args->Add(factory()->NewVariableProxy(PromiseVariable()), zone());
args->Add(value, zone());
Expression* call_runtime =
factory()->NewCallRuntime(Runtime::kInlineResolvePromise, args, pos);
return factory()->NewBinaryOperation(
Token::COMMA, call_runtime,
factory()->NewVariableProxy(PromiseVariable()), pos);
}
Expression* Parser::BuildRejectPromise(Expression* value, int pos) {
// %promise_internal_reject(.promise, value, false), .promise
// Disables the additional debug event for the rejection since a debug event
......@@ -3574,10 +3561,9 @@ void Parser::RewriteAsyncFunctionBody(ZonePtrList<Statement>* body,
// })
// }
return_value = BuildResolvePromise(return_value, return_value->position());
block->statements()->Add(
factory()->NewReturnStatement(return_value, return_value->position()),
zone());
block->statements()->Add(factory()->NewAsyncReturnStatement(
return_value, return_value->position()),
zone());
block = BuildRejectPromiseOnException(block);
body->Add(block, zone());
}
......
......@@ -547,7 +547,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
Expression* BuildInitialYield(int pos, FunctionKind kind);
Assignment* BuildCreateJSGeneratorObject(int pos, FunctionKind kind);
Expression* BuildResolvePromise(Expression* value, int pos);
Expression* BuildRejectPromise(Expression* value, int pos);
Variable* PromiseVariable();
Variable* AsyncGeneratorAwaitVariable();
......
......@@ -16,7 +16,7 @@ snippet: "
"
frame size: 23
parameter count: 1
bytecode array length: 514
bytecode array length: 518
bytecodes: [
B(SwitchOnGeneratorState), R(3), U8(0), U8(3),
B(Mov), R(closure), R(12),
......@@ -183,14 +183,11 @@ bytecodes: [
B(Ldar), R(17),
B(ReThrow),
B(LdaUndefined),
B(Star), R(17),
B(Mov), R(0), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(16), U8(2),
B(Star), R(13),
B(LdaZero),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(16),
B(CreateCatchContext), R(16), U8(12),
B(Star), R(15),
......@@ -205,7 +202,7 @@ bytecodes: [
B(Mov), R(0), R(17),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(17), U8(3),
B(PopContext), R(16),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(16),
......@@ -214,7 +211,7 @@ bytecodes: [
B(Star), R(12),
B(Jump), U8(8),
B(Star), R(13),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(12),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -226,8 +223,13 @@ bytecodes: [
B(Ldar), R(14),
B(SetPendingMessage),
B(Ldar), R(12),
B(SwitchOnSmiNoFeedback), U8(13), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(13), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(15),
B(Mov), R(13), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(15), U8(2),
B(Ldar), R(0),
/* 57 S> */ B(Return),
B(Ldar), R(13),
/* 57 S> */ B(Return),
B(Ldar), R(13),
......@@ -250,11 +252,12 @@ constant pool: [
ONE_BYTE_INTERNALIZED_STRING_TYPE [""],
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[26, 467, 475],
[29, 428, 430],
[26, 458, 466],
[29, 418, 420],
[35, 211, 219],
[38, 174, 176],
[279, 328, 330],
......@@ -269,7 +272,7 @@ snippet: "
"
frame size: 23
parameter count: 1
bytecode array length: 543
bytecode array length: 532
bytecodes: [
B(SwitchOnGeneratorState), R(3), U8(0), U8(3),
B(Mov), R(closure), R(12),
......@@ -437,16 +440,13 @@ bytecodes: [
B(LdaZero),
B(Star), R(12),
B(Mov), R(17), R(13),
B(Jump), U8(78),
B(Jump), U8(67),
B(Ldar), R(17),
B(ReThrow),
B(LdaUndefined),
B(Star), R(17),
B(Mov), R(0), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(16), U8(2),
B(LdaSmi), I8(1),
B(Star), R(13),
B(LdaZero),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(16),
......@@ -519,8 +519,8 @@ constant pool: [
Smi [22],
]
handlers: [
[26, 483, 491],
[29, 443, 445],
[26, 472, 480],
[29, 432, 434],
[35, 213, 221],
[38, 176, 178],
[282, 331, 333],
......@@ -538,7 +538,7 @@ snippet: "
"
frame size: 23
parameter count: 1
bytecode array length: 532
bytecode array length: 536
bytecodes: [
B(SwitchOnGeneratorState), R(3), U8(0), U8(3),
B(Mov), R(closure), R(12),
......@@ -713,14 +713,11 @@ bytecodes: [
B(Ldar), R(17),
B(ReThrow),
B(LdaUndefined),
B(Star), R(17),
B(Mov), R(0), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(16), U8(2),
B(Star), R(13),
B(LdaZero),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(16),
B(CreateCatchContext), R(16), U8(12),
B(Star), R(15),
......@@ -735,7 +732,7 @@ bytecodes: [
B(Mov), R(0), R(17),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(17), U8(3),
B(PopContext), R(16),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(16),
......@@ -744,7 +741,7 @@ bytecodes: [
B(Star), R(12),
B(Jump), U8(8),
B(Star), R(13),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(12),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -756,8 +753,13 @@ bytecodes: [
B(Ldar), R(14),
B(SetPendingMessage),
B(Ldar), R(12),
B(SwitchOnSmiNoFeedback), U8(13), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(13), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(15),
B(Mov), R(13), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(15), U8(2),
B(Ldar), R(0),
/* 114 S> */ B(Return),
B(Ldar), R(13),
/* 114 S> */ B(Return),
B(Ldar), R(13),
......@@ -780,11 +782,12 @@ constant pool: [
ONE_BYTE_INTERNALIZED_STRING_TYPE [""],
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[26, 485, 493],
[29, 446, 448],
[26, 476, 484],
[29, 436, 438],
[35, 229, 237],
[38, 192, 194],
[297, 346, 348],
......@@ -800,7 +803,7 @@ snippet: "
"
frame size: 20
parameter count: 1
bytecode array length: 403
bytecode array length: 392
bytecodes: [
/* 16 E> */ B(StackCheck),
B(CallJSRuntime), U8(%async_function_promise_create), R(0), U8(0),
......@@ -916,16 +919,13 @@ bytecodes: [
B(LdaZero),
B(Star), R(10),
B(Mov), R(15), R(11),
B(Jump), U8(78),
B(Jump), U8(67),
B(Ldar), R(15),
B(ReThrow),
B(LdaUndefined),
B(Star), R(15),
B(Mov), R(0), R(14),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(14), U8(2),
B(LdaSmi), I8(1),
B(Star), R(11),
B(LdaZero),
B(Star), R(10),
B(Mov), R(0), R(11),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(14),
......@@ -996,8 +996,8 @@ constant pool: [
Smi [22],
]
handlers: [
[10, 343, 351],
[13, 303, 305],
[10, 332, 340],
[13, 292, 294],
[27, 150, 158],
[30, 113, 115],
[219, 229, 231],
......
......@@ -926,7 +926,7 @@ snippet: "
"
frame size: 23
parameter count: 2
bytecode array length: 363
bytecode array length: 367
bytecodes: [
/* 16 E> */ B(StackCheck),
B(CallJSRuntime), U8(%async_function_promise_create), R(0), U8(0),
......@@ -1038,14 +1038,11 @@ bytecodes: [
B(Ldar), R(18),
B(ReThrow),
B(LdaUndefined),
B(Star), R(18),
B(Mov), R(0), R(17),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(17), U8(2),
B(Star), R(14),
B(LdaZero),
B(Star), R(13),
B(Mov), R(0), R(14),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(17),
B(CreateCatchContext), R(17), U8(7),
B(Star), R(16),
......@@ -1060,7 +1057,7 @@ bytecodes: [
B(Mov), R(0), R(18),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(18), U8(3),
B(PopContext), R(17),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(13),
B(Mov), R(0), R(14),
B(Jump), U8(16),
......@@ -1069,7 +1066,7 @@ bytecodes: [
B(Star), R(13),
B(Jump), U8(8),
B(Star), R(14),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(13),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -1081,8 +1078,13 @@ bytecodes: [
B(Ldar), R(15),
B(SetPendingMessage),
B(Ldar), R(13),
B(SwitchOnSmiNoFeedback), U8(8), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(8), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(16),
B(Mov), R(14), R(17),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(16), U8(2),
B(Ldar), R(0),
/* 60 S> */ B(Return),
B(Ldar), R(14),
/* 60 S> */ B(Return),
B(Ldar), R(14),
......@@ -1100,11 +1102,12 @@ constant pool: [
ONE_BYTE_INTERNALIZED_STRING_TYPE [""],
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[10, 316, 324],
[13, 277, 279],
[10, 307, 315],
[13, 267, 269],
[19, 137, 145],
[22, 100, 102],
[205, 215, 217],
......@@ -1119,7 +1122,7 @@ snippet: "
"
frame size: 23
parameter count: 2
bytecode array length: 414
bytecode array length: 418
bytecodes: [
B(SwitchOnGeneratorState), R(3), U8(0), U8(1),
B(Mov), R(closure), R(12),
......@@ -1249,14 +1252,11 @@ bytecodes: [
B(Ldar), R(17),
B(ReThrow),
B(LdaUndefined),
B(Star), R(17),
B(Mov), R(0), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(16), U8(2),
B(Star), R(13),
B(LdaZero),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(16),
B(CreateCatchContext), R(16), U8(8),
B(Star), R(15),
......@@ -1271,7 +1271,7 @@ bytecodes: [
B(Mov), R(0), R(17),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(17), U8(3),
B(PopContext), R(16),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(12),
B(Mov), R(0), R(13),
B(Jump), U8(16),
......@@ -1280,7 +1280,7 @@ bytecodes: [
B(Star), R(12),
B(Jump), U8(8),
B(Star), R(13),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(12),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -1292,8 +1292,13 @@ bytecodes: [
B(Ldar), R(14),
B(SetPendingMessage),
B(Ldar), R(12),
B(SwitchOnSmiNoFeedback), U8(9), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(9), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(15),
B(Mov), R(13), R(16),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(15), U8(2),
B(Ldar), R(0),
/* 54 S> */ B(Return),
B(Ldar), R(13),
/* 54 S> */ B(Return),
B(Ldar), R(13),
......@@ -1312,11 +1317,12 @@ constant pool: [
ONE_BYTE_INTERNALIZED_STRING_TYPE [""],
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[26, 367, 375],
[29, 328, 330],
[26, 358, 366],
[29, 318, 320],
[35, 188, 196],
[38, 151, 153],
[256, 266, 268],
......
......@@ -381,7 +381,7 @@ snippet: "
"
frame size: 12
parameter count: 1
bytecode array length: 140
bytecode array length: 144
bytecodes: [
/* 16 E> */ B(StackCheck),
B(CallJSRuntime), U8(%async_function_promise_create), R(0), U8(0),
......@@ -400,16 +400,13 @@ bytecodes: [
B(Star), R(2),
B(JumpLoop), U8(17), I8(0),
B(LdaUndefined),
B(Star), R(9),
B(Mov), R(0), R(8),
/* 49 E> */ B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(8), U8(2),
B(Star), R(5),
B(LdaZero),
B(Star), R(4),
B(Mov), R(0), R(5),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(8),
B(CreateCatchContext), R(8), U8(0),
/* 49 E> */ B(CreateCatchContext), R(8), U8(0),
B(Star), R(7),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -422,7 +419,7 @@ bytecodes: [
B(Mov), R(0), R(9),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(9), U8(3),
B(PopContext), R(8),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(4),
B(Mov), R(0), R(5),
B(Jump), U8(16),
......@@ -431,7 +428,7 @@ bytecodes: [
B(Star), R(4),
B(Jump), U8(8),
B(Star), R(5),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(4),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -443,8 +440,13 @@ bytecodes: [
B(Ldar), R(6),
B(SetPendingMessage),
B(Ldar), R(4),
B(SwitchOnSmiNoFeedback), U8(1), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(1), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(7),
B(Mov), R(5), R(8),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(7), U8(2),
B(Ldar), R(0),
/* 67 S> */ B(Return),
B(Ldar), R(5),
/* 67 S> */ B(Return),
B(Ldar), R(5),
......@@ -455,11 +457,12 @@ bytecodes: [
constant pool: [
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[10, 93, 101],
[13, 54, 56],
[10, 84, 92],
[13, 44, 46],
]
---
......@@ -471,7 +474,7 @@ snippet: "
"
frame size: 11
parameter count: 1
bytecode array length: 191
bytecode array length: 195
bytecodes: [
B(SwitchOnGeneratorState), R(2), U8(0), U8(1),
B(Mov), R(closure), R(3),
......@@ -508,16 +511,13 @@ bytecodes: [
B(Star), R(1),
B(JumpLoop), U8(52), I8(0),
B(LdaUndefined),
B(Star), R(8),
B(Mov), R(0), R(7),
/* 49 E> */ B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(7), U8(2),
B(Star), R(4),
B(LdaZero),
B(Star), R(3),
B(Mov), R(0), R(4),
B(Jump), U8(55),
B(Jump), U8(39),
B(Jump), U8(56),
B(Jump), U8(40),
B(Star), R(7),
B(CreateCatchContext), R(7), U8(1),
/* 49 E> */ B(CreateCatchContext), R(7), U8(1),
B(Star), R(6),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -530,7 +530,7 @@ bytecodes: [
B(Mov), R(0), R(8),
B(InvokeIntrinsic), U8(Runtime::k_RejectPromise), R(8), U8(3),
B(PopContext), R(7),
B(LdaZero),
B(LdaSmi), I8(1),
B(Star), R(3),
B(Mov), R(0), R(4),
B(Jump), U8(16),
......@@ -539,7 +539,7 @@ bytecodes: [
B(Star), R(3),
B(Jump), U8(8),
B(Star), R(4),
B(LdaSmi), I8(1),
B(LdaSmi), I8(2),
B(Star), R(3),
B(LdaTheHole),
B(SetPendingMessage),
......@@ -551,8 +551,13 @@ bytecodes: [
B(Ldar), R(5),
B(SetPendingMessage),
B(Ldar), R(3),
B(SwitchOnSmiNoFeedback), U8(2), U8(2), I8(0),
B(Jump), U8(8),
B(SwitchOnSmiNoFeedback), U8(2), U8(3), I8(0),
B(Jump), U8(21),
B(Mov), R(0), R(6),
B(Mov), R(4), R(7),
B(InvokeIntrinsic), U8(Runtime::k_ResolvePromise), R(6), U8(2),
B(Ldar), R(0),
/* 61 S> */ B(Return),
B(Ldar), R(4),
/* 61 S> */ B(Return),
B(Ldar), R(4),
......@@ -564,10 +569,11 @@ constant pool: [
Smi [58],
SCOPE_INFO_TYPE,
Smi [6],
Smi [9],
Smi [19],
Smi [22],
]
handlers: [
[26, 144, 152],
[29, 105, 107],
[26, 135, 143],
[29, 95, 97],
]
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