f0941f7c7d
Summary: Previously, we would create a wrapper function in the flowgraph around converted closures, which would forward all the closure's arguments and unpack the context argument before calling the real closure function. Now, we perform the unpacking at the top of the real function to avoid having any wrapper function. Previously, captured parameters would still be appear live to the GC even if they're updated, because after they are copied into the context, all updates to them are done there. Now, as in regular closures, we zero-out the parameter variable after copying it's value into the context, avoiding potential memory leaks. Test Plan: Ran the closure conversion test suite. Ran benchmarks on Golem -- all statistically significant regressions are gone. BUG= R=dmitryas@google.com, regis@google.com Review-Url: https://codereview.chromium.org/3008923002 .
32 lines
933 B
Plaintext
32 lines
933 B
Plaintext
library;
|
|
import self as self;
|
|
import "dart:core" as core;
|
|
|
|
static method doit(core::int x) → void {
|
|
final dynamic #context = MakeVector(3);
|
|
#context[2] = x;
|
|
x = null;
|
|
final core::int max = 10;
|
|
final core::double expectedSum = max.-(1).*(max)./(2);
|
|
core::int counter = 0;
|
|
dynamic calls = <dynamic>[];
|
|
while (counter.<(max)) {
|
|
final dynamic #context = MakeVector(3);
|
|
#context[1] = #context;
|
|
#context[2] = counter;
|
|
calls.add(MakeClosure<() → dynamic>(self::closure#doit#function, #context));
|
|
counter = counter.+(1);
|
|
}
|
|
core::double sum = 0.0;
|
|
for (dynamic c in calls)
|
|
sum = sum.+(c.call());
|
|
if(!sum.==(expectedSum))
|
|
throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}");
|
|
}
|
|
static method main() → void {
|
|
self::doit(0);
|
|
}
|
|
static method closure#doit#function(dynamic #contextParameter) → dynamic {
|
|
return (#contextParameter[2]).+(#contextParameter[1][2]);
|
|
}
|