Skip to content

Commit

Permalink
Revert "Fix closure conversion in field and local initializers."
Browse files Browse the repository at this point in the history
This reverts commit a49dcb6.

Review-Url: https://codereview.chromium.org/2974673002 .
  • Loading branch information
sjindel-google committed Jul 7, 2017
1 parent 73ec7f0 commit a7d1837
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 92 deletions.
17 changes: 10 additions & 7 deletions pkg/kernel/lib/transformations/closure/rewriter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ abstract class InitializerRewriter extends AstRewriter {
@override
void insertContextDeclaration(Expression accessParent) {
_createDeclaration();
var oldParent = initializingExpression.parent;
Let binding = new Let(contextDeclaration, initializingExpression);
binding.parent = oldParent;
setInitializerExpression(binding);
initializingExpression.parent = binding;
}

@override
Expand All @@ -125,19 +124,23 @@ class FieldInitializerRewriter extends InitializerRewriter {
}

void setInitializerExpression(Expression expression) {
expression.parent.value = expression;
assert(initializingExpression.parent is FieldInitializer);
FieldInitializer parent = initializingExpression.parent;
parent.value = expression;
expression.parent = parent;
}
}

class LocalInitializerRewriter extends InitializerRewriter {
LocalInitializerRewriter(Expression initializingExpression)
: super(initializingExpression) {
// The initializer is up two levels because the variable declaration node is
// in between.
assert(initializingExpression.parent.parent is LocalInitializer);
assert(initializingExpression.parent is LocalInitializer);
}

void setInitializerExpression(Expression expression) {
expression.parent.initializer = expression;
assert(initializingExpression.parent is LocalInitializer);
LocalInitializer parent = initializingExpression.parent;
parent.variable.initializer = expression;
expression.parent = parent;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE.md file.

local_initializers: Crash
35 changes: 0 additions & 35 deletions pkg/kernel/testcases/closures_initializers/initializers.dart

This file was deleted.

This file was deleted.

23 changes: 23 additions & 0 deletions pkg/kernel/testcases/closures_initializers/local_initializers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// The purpose of this test is to detect that closures in [LocalInitializer]s
// are properly converted. This test assumes that
// [ArgumentExtractionForRedirecting] transformer was run before closure
// conversion. It should introduce one [LocalInitializer] for each argument
// passed to the redirecting constructor. If such argument contains a closure,
// it would appear in a [LocalInitializer].

class X {}

class A {
X foo;
A.named(X foo) {}
A(X foo) : this.named((() => foo)());
}

main() {
A a = new A(new X());
a.foo; // To prevent dartanalyzer from marking [a] as unused.
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,16 @@ class X extends core::Object {
;
}
class A extends core::Object {
field self::X foo;
constructor •(self::X i) → void
: self::A::foo = let final Vector #context = MakeVector(2) in let dynamic #t1 = #context[1] = i in (MakeClosure<() → dynamic>(self::closure#A#function#function, #context)).call(), super core::Object::•()
;
}
class B extends core::Object {
field self::X foo = null;
constructor named(self::X foo) → void
: super core::Object::•() {}
constructor •(self::X foo) → void
: dynamic extracted#0 = let final Vector #context = MakeVector(2) in let dynamic #t2 = #context[1] = foo in (MakeClosure<() → dynamic>(self::closure#B#function#function, #context)).call(), this self::B::named(extracted#0)
: dynamic extracted#0 = () → self::X
throw "Calling unconverted closure at pkg/kernel/testcases/closures_initializers/local_initializers.dart:17:26";
.call(), this self::A::named(extracted#0)
;
}
static method main() → dynamic {
self::A a = new self::A::•(new self::X::•());
a.foo;
self::B b = new self::B::•(new self::X::•());
b.foo;
}
static method closure#A#function#function(Vector #contextParameter) → dynamic {
return #contextParameter[1];
}
static method closure#B#function#function(Vector #contextParameter) → dynamic {
return #contextParameter[1];
}

0 comments on commit a7d1837

Please sign in to comment.