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

Issue 460763002: Fix returning from async functions. (Closed)

Created:
6 years, 4 months ago by Michael Lippautz (Google)
Modified:
6 years, 4 months ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org, Ivan Posva
Visibility:
Public.

Description

This CL deals with handling of return statements in functions modified as async. These functions contain a so-called async closure (with the actual body) that should not just return when encountering a return statement, but rather call the completer first and then return (null). Previously the last return node has been replaced with a completer.complete call. This does not work for return statements in nested blocks or try-catch-finally blocks. Instead of replacing return statements we now call the completer after resolving all steps necessary for return nodes, i.e., right after inlining all finally blocks. We also need "continuation" returns later on that do not complete the completer. We differentiate by whether a return node has its scope set or not. BUG= R=hausner@google.com, srdjan@google.com Committed: https://code.google.com/p/dart/source/detail?r=39167

Patch Set 1 : #

Total comments: 2

Patch Set 2 : add scope via sequencenode add method #

Total comments: 6

Patch Set 3 : first set of comments #

Total comments: 2

Patch Set 4 : #

Patch Set 5 : update language test status #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+164 lines, -43 lines) Patch
M runtime/vm/ast.h View 1 2 3 4 chunks +15 lines, -3 lines 0 comments Download
M runtime/vm/ast.cc View 1 2 1 chunk +8 lines, -0 lines 0 comments Download
M runtime/vm/flow_graph_builder.cc View 1 2 1 chunk +36 lines, -0 lines 1 comment Download
M runtime/vm/parser.cc View 1 5 chunks +8 lines, -40 lines 0 comments Download
A tests/language/async_control_structures_test.dart View 1 2 1 chunk +95 lines, -0 lines 0 comments Download
M tests/language/language.status View 1 2 3 4 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 11 (0 generated)
Michael Lippautz (Google)
adding the scope to return nodes seems ugly, any suggestions?
6 years, 4 months ago (2014-08-12 18:21:57 UTC) #1
hausner
Holding off with the review until you make the change we discussed offline. https://codereview.chromium.org/460763002/diff/180001/runtime/vm/ast.h File ...
6 years, 4 months ago (2014-08-12 20:03:56 UTC) #2
Michael Lippautz (Google)
PTAL, scope is now added through SequenceNode::Add() to return nodes. https://codereview.chromium.org/460763002/diff/180001/runtime/vm/ast.h File runtime/vm/ast.h (right): https://codereview.chromium.org/460763002/diff/180001/runtime/vm/ast.h#newcode521 ...
6 years, 4 months ago (2014-08-12 20:32:12 UTC) #3
hausner
LGTMwC https://codereview.chromium.org/460763002/diff/220001/runtime/vm/ast.h File runtime/vm/ast.h (right): https://codereview.chromium.org/460763002/diff/220001/runtime/vm/ast.h#newcode261 runtime/vm/ast.h:261: void Add(AstNode* node) { This should now maybe ...
6 years, 4 months ago (2014-08-12 20:51:27 UTC) #4
Michael Lippautz (Google)
Thanks, waiting for a backend guy :) https://codereview.chromium.org/460763002/diff/220001/runtime/vm/ast.h File runtime/vm/ast.h (right): https://codereview.chromium.org/460763002/diff/220001/runtime/vm/ast.h#newcode261 runtime/vm/ast.h:261: void Add(AstNode* ...
6 years, 4 months ago (2014-08-12 21:13:57 UTC) #5
srdjan
lgtm https://codereview.chromium.org/460763002/diff/240001/runtime/vm/ast.h File runtime/vm/ast.h (right): https://codereview.chromium.org/460763002/diff/240001/runtime/vm/ast.h#newcode566 runtime/vm/ast.h:566: // Returns true if the return node is ...
6 years, 4 months ago (2014-08-12 21:39:25 UTC) #6
Michael Lippautz (Google)
Committed patchset #5 manually as 39167 (presubmit successful).
6 years, 4 months ago (2014-08-12 21:50:44 UTC) #7
Michael Lippautz (Google)
https://codereview.chromium.org/460763002/diff/240001/runtime/vm/ast.h File runtime/vm/ast.h (right): https://codereview.chromium.org/460763002/diff/240001/runtime/vm/ast.h#newcode566 runtime/vm/ast.h:566: // Returns true if the return node is not ...
6 years, 4 months ago (2014-08-12 21:50:51 UTC) #8
Florian Schneider
https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_builder.cc File runtime/vm/flow_graph_builder.cc (right): https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_builder.cc#newcode1069 runtime/vm/flow_graph_builder.cc:1069: arguments->Add(PushArgument(rcv_value)); I'm not sure this works. Is this code ...
6 years, 4 months ago (2014-08-13 11:10:29 UTC) #9
Florian Schneider
On 2014/08/13 11:10:29, Florian Schneider wrote: > https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_builder.cc > File runtime/vm/flow_graph_builder.cc (right): > > https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_builder.cc#newcode1069 ...
6 years, 4 months ago (2014-08-13 11:26:36 UTC) #10
Michael Lippautz (Google)
6 years, 4 months ago (2014-08-13 16:25:33 UTC) #11
Message was sent while issue was closed.
On 2014/08/13 11:26:36, Florian Schneider wrote:
> On 2014/08/13 11:10:29, Florian Schneider wrote:
> >
>
https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_b...
> > File runtime/vm/flow_graph_builder.cc (right):
> > 
> >
>
https://codereview.chromium.org/460763002/diff/280001/runtime/vm/flow_graph_b...
> > runtime/vm/flow_graph_builder.cc:1069:
> arguments->Add(PushArgument(rcv_value));
> > I'm not sure this works. Is this code path exercised by your tests?
> > 
> > You need to follow a stack discipline when pushing the arguments. Bind
pushes
> on
> > the expression stack, PushArgument consumes the top value.
> > 
> > Do(BuildStoreExprTemp(return_value));
> > 
> > Value* rcv_value = Bind(BuildLoadLocal(*rcv_var));
> > arguments->Add(PushArgument(rcv_value));
> > 
> > Value* returned_value = Bind(BuildLoadExprTemp());
> > arguments->Add(PushArgument(returned_value));
> > 
> > In this case you could also just swap the two PushArgument calls, because
> > evaluating the arguments does not have side-effects.
> 
> This is probably the reason it does not work for optimized code.

Thanksa lot! Yes, this also fixes the problem w/ optimized code.

See https://codereview.chromium.org/467323002/

Powered by Google App Engine
This is Rietveld 408576698