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

Unified Diff: pkg/compiler/lib/src/js_model/closure_visitors.dart

Issue 2981723002: Distinguish between actual closure scopes and non-closure scopes. (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_model/closure_visitors.dart
diff --git a/pkg/compiler/lib/src/js_model/closure_visitors.dart b/pkg/compiler/lib/src/js_model/closure_visitors.dart
index 1dcb29f8de16034239276ab4e1abeaba32bf6eaa..1485735b5dc7e4ebb43d0ea76b4cfc69f84e82e7 100644
--- a/pkg/compiler/lib/src/js_model/closure_visitors.dart
+++ b/pkg/compiler/lib/src/js_model/closure_visitors.dart
@@ -19,6 +19,14 @@ class ClosureScopeBuilder extends ir.Visitor {
/// [translateLazyIntializer] or [translateConstructorOrProcedure]).
Map<ir.Node, ClosureScope> _closureInfoMap = <ir.Node, ClosureScope>{};
+ /// Map entities to their corresponding scope information (such as what
+ /// variables are captured/used). The distinction between this map and
+ /// [_closureInfoMap] is that [_closureInfoMap] stores this data for closures
+ /// specifically, whereas [_scopeInfoMap] stores this information for entities
+ /// that are *not* closures (this information is used by the locals handler).
+ /// The union of these two maps represents all the scopes encountered.
+ Map<Entity, ScopeInfo> _scopeInfoMap = <Entity, ScopeInfo>{};
sra1 2017/07/12 23:57:41 final, don't initialize.
Emily Fortuna 2017/07/13 21:03:39 Done.
+
/// A map of the nodes that we have flagged as necessary to generate closure
/// classes for in a later stage. We map that node to information ascertained
/// about variable usage in the surrounding scope.
@@ -61,8 +69,8 @@ class ClosureScopeBuilder extends ir.Visitor {
final KernelToElementMap _kernelToElementMap;
- ClosureScopeBuilder(this._closureInfoMap, this._closuresToGenerate,
- this._localsMap, this._kernelToElementMap);
+ ClosureScopeBuilder(this._closureInfoMap, this._scopeInfoMap,
+ this._closuresToGenerate, this._localsMap, this._kernelToElementMap);
/// Update the [ClosureScope] object corresponding to
/// this node if any variables are captured.
@@ -212,11 +220,20 @@ class ClosureScopeBuilder extends ir.Visitor {
// field, constructor, or method that is being analyzed.
_isInsideClosure = _outermostNode != null;
_executableContext = node;
- if (!_isInsideClosure) {
+ _currentScopeInfo = new KernelScopeInfo(_nodeToThisLocal(node));
+ if (_isInsideClosure) {
+ _closuresToGenerate[node] = _currentScopeInfo;
+ } else {
_outermostNode = node;
+ Entity entity;
+ ir.TreeNode tempNode = node;
+ if (tempNode is ir.Member) {
+ entity = _kernelToElementMap.getMember(tempNode);
Johnni Winther 2017/07/13 08:56:14 Maybe the visitor should have the member entity as
Emily Fortuna 2017/07/13 21:03:39 done.
+ } else {
+ entity = _kernelToElementMap.getLocalFunction(tempNode);
Johnni Winther 2017/07/13 08:56:14 Can this ever happen? We always start visiting on
Emily Fortuna 2017/07/13 21:03:39 You're right it won't. Took it out.
+ }
+ _scopeInfoMap[entity] = _currentScopeInfo;
}
- _currentScopeInfo = new KernelScopeInfo(_nodeToThisLocal(node));
- _closuresToGenerate[node] = _currentScopeInfo;
enterNewScope(node, () {
node.visitChildren(this);

Powered by Google App Engine
This is Rietveld 408576698