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

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

Issue 2938203003: Compute KernelClosureRepresentationInfo.variableIsUsedInTryOrSync (Closed)
Patch Set: Rebased 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
70 @override
71 visitVariableGet(ir.VariableGet node) {
72 if (_inTry) {
73 info.registerUsedInTryOrSync(_localsMap.getLocal(node.variable));
74 }
75 }
76 }
77
78 /// TODO(johnniwinther,efortuna): Merge this with [KernelClosureConversionTask].
79 class KernelClosureDataLookup implements ClosureDataLookup<ir.Node> {
80 final KernelToElementMapImpl _elementMap;
81 final KernelToLocalsMap _localsMap;
82 Map<Entity, ClosureRepresentationInfo> _infoMap =
83 <Entity, ClosureRepresentationInfo>{};
84
85 KernelClosureDataLookup(this._elementMap, this._localsMap);
86
87 /// TODO(johnniwinther,efortuna): Implement this.
88 @override
89 ClosureAnalysisInfo getClosureAnalysisInfo(ir.Node node) {
90 return const ClosureAnalysisInfo();
91 }
92
93 /// TODO(johnniwinther,efortuna): Implement this.
94 @override
95 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(
96 ir.Node loopNode) {
97 return const LoopClosureRepresentationInfo();
98 }
99
100 @override
101 ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) {
102 return _infoMap.putIfAbsent(entity, () {
103 if (entity is MemberEntity) {
104 ir.Member node = _elementMap.getMemberNode(entity);
105 ThisLocal thisLocal;
106 if (entity.isInstanceMember) {
107 thisLocal = new ThisLocal(entity);
108 }
109 KernelClosureDataBuilder builder =
110 new KernelClosureDataBuilder(_localsMap, thisLocal);
111 node.accept(builder);
112 return builder.info;
113 }
114
115 /// TODO(johnniwinther,efortuna): Implement this.
116 return const ClosureRepresentationInfo();
117 });
118 }
119 }
120
121 // TODO(johnniwinther): Add unittest for the computed
122 // [ClosureRepresentationInfo].
123 class KernelClosureRepresentationInfo extends ClosureRepresentationInfo {
124 final ThisLocal thisLocal;
125 final Set<Local> _localsUsedInTryOrSync = new Set<Local>();
126
127 KernelClosureRepresentationInfo(this.thisLocal);
128
129 void registerUsedInTryOrSync(Local local) {
130 _localsUsedInTryOrSync.add(local);
131 }
132
133 bool variableIsUsedInTryOrSync(Local variable) =>
134 _localsUsedInTryOrSync.contains(variable);
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698