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

Issue 9664062: Support allocating and calling closures in the new non-optimizing compiler. (Closed)

Created:
8 years, 9 months ago by Kevin Millikin (Google)
Modified:
8 years, 9 months ago
Reviewers:
srdjan
CC:
reviews_dartlang.org, regis
Visibility:
Public.

Description

Support allocating and calling closures in the new non-optimizing compiler. As part of this change, variable allocation is split out from the backend code generator. R=srdjan@google.com BUG= TEST= Committed: https://code.google.com/p/dart/source/detail?r=5392

Patch Set 1 #

Total comments: 12

Patch Set 2 : Incorporated review comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+339 lines, -174 lines) Patch
M runtime/vm/code_generator_ia32.cc View 1 5 chunks +39 lines, -66 lines 0 comments Download
M runtime/vm/code_generator_x64.cc View 1 5 chunks +39 lines, -66 lines 0 comments Download
M runtime/vm/compiler.cc View 1 chunk +1 line, -0 lines 0 comments Download
M runtime/vm/flow_graph_builder.h View 1 chunk +2 lines, -2 lines 0 comments Download
M runtime/vm/flow_graph_builder.cc View 1 7 chunks +77 lines, -6 lines 0 comments Download
M runtime/vm/flow_graph_compiler_x64.h View 1 2 chunks +0 lines, -3 lines 0 comments Download
M runtime/vm/flow_graph_compiler_x64.cc View 1 6 chunks +55 lines, -23 lines 0 comments Download
M runtime/vm/intermediate_language.h View 1 8 chunks +70 lines, -5 lines 0 comments Download
M runtime/vm/parser.h View 1 2 chunks +17 lines, -1 line 0 comments Download
M runtime/vm/parser.cc View 1 1 chunk +36 lines, -0 lines 0 comments Download
M runtime/vm/scopes.h View 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/unit_test.cc View 2 chunks +2 lines, -1 line 0 comments Download

Messages

Total messages: 6 (0 generated)
Kevin Millikin (Google)
It turns out to be hard and error-prone, to try to make the variable allocation ...
8 years, 9 months ago (2012-03-12 14:06:36 UTC) #1
srdjan
LGTM with one question/comment https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/code_generator_ia32.cc File runtime/vm/code_generator_ia32.cc (right): https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/code_generator_ia32.cc#newcode343 runtime/vm/code_generator_ia32.cc:343: // - allocate local variables ...
8 years, 9 months ago (2012-03-12 18:35:23 UTC) #2
srdjan
8 years, 9 months ago (2012-03-12 18:36:23 UTC) #3
srdjan
https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/flow_graph_builder.cc File runtime/vm/flow_graph_builder.cc (right): https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/flow_graph_builder.cc#newcode1495 runtime/vm/flow_graph_builder.cc:1495: } Why do we bailout here and not in ...
8 years, 9 months ago (2012-03-12 19:56:17 UTC) #4
srdjan
https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/parser.cc File runtime/vm/parser.cc (right): https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/parser.cc#newcode147 runtime/vm/parser.cc:147: local_count_ = first_local_index_ - next_free_frame_index; + copied_parameter_count_;
8 years, 9 months ago (2012-03-12 22:55:49 UTC) #5
Kevin Millikin (Google)
8 years, 9 months ago (2012-03-13 08:59:49 UTC) #6
https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/code_generat...
File runtime/vm/code_generator_ia32.cc (right):

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/code_generat...
runtime/vm/code_generator_ia32.cc:343: // - allocate local variables on stack.
On 2012/03/12 18:35:23, srdjan wrote:
> Remove this step. Maybe write as a comment that the local variables have
already
> been allocated.

OK, removed.  I thought it was referring to reserving space for them on stack.

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/code_generat...
runtime/vm/code_generator_ia32.cc:741: (function.context_scope() ==
ContextScope::null())) {
On 2012/03/12 18:35:23, srdjan wrote:
> Why the changed condition? Previously we did not go to else clause if
> IsNonImplicitClosureFunction was true, now we do.

Now we can have both IsNonImplicitClosureFunction() and context_scope() !=
ContextScope::null(), because it was set by the new backend which later bailed
out.

I suppose here we could throw it away and reset it, but I thought it better to
assume it was correct and use it.

The else only contains an if now, and I think IsNonImplicitClosureFunction() and
IsImplicitInstanceClosureFunction() are mutually exclusive, so the meaning
should be the same as before.

In any case, I will restructure it to be more clear.  What do you think of:

if (...IsNonImplicitClosureFunction()) {
  if (...context_scope() == ContextScope::null()) {
     ...
  }
} else if (...IsImplicitClosureFunction()) {
  ...
}

?

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/flow_graph_b...
File runtime/vm/flow_graph_builder.cc (right):

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/flow_graph_b...
runtime/vm/flow_graph_builder.cc:814: const int context_level = 0;  // Only
because we don't handle nesting yet.
On 2012/03/12 18:35:23, srdjan wrote:
> Dont you need to check that state()->context_level() == 0?

Eventually, or handle non-zero.  There is no context level tracking in this
compiler, yet.

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/flow_graph_b...
runtime/vm/flow_graph_builder.cc:1495: }
On 2012/03/12 19:56:17, srdjan wrote:
> Why do we bailout here and not in the FlowGraphCompiler.

I moved the bailout because I initially moved the variable allocation here
(needed for graph translation of closures and context variables correctly, in
the very back end is too late); and because the graph translation assumes (right
now) that we have already bailed out so it doesn't set an invalid context scope
on a function, that we could potentially observe if we bail out of this
compiler. 

When I realized that there was no good way to safely repeat the variable
allocation (it mutates variables, which are in the AST shared by the other
compiler, and so a pain in the butt to clear), I moved it out of the compilers.

It still seems like a good idea to bail out earlier for global properties like
this, rather than translate the graph and bail out much later.  It is safer and
easier to prototype this way---the graph translation can assume that we have
bailed out already in many cases.

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/parser.cc
File runtime/vm/parser.cc (right):

https://chromiumcodereview.appspot.com/9664062/diff/1/runtime/vm/parser.cc#ne...
runtime/vm/parser.cc:147: local_count_ = first_local_index_ -
next_free_frame_index;
On 2012/03/12 22:55:49, srdjan wrote:
> + copied_parameter_count_;

Consistent terminology will help.

Maybe the name is too generic, but this is intended to *not* include the copied
parameter count (which is actually a property independent of variable
allocation, and) which is already counted in the field copied_parameter_count_. 
I want the name "local" to mean the same thing in "first_local_index_" and
"local_count_".

I don't know what would be a better name.  stack_local_count_ is more accurate,
but still not obvious.

This field is used in two ways: once to decide how much space to reserve in the
frame (where we need to include copied parameter count, and the code currently
adds the two quantities at the use site), and once when we need to initialize
only the local variables (ignoring copied parameters and starting from
first_local_index_).

In any case, we either need to add copied parameters (to get total) at one of
the use sites, or else subtract (to get just local variables) at the other use
site.  Or add another, redundant, field (or accessor), but I really don't like
that.

Powered by Google App Engine
This is Rietveld 408576698