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

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

Issue 2938203003: Compute KernelClosureRepresentationInfo.variableIsUsedInTryOrSync (Closed)
Patch Set: Remove test line Created 3 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:kernel/ast.dart' as ir;
6
7 import '../closure.dart';
8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart';
11 import '../common_elements.dart';
12 import '../compiler.dart';
13 import '../constants/values.dart'
14 show
15 ConstantValue,
16 InterceptorConstantValue,
17 StringConstantValue,
18 TypeConstantValue;
19 import '../elements/elements.dart';
20 import '../elements/entities.dart';
21 import '../elements/jumps.dart';
22 import '../elements/resolution_types.dart';
23 import '../elements/types.dart';
24 import '../io/source_information.dart';
25 import '../js/js.dart' as js;
26 import '../js_backend/backend.dart' show JavaScriptBackend;
27 import '../kernel/closure.dart';
28 import '../native/native.dart' as native;
29 import '../resolution/tree_elements.dart';
30 import '../tree/nodes.dart' show Node;
31 import '../types/masks.dart';
32 import '../universe/selector.dart';
33 import '../universe/side_effects.dart' show SideEffects;
34 import '../universe/use.dart' show DynamicUse;
35 import '../universe/world_builder.dart' show CodegenWorldBuilder;
36 import '../world.dart';
37 import 'element_map.dart';
38 import 'element_map_impl.dart';
39
40 class KernelClosureDataBuilder extends ir.Visitor {
41 final KernelToLocalsMap _localsMap;
42 final KernelClosureRepresentationInfo info;
43
44 bool _inTry = false;
45
46 KernelClosureDataBuilder(this._localsMap, ThisLocal thisLocal)
47 : info = new KernelClosureRepresentationInfo(thisLocal);
48
49 @override
50 defaultNode(ir.Node node) {
51 node.visitChildren(this);
52 }
53
54 @override
55 visitTryCatch(ir.TryCatch node) {
56 bool oldInTry = _inTry;
57 _inTry = true;
58 node.visitChildren(this);
59 _inTry = oldInTry;
60 }
61
62 @override
63 visitTryFinally(ir.TryFinally node) {
64 bool oldInTry = _inTry;
65 _inTry = true;
66 node.visitChildren(this);
67 _inTry = oldInTry;
68 }
69
Emily Fortuna 2017/06/15 22:54:28 add @override?
Johnni Winther 2017/06/16 13:40:07 Done.
70 visitVariableGet(ir.VariableGet node) {
71 if (_inTry) {
72 info.registerUsedInTryOrSync(_localsMap.getLocal(node.variable));
73 }
74 }
75 }
76
77 class KernelClosureDataLookup implements ClosureDataLookup<ir.Node> {
78 final KernelToElementMapImpl _elementMap;
79 final KernelToLocalsMap _localsMap;
80 Map<Entity, ClosureRepresentationInfo> _infoMap =
81 <Entity, ClosureRepresentationInfo>{};
82
83 KernelClosureDataLookup(this._elementMap, this._localsMap);
84
85 /// TODO(johnniwinther,efortuna): Implement this.
86 @override
87 ClosureAnalysisInfo getClosureAnalysisInfo(ir.Node node) {
88 return const ClosureAnalysisInfo();
89 }
90
91 /// TODO(johnniwinther,efortuna): Implement this.
92 @override
93 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(
94 ir.Node loopNode) {
95 return const LoopClosureRepresentationInfo();
96 }
97
98 @override
99 ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) {
100 return _infoMap.putIfAbsent(entity, () {
101 if (entity is MemberEntity) {
102 ir.Member node = _elementMap.getMemberNode(entity);
103 ThisLocal thisLocal;
104 if (entity.isInstanceMember) {
105 thisLocal = new ThisLocal(entity);
106 }
107 KernelClosureDataBuilder builder =
108 new KernelClosureDataBuilder(_localsMap, thisLocal);
109 node.accept(builder);
110 return builder.info;
111 }
112
113 /// TODO(johnniwinther,efortuna): Implement this.
114 return const ClosureRepresentationInfo();
115 });
116 }
117 }
118
119 // TODO(johnniwinther): Add unittest for the computed
120 // [ClosureRepresentationInfo].
121 class KernelClosureRepresentationInfo extends ClosureRepresentationInfo {
122 final ThisLocal thisLocal;
123 final Set<Local> _localsUsedInTryOrSync = new Set<Local>();
124
125 KernelClosureRepresentationInfo(this.thisLocal);
126
127 void registerUsedInTryOrSync(Local local) {
128 _localsUsedInTryOrSync.add(local);
129 }
130
131 bool variableIsUsedInTryOrSync(Local variable) =>
132 _localsUsedInTryOrSync.contains(variable);
133 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart » ('j') | pkg/compiler/lib/src/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698