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

Side by Side Diff: pkg/compiler/lib/src/js_model/closure.dart

Issue 2995113002: Share locals between members (Closed)
Patch Set: Rebased Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_model/locals.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/tasks.dart'; 9 import '../common/tasks.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ir.FunctionNode node, 136 ir.FunctionNode node,
137 KernelScopeInfo info, 137 KernelScopeInfo info,
138 JsClosedWorld closedWorldRefiner) { 138 JsClosedWorld closedWorldRefiner) {
139 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(member); 139 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(member);
140 KernelClosureClass closureClass = closedWorldRefiner.buildClosureClass( 140 KernelClosureClass closureClass = closedWorldRefiner.buildClosureClass(
141 member, node, member.library, info, node.location, localsMap); 141 member, node, member.library, info, node.location, localsMap);
142 142
143 // We want the original declaration where that function is used to point 143 // We want the original declaration where that function is used to point
144 // to the correct closure class. 144 // to the correct closure class.
145 _memberClosureRepresentationMap[closureClass.callMethod] = closureClass; 145 _memberClosureRepresentationMap[closureClass.callMethod] = closureClass;
146 _globalLocalsMap.setLocalsMap(closureClass.callMethod, localsMap);
146 if (node.parent is ir.Member) { 147 if (node.parent is ir.Member) {
147 assert(_elementMap.getMember(node.parent) == member); 148 assert(_elementMap.getMember(node.parent) == member);
148 _memberClosureRepresentationMap[member] = closureClass; 149 _memberClosureRepresentationMap[member] = closureClass;
149 } else { 150 } else {
150 assert(node.parent is ir.FunctionExpression || 151 assert(node.parent is ir.FunctionExpression ||
151 node.parent is ir.FunctionDeclaration); 152 node.parent is ir.FunctionDeclaration);
152 _localClosureRepresentationMap[node.parent] = closureClass; 153 _localClosureRepresentationMap[node.parent] = closureClass;
153 } 154 }
154 return closureClass; 155 return closureClass;
155 } 156 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 /// A local variable to disambiguate between a variable that has been captured 419 /// A local variable to disambiguate between a variable that has been captured
419 /// from one scope to another. This is the ir.Node version that corresponds to 420 /// from one scope to another. This is the ir.Node version that corresponds to
420 /// [BoxLocal]. 421 /// [BoxLocal].
421 class NodeBox { 422 class NodeBox {
422 final String name; 423 final String name;
423 final ir.TreeNode executableContext; 424 final ir.TreeNode executableContext;
424 NodeBox(this.name, this.executableContext); 425 NodeBox(this.name, this.executableContext);
425 } 426 }
426 427
427 class JClosureClass extends JClass { 428 class JClosureClass extends JClass {
428 // TODO(efortuna): Storing this map here is so horrible. Instead store this on 429 JClosureClass(JLibrary library, int classIndex, String name)
429 // the ScopeModel (because all of the closures share that localsMap) and then
430 // set populate the getLocalVariable lookup with this localsMap for all the
431 // closures.
432 final KernelToLocalsMap localsMap;
433
434 JClosureClass(this.localsMap, JLibrary library, int classIndex, String name)
435 : super(library, classIndex, name, isAbstract: false); 430 : super(library, classIndex, name, isAbstract: false);
436 431
437 @override 432 @override
438 bool get isClosure => true; 433 bool get isClosure => true;
439 434
440 String toString() => '${jsElementPrefix}closure_class($name)'; 435 String toString() => '${jsElementPrefix}closure_class($name)';
441 } 436 }
442 437
443 class JClosureField extends JField { 438 class JClosureField extends JField {
444 JClosureField(String name, int memberIndex, 439 JClosureField(String name, int memberIndex,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 KernelScopeInfo scopeInfo; 565 KernelScopeInfo scopeInfo;
571 566
572 /// Collected [CapturedScope] data for nodes. 567 /// Collected [CapturedScope] data for nodes.
573 Map<ir.Node, KernelCapturedScope> capturedScopesMap = 568 Map<ir.Node, KernelCapturedScope> capturedScopesMap =
574 <ir.Node, KernelCapturedScope>{}; 569 <ir.Node, KernelCapturedScope>{};
575 570
576 /// Collected [ScopeInfo] data for nodes. 571 /// Collected [ScopeInfo] data for nodes.
577 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = 572 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate =
578 <ir.FunctionNode, KernelScopeInfo>{}; 573 <ir.FunctionNode, KernelScopeInfo>{};
579 } 574 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_model/locals.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698