Chromium Code Reviews| Index: pkg/compiler/lib/src/closure.dart |
| diff --git a/pkg/compiler/lib/src/closure.dart b/pkg/compiler/lib/src/closure.dart |
| index bcbd8365b2020fccab714cd3a4ab5f55ac8af05a..10dfc4e46988c25093ca2a6291098eeea05845a9 100644 |
| --- a/pkg/compiler/lib/src/closure.dart |
| +++ b/pkg/compiler/lib/src/closure.dart |
| @@ -88,6 +88,8 @@ class ScopeInfo { |
| /// we rewrite sync* functions. See also comments in |
| /// [ClosureClassMap.useLocal]. |
| bool localIsUsedInTryOrSync(Local variable) => false; |
| + |
| + String toString() => 'ScopeInfo()'; |
| } |
| /// Class representing the usage of a scope that has been captured in the |
| @@ -110,18 +112,19 @@ class CapturedScope extends ScopeInfo { |
| /// True if [variable] has been mutated and is also used in another scope. |
| bool isBoxed(Local variable) => false; |
| - /// If true, this closure accesses a variable that was defined in an outside |
| - /// scope and this variable gets modified at some point (sometimes we say that |
| - /// variable has been "captured"). In this situation, access to this variable |
| - /// is controlled via a wrapper (box) so that updates to this variable |
| - /// are done in a way that is in line with Dart's closure rules. |
| - bool get requiresContextBox => false; |
| - |
| - /// Accessor to the local environment in which a particular closure node is |
| - /// executed. This will encapsulate the value of any variables that have been |
| - /// scoped into this context from outside. This is an accessor to the |
| - /// contextBox that [requiresContextBox] is testing is required. |
| - Local get context => null; |
| + /// If `true` this scope requires a `box`. A box is a JavaScript object that |
| + /// holds all mutated variables declared in this scope that are accessed in |
| + /// another scope. |
| + bool get hasBox => false; |
|
Emily Fortuna
2017/08/22 23:47:36
this naming of "context" was suggested by Siggi to
Johnni Winther
2017/08/23 07:47:17
[context] _is_ the box, i.e. the JS object that ho
|
| + |
| + /// Accessor to the box created for this scope. If [hasBox] is `false`, |
| + /// `null` is returned. |
| + /// |
| + /// The box is a JavaScript object that holds all mutated variables declared |
| + /// in this scope that are accessed in another scope. |
| + Local get box => null; |
| + |
| + String toString() => 'CapturedScope()'; |
| } |
| /// Class that describes the actual mechanics of how values of variables |
| @@ -162,6 +165,8 @@ class CapturedLoopScope extends CapturedScope { |
| /// `i` would be a part of the boxedLoopVariables AND boxedVariables, but b |
| /// would only be a part of boxedVariables. |
| List<Local> get boxedLoopVariables => const <Local>[]; |
| + |
| + String toString() => 'CapturedLoopScope()'; |
| } |
| /// Class that describes the actual mechanics of how the converted, rewritten |
| @@ -225,6 +230,8 @@ class ClosureRepresentationInfo extends ScopeInfo { |
| /// closure) and all variables captured in nested scopes that we may be |
| /// capturing as well. These nested scopes hold "boxes" to hold the executable |
| /// context for that scope. |
| + // TODO(johnniwinther,efortuna): Remove the need for this. It is now only |
| + // used in inference. |
| void forEachCapturedVariable(f(Local from, FieldEntity to)) {} |
| /// Loop through each variable that has been boxed in this closure class. Only |
| @@ -234,6 +241,8 @@ class ClosureRepresentationInfo extends ScopeInfo { |
| /// includes looping over variables that were boxed from other scopes, not |
| /// strictly variables defined in this closure, unlike the behavior in |
| /// the superclass ScopeInfo. |
| + // TODO(johnniwinther,efortuna): Remove the need for this. It is now only |
| + // used in inference. |
| void forEachBoxedVariable(f(Local local, FieldEntity field)) {} |
| /// Loop through each free variable in this closure. Free variables are the |
| @@ -243,6 +252,8 @@ class ClosureRepresentationInfo extends ScopeInfo { |
| /// Return true if [variable] has been captured and mutated (all other |
| /// variables do not require boxing). |
| + // TODO(johnniwinther,efortuna): Remove the need for this. It is now only |
| + // used in inference. |
| bool isVariableBoxed(Local variable) => false; |
| // TODO(efortuna): Remove this method. The old system was using |
| @@ -278,8 +289,9 @@ class ClosureTask extends ClosureConversionTask<Node> { |
| CapturedScope getCapturedScope(covariant MemberElement member) { |
| ResolvedAst resolvedAst = member.resolvedAst; |
| - if (resolvedAst.kind != ResolvedAstKind.PARSED) |
| + if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
| return const CapturedScope(); |
| + } |
| return _getCapturedScope(resolvedAst.node); |
| } |
| @@ -689,9 +701,9 @@ class CapturedScopeImpl implements CapturedScope, CapturedLoopScope { |
| CapturedScopeImpl(this.boxElement, this.capturedVariables); |
| - Local get context => boxElement; |
| + Local get box => boxElement; |
| - bool get requiresContextBox => capturedVariables.keys.isNotEmpty; |
| + bool get hasBox => boxElement != null; |
| void forEachBoxedVariable(f(Local local, FieldEntity field)) { |
| capturedVariables.forEach(f); |