Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Issue 2654423004: [async-functions] support await expressions in finally statements (Closed)

Created:
3 years, 10 months ago by caitp
Modified:
3 years, 10 months ago
CC:
v8-reviews_googlegroups.com
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

[async-functions] support await expressions in finally statements Changes: - Async functions no longer desugar return statements in Parser::RewriteReturn. Instead, return desugaring happens in BytecodeGenerator::BuildReturn(). This enables evaluation of ResolvePromise() to wait until all finally blocks are evaluated - Parameter initialization block (created in Parser::BuildParameterInitializationBlock()) is now stored as a separate member of FunctionLiteral, rather than part of the function body. - The `Scope::function_var_` assignment (in named function expressions) happens in BytecodeGenerator rather than as part of the function body. This variable is created at the end of ParseFunctionBody in parser-base.h, and is guaranteed to be allocated if there are any inner lazily parsed function scopes which may capture the variable, or any eval calls which may capture the variable. - The above 2 changes allow for generators and async functions to be desugared in BytecodeGenerator, rather than in the Parser, allowing them to evaluate parameter initialization as part of a try-block, with a catch handler (in the case of async functions) and a finally block which closes the generator. - BytecodeGenerator::VisitTryCatchStatement and VisitTryFinallyStatement defer to BuildTryCatch and BuildTryFinally, to allow this code to be reused by the async function/generator desugarings in BytecodeGenerator::GenerateBytecodeBody() - BytecodeGenerator::VisitYield() now defers to BytecodeGenerator::BuildYield() and BytecodeGenerator::BuildAwait(), depending on what type of yield it is, which in turn perform different operations to suspend the generator. BuildYield() is also used to desugar the initial yield in generators and modules. Because of this, ast-numbering.cc ensures that modules and generator have at least one yield point, and syntactic yields begin at yield_id=1 rather than 0. Because await desugaring happens in BytecodeGenerator rather than in Parser::RewriteAwaitExpression(), BytecodeGenerator tracks the current catch_prediction via member catch_prediction_, in the same way that ast-numbering.cc does this. For each catch block generated (via BuildTryCatch), if the catch prediction bit is not HandlerTable::UNCAUGHT, BytecodeGenerator::catch_prediction_ is updated for the course of the catch block, and restored to its previous value afterwards. This results in BytecodeGenerator selecting the correct Await builtin, depending on whether it occurs at the top-level of an async function, or within a syntactic catch try scope. BUG=v8:5896 R=gsathya@chromium.org, rmcilroy@chromium.org, neis@chromium.org

Patch Set 1 #

Patch Set 2 : Get everything working (except possibly inspector tests) #

Total comments: 2

Patch Set 3 : make -Wunused-variable bots happy maybe #

Total comments: 4

Patch Set 4 : and again #

Patch Set 5 : make await desugaring behave like it used to in debugger #

Patch Set 6 : fix bytecode for await #

Patch Set 7 : clean merge #

Patch Set 8 : fix the test262 problems sort of #

Patch Set 9 : I'd like to build with -Wunused-variables locally, but how!? #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1380 lines, -1235 lines) Patch
M src/asmjs/asm-wasm-builder.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M src/ast/ast.h View 1 2 3 4 5 6 9 chunks +43 lines, -13 lines 0 comments Download
M src/ast/ast.cc View 1 2 3 4 5 6 1 chunk +13 lines, -1 line 0 comments Download
M src/ast/ast-expression-rewriter.cc View 1 3 chunks +6 lines, -1 line 0 comments Download
M src/ast/ast-numbering.cc View 1 2 3 4 5 6 3 chunks +26 lines, -1 line 0 comments Download
M src/ast/ast-traversal-visitor.h View 1 2 chunks +6 lines, -1 line 0 comments Download
M src/ast/prettyprinter.cc View 1 2 3 4 5 6 2 chunks +9 lines, -0 lines 0 comments Download
M src/ast/scopes.h View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M src/ast/scopes.cc View 1 2 3 4 5 6 7 8 1 chunk +12 lines, -0 lines 0 comments Download
M src/bailout-reason.h View 1 1 chunk +2 lines, -1 line 0 comments Download
M src/compiler/ast-graph-builder.cc View 1 2 3 4 5 6 1 chunk +5 lines, -0 lines 0 comments Download
M src/compiler/ast-loop-assignment-analyzer.cc View 1 2 chunks +2 lines, -1 line 0 comments Download
M src/crankshaft/hydrogen.cc View 1 2 3 4 5 6 1 chunk +4 lines, -0 lines 0 comments Download
M src/crankshaft/typing.cc View 1 2 chunks +2 lines, -1 line 0 comments Download
M src/full-codegen/full-codegen.cc View 1 2 3 4 5 6 2 chunks +5 lines, -0 lines 0 comments Download
M src/interpreter/bytecode-array-builder.h View 1 2 3 4 2 chunks +17 lines, -6 lines 0 comments Download
M src/interpreter/bytecode-generator.h View 1 2 3 4 5 2 chunks +24 lines, -0 lines 0 comments Download
M src/interpreter/bytecode-generator.cc View 1 2 3 4 5 6 15 chunks +305 lines, -41 lines 0 comments Download
M src/parsing/parser.h View 1 2 3 4 5 6 5 chunks +8 lines, -25 lines 0 comments Download
M src/parsing/parser.cc View 1 2 3 4 5 6 7 14 chunks +26 lines, -318 lines 0 comments Download
M src/parsing/parser-base.h View 1 2 3 4 5 6 7 20 chunks +39 lines, -121 lines 0 comments Download
M src/parsing/pattern-rewriter.cc View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
M src/parsing/preparser.h View 1 2 3 4 5 6 7 chunks +10 lines, -13 lines 0 comments Download
M src/parsing/preparser.cc View 1 1 chunk +3 lines, -2 lines 0 comments Download
M src/utils.h View 1 1 chunk +19 lines, -0 lines 0 comments Download
M test/cctest/interpreter/bytecode_expectations/Generators.golden View 1 2 3 4 5 6 12 chunks +229 lines, -251 lines 0 comments Download
M test/cctest/interpreter/bytecode_expectations/Modules.golden View 1 12 chunks +376 lines, -420 lines 0 comments Download
M test/cctest/interpreter/bytecode_expectations/ThisFunction.golden View 1 1 chunk +2 lines, -3 lines 0 comments Download
M test/debugger/debug/debug-scopes-suspended-generators.js View 1 2 3 4 9 chunks +5 lines, -15 lines 0 comments Download
A test/mjsunit/es8/async-function-try-finally.js View 1 1 chunk +177 lines, -0 lines 0 comments Download

Messages

Total messages: 47 (39 generated)
caitp
hi, I've hacked together a fix for this which seems to work locally. It's a ...
3 years, 10 months ago (2017-01-27 19:32:25 UTC) #3
caitp
I think the last test failures are related to Promise debug events, but will definitely ...
3 years, 10 months ago (2017-01-30 04:20:29 UTC) #20
Dan Ehrenberg
Could you separate out desugaring in the interpreter from addressing this bug in separate patches? ...
3 years, 10 months ago (2017-01-30 16:18:08 UTC) #40
adamk
From talking to neis about this this morning, it's not clear to me why moving ...
3 years, 10 months ago (2017-01-30 21:10:46 UTC) #43
caitp
On 2017/01/30 21:10:46, adamk wrote: > From talking to neis about this this morning, it's ...
3 years, 10 months ago (2017-01-30 22:23:01 UTC) #44
rmcilroy
On 2017/01/30 22:23:01, caitp wrote: > On 2017/01/30 21:10:46, adamk wrote: > > From talking ...
3 years, 10 months ago (2017-01-31 20:47:09 UTC) #45
rmcilroy
On 2017/01/31 20:47:09, rmcilroy (travelling till 3rd) wrote: > On 2017/01/30 22:23:01, caitp wrote: > ...
3 years, 10 months ago (2017-01-31 20:50:58 UTC) #46
caitp
3 years, 10 months ago (2017-01-31 21:40:59 UTC) #47
On 2017/01/31 20:47:09, rmcilroy (travelling till 3rd) wrote:
> I would definitly prefer a CL which is just moving where the desugaring
happens.
> I'd also like to understand why it's necessary to move the desugaring to the
> bytecode generator? This adds a lot of complexity and I'm not clear on the
> benefits. 
> 
> I'm traveling this week, so I'm unlikely to get to this review until next
week.

Moving the desugaring of `return` to the BytecodeGenerator allows us to reuse
the state machine which already exists, and defers return commands until after
finally blocks have been completed.

Moving the rest of the desugaring to bytecode is an easy fix for removing the
two implicit try/catch with just one in async functions, which has been on a
todo list for a while.

Powered by Google App Engine
This is Rietveld 408576698