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 f9e5b33adf91eb26c4c84bafab4cfbb9fb0f9171..260d9fa56a70af481807d18cb63abce09c886b24 100644 |
| --- a/pkg/compiler/lib/src/closure.dart |
| +++ b/pkg/compiler/lib/src/closure.dart |
| @@ -53,10 +53,11 @@ abstract class ClosureDataLookup<T> { |
| /// Look up information about a loop, in case any variables it declares need |
| /// to be boxed/snapshotted. |
| - LoopClosureScope getLoopClosureScope(T loopNode); |
| + LoopScopeInClosure getLoopScopeInClosure(T loopNode); |
| - /// Accessor to the information about closures that the SSA builder will use. |
| - ClosureScope getClosureScope(MemberEntity entity); |
| + /// Accessor to the information about scopes that closures capture. Used by |
| + /// the SSA builder. |
| + ScopeInClosure getScopeInClosure(MemberEntity entity); |
| } |
| /// Class that represents one level of scoping information, whether this scope |
| @@ -105,8 +106,8 @@ class ScopeInfo { |
| /// Class representing the usage of a scope that has been captured in the |
| /// context of a closure. |
| -class ClosureScope extends ScopeInfo { |
| - const ClosureScope(); |
| +class ScopeInClosure extends ScopeInfo { |
|
sra1
2017/07/14 20:57:39
Maybe CapturedScope is a better name?
|
| + const ScopeInClosure(); |
| /// 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 |
| @@ -137,8 +138,8 @@ class ClosureScope extends ScopeInfo { |
| /// the result would be [5, 5, 5, 5, 5]. Because of this difference we need to |
| /// create a closure for these sorts of loops to capture the variable's value at |
| /// each iteration, by boxing the iteration variable[s]. |
| -class LoopClosureScope extends ClosureScope { |
| - const LoopClosureScope(); |
| +class LoopScopeInClosure extends ScopeInClosure { |
| + const LoopScopeInClosure(); |
| /// True if this loop scope declares in the first part of the loop |
| /// `for (<here>;...;...)` any variables that need to be boxed. |
| @@ -251,7 +252,7 @@ class ClosureRepresentationInfo extends ScopeInfo { |
| } |
| class ClosureTask extends ClosureConversionTask<Node> { |
| - Map<Node, ClosureScopeImpl> _closureInfoMap = <Node, ClosureScopeImpl>{}; |
| + Map<Node, ScopeInClosureImpl> _closureInfoMap = <Node, ScopeInClosureImpl>{}; |
| Map<Element, ClosureClassMap> _closureMappingCache = |
| <Element, ClosureClassMap>{}; |
| Compiler compiler; |
| @@ -268,15 +269,16 @@ class ClosureTask extends ClosureConversionTask<Node> { |
| createClosureClasses(closedWorldRefiner); |
| } |
| - ClosureScope _getClosureScope(Node node) { |
| + ScopeInClosure _getScopeInClosure(Node node) { |
| var value = _closureInfoMap[node]; |
| - return value == null ? const ClosureScope() : value; |
| + return value == null ? const ScopeInClosure() : value; |
| } |
| - ClosureScope getClosureScope(covariant MemberElement member) { |
| + ScopeInClosure getScopeInClosure(covariant MemberElement member) { |
| ResolvedAst resolvedAst = member.resolvedAst; |
| - if (resolvedAst.kind != ResolvedAstKind.PARSED) return const ClosureScope(); |
| - return _getClosureScope(resolvedAst.node); |
| + if (resolvedAst.kind != ResolvedAstKind.PARSED) |
| + return const ScopeInClosure(); |
| + return _getScopeInClosure(resolvedAst.node); |
| } |
| ScopeInfo getScopeInfo(Element member) { |
| @@ -287,9 +289,9 @@ class ClosureTask extends ClosureConversionTask<Node> { |
| return getClosureToClassMapping(member); |
| } |
| - LoopClosureScope getLoopClosureScope(Node loopNode) { |
| + LoopScopeInClosure getLoopScopeInClosure(Node loopNode) { |
| var value = _closureInfoMap[loopNode]; |
| - return value == null ? const LoopClosureScope() : value; |
| + return value == null ? const LoopScopeInClosure() : value; |
| } |
| /// Returns the [ClosureClassMap] computed for [resolvedAst]. |
| @@ -655,7 +657,7 @@ class SynthesizedCallMethodElementX extends BaseFunctionElementX |
| // The box-element for a scope, and the captured variables that need to be |
| // stored in the box. |
| -class ClosureScopeImpl implements ClosureScope, LoopClosureScope { |
| +class ScopeInClosureImpl implements ScopeInClosure, LoopScopeInClosure { |
| final BoxLocal boxElement; |
| final Map<Local, BoxFieldElement> capturedVariables; |
| @@ -664,7 +666,7 @@ class ClosureScopeImpl implements ClosureScope, LoopClosureScope { |
| // Otherwise contains the empty List. |
| List<Local> boxedLoopVariables = const <Local>[]; |
| - ClosureScopeImpl(this.boxElement, this.capturedVariables); |
| + ScopeInClosureImpl(this.boxElement, this.capturedVariables); |
| Local get context => boxElement; |
| @@ -687,16 +689,16 @@ class ClosureScopeImpl implements ClosureScope, LoopClosureScope { |
| // Should not be called. Added to make the new interface happy. |
| bool localIsUsedInTryOrSync(Local variable) => |
| - throw new UnsupportedError("ClosureScopeImpl.localIsUsedInTryOrSync"); |
| + throw new UnsupportedError("ScopeInClosureImpl.localIsUsedInTryOrSync"); |
| // Should not be called. Added to make the new interface happy. |
| Local get thisLocal => |
| - throw new UnsupportedError("ClosureScopeImpl.thisLocal"); |
| + throw new UnsupportedError("ScopeInClosureImpl.thisLocal"); |
| String toString() { |
| String separator = ''; |
| StringBuffer sb = new StringBuffer(); |
| - sb.write('ClosureScopeImpl('); |
| + sb.write('ScopeInClosureImpl('); |
| if (boxElement != null) { |
| sb.write('box=$boxElement'); |
| separator = ','; |
| @@ -740,12 +742,12 @@ class ClosureClassMap implements ClosureRepresentationInfo { |
| /// their locations. |
| final Map<Local, FieldEntity> freeVariableMap = new Map<Local, FieldEntity>(); |
| - /// Maps [Loop] and [FunctionExpression] nodes to their [ClosureScopeImpl] which |
| + /// Maps [Loop] and [FunctionExpression] nodes to their [ScopeInClosureImpl] which |
| /// contains their box and the captured variables that are stored in the box. |
| /// This map will be empty if the method/closure of this [ClosureData] does |
| /// not contain any nested closure. |
| - final Map<Node, ClosureScopeImpl> capturingScopes = |
| - new Map<Node, ClosureScopeImpl>(); |
| + final Map<Node, ScopeInClosureImpl> capturingScopes = |
| + new Map<Node, ScopeInClosureImpl>(); |
| /// Set of [variable]s referenced in this scope that are used inside a |
| /// `try` block or a `sync*` generator (this is important to know because |
| @@ -816,7 +818,7 @@ class ClosureClassMap implements ClosureRepresentationInfo { |
| if (variable is BoxLocal) return; |
| f(variable, copy); |
| }); |
| - capturingScopes.values.forEach((ClosureScopeImpl scope) { |
| + capturingScopes.values.forEach((ScopeInClosureImpl scope) { |
| scope.forEachCapturedVariable(f); |
| }); |
| } |
| @@ -827,7 +829,7 @@ class ClosureClassMap implements ClosureRepresentationInfo { |
| if (!isVariableBoxed(variable)) return; |
| f(variable, copy); |
| }); |
| - capturingScopes.values.forEach((ClosureScopeImpl scope) { |
| + capturingScopes.values.forEach((ScopeInClosureImpl scope) { |
| scope.forEachCapturedVariable(f); |
| }); |
| } |
| @@ -850,7 +852,7 @@ class ClosureTranslator extends Visitor { |
| bool inTryStatement = false; |
| final Map<Element, ClosureClassMap> closureMappingCache; |
| - final Map<Node, ClosureScopeImpl> closureInfo; |
| + final Map<Node, ScopeInClosureImpl> closureInfo; |
| // Map of captured variables. Initially they will map to `null`. If |
| // a variable needs to be boxed then the scope declaring the variable |
| @@ -1261,7 +1263,7 @@ class ClosureTranslator extends Visitor { |
| boxCapturedVariable(variable); |
| } |
| if (!scopeMapping.isEmpty) { |
| - ClosureScopeImpl scope = new ClosureScopeImpl(box, scopeMapping); |
| + ScopeInClosureImpl scope = new ScopeInClosureImpl(box, scopeMapping); |
| closureData.capturingScopes[node] = scope; |
| assert(closureInfo[node] == null); |
| closureInfo[node] = scope; |
| @@ -1326,7 +1328,7 @@ class ClosureTranslator extends Visitor { |
| } |
| } |
| }); |
| - ClosureScopeImpl scopeData = closureData.capturingScopes[node]; |
| + ScopeInClosureImpl scopeData = closureData.capturingScopes[node]; |
| if (scopeData == null) return; |
| scopeData.boxedLoopVariables = boxedLoopVariables; |
| } |