Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 ir.FunctionNode node, | 132 ir.FunctionNode node, |
| 133 KernelScopeInfo info, | 133 KernelScopeInfo info, |
| 134 JsClosedWorld closedWorldRefiner) { | 134 JsClosedWorld closedWorldRefiner) { |
| 135 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(member); | 135 KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(member); |
| 136 KernelClosureClass closureClass = closedWorldRefiner.buildClosureClass( | 136 KernelClosureClass closureClass = closedWorldRefiner.buildClosureClass( |
| 137 member, node, member.library, info, node.location, localsMap); | 137 member, node, member.library, info, node.location, localsMap); |
| 138 | 138 |
| 139 // We want the original declaration where that function is used to point | 139 // We want the original declaration where that function is used to point |
| 140 // to the correct closure class. | 140 // to the correct closure class. |
| 141 _closureRepresentationMap[closureClass.callMethod] = closureClass; | 141 _closureRepresentationMap[closureClass.callMethod] = closureClass; |
| 142 _globalLocalsMap.setLocalsMap(closureClass.callMethod, localsMap); | |
|
Emily Fortuna
2017/08/17 19:01:59
what about grouping the locals map for all the cre
Johnni Winther
2017/08/18 14:59:39
This line means we are sharing the map for all tho
| |
| 142 Entity entity; | 143 Entity entity; |
| 143 if (node.parent is ir.Member) { | 144 if (node.parent is ir.Member) { |
| 144 entity = _elementMap.getMember(node.parent); | 145 entity = _elementMap.getMember(node.parent); |
| 145 } else { | 146 } else { |
| 146 entity = localsMap.getLocalFunction(node.parent); | 147 entity = localsMap.getLocalFunction(node.parent); |
| 147 } | 148 } |
| 148 assert(entity != null); | 149 assert(entity != null); |
| 149 _closureRepresentationMap[entity] = closureClass; | 150 _closureRepresentationMap[entity] = closureClass; |
| 150 return closureClass; | 151 return closureClass; |
| 151 } | 152 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 /// A local variable to disambiguate between a variable that has been captured | 392 /// A local variable to disambiguate between a variable that has been captured |
| 392 /// from one scope to another. This is the ir.Node version that corresponds to | 393 /// from one scope to another. This is the ir.Node version that corresponds to |
| 393 /// [BoxLocal]. | 394 /// [BoxLocal]. |
| 394 class NodeBox { | 395 class NodeBox { |
| 395 final String name; | 396 final String name; |
| 396 final ir.TreeNode executableContext; | 397 final ir.TreeNode executableContext; |
| 397 NodeBox(this.name, this.executableContext); | 398 NodeBox(this.name, this.executableContext); |
| 398 } | 399 } |
| 399 | 400 |
| 400 class JClosureClass extends JClass { | 401 class JClosureClass extends JClass { |
| 401 // TODO(efortuna): Storing this map here is so horrible. Instead store this on | 402 JClosureClass(JLibrary library, int classIndex, String name) |
| 402 // the ScopeModel (because all of the closures share that localsMap) and then | |
| 403 // set populate the getLocalVariable lookup with this localsMap for all the | |
| 404 // closures. | |
| 405 final KernelToLocalsMap localsMap; | |
|
Emily Fortuna
2017/08/17 19:01:59
if we get rid of this field, all JClosureClasses c
Johnni Winther
2017/08/18 14:59:39
It does have a better to `toString` and the right
| |
| 406 | |
| 407 JClosureClass(this.localsMap, JLibrary library, int classIndex, String name) | |
| 408 : super(library, classIndex, name, isAbstract: false); | 403 : super(library, classIndex, name, isAbstract: false); |
| 409 | 404 |
| 410 @override | 405 @override |
| 411 bool get isClosure => true; | 406 bool get isClosure => true; |
| 412 | 407 |
| 413 String toString() => '${jsElementPrefix}closure_class($name)'; | 408 String toString() => '${jsElementPrefix}closure_class($name)'; |
| 414 } | 409 } |
| 415 | 410 |
| 416 class JClosureField extends JField { | 411 class JClosureField extends JField { |
| 417 JClosureField(String name, int memberIndex, | 412 JClosureField(String name, int memberIndex, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 KernelScopeInfo scopeInfo; | 532 KernelScopeInfo scopeInfo; |
| 538 | 533 |
| 539 /// Collected [CapturedScope] data for nodes. | 534 /// Collected [CapturedScope] data for nodes. |
| 540 Map<ir.Node, KernelCapturedScope> capturedScopesMap = | 535 Map<ir.Node, KernelCapturedScope> capturedScopesMap = |
| 541 <ir.Node, KernelCapturedScope>{}; | 536 <ir.Node, KernelCapturedScope>{}; |
| 542 | 537 |
| 543 /// Collected [ScopeInfo] data for nodes. | 538 /// Collected [ScopeInfo] data for nodes. |
| 544 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = | 539 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = |
| 545 <ir.FunctionNode, KernelScopeInfo>{}; | 540 <ir.FunctionNode, KernelScopeInfo>{}; |
| 546 } | 541 } |
| OLD | NEW |