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

Side by Side Diff: pkg/compiler/lib/src/universe/world_impact.dart

Issue 1435853002: Register closures using StaticUse. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment Created 5 years, 1 month 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 | « pkg/compiler/lib/src/universe/use.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.universe.world_impact; 5 library dart2js.universe.world_impact;
6 6
7 import '../dart_types.dart' show 7 import '../dart_types.dart' show
8 DartType, 8 DartType,
9 InterfaceType; 9 InterfaceType;
10 import '../elements/elements.dart' show 10 import '../elements/elements.dart' show
(...skipping 16 matching lines...) Expand all
27 27
28 Iterable<StaticUse> get staticUses => const <StaticUse>[]; 28 Iterable<StaticUse> get staticUses => const <StaticUse>[];
29 29
30 // TODO(johnniwinther): Replace this by called constructors with type 30 // TODO(johnniwinther): Replace this by called constructors with type
31 // arguments. 31 // arguments.
32 // TODO(johnniwinther): Collect all checked types for checked mode separately 32 // TODO(johnniwinther): Collect all checked types for checked mode separately
33 // to support serialization. 33 // to support serialization.
34 34
35 Iterable<TypeUse> get typeUses => const <TypeUse>[]; 35 Iterable<TypeUse> get typeUses => const <TypeUse>[];
36 36
37 Iterable<LocalFunctionElement> get closures => const <LocalFunctionElement>[];
38
39 String toString() => dump(this); 37 String toString() => dump(this);
40 38
41 static String dump(WorldImpact worldImpact) { 39 static String dump(WorldImpact worldImpact) {
42 StringBuffer sb = new StringBuffer(); 40 StringBuffer sb = new StringBuffer();
43 printOn(sb, worldImpact); 41 printOn(sb, worldImpact);
44 return sb.toString(); 42 return sb.toString();
45 } 43 }
46 44
47 static void printOn(StringBuffer sb, WorldImpact worldImpact) { 45 static void printOn(StringBuffer sb, WorldImpact worldImpact) {
48 void add(String title, Iterable iterable) { 46 void add(String title, Iterable iterable) {
49 if (iterable.isNotEmpty) { 47 if (iterable.isNotEmpty) {
50 sb.write('\n $title:'); 48 sb.write('\n $title:');
51 iterable.forEach((e) => sb.write('\n $e')); 49 iterable.forEach((e) => sb.write('\n $e'));
52 } 50 }
53 } 51 }
54 52
55 add('dynamic uses', worldImpact.dynamicUses); 53 add('dynamic uses', worldImpact.dynamicUses);
56 add('static uses', worldImpact.staticUses); 54 add('static uses', worldImpact.staticUses);
57 add('type uses', worldImpact.typeUses); 55 add('type uses', worldImpact.typeUses);
58 add('closures', worldImpact.closures);
59 } 56 }
60 } 57 }
61 58
62 class WorldImpactBuilder { 59 class WorldImpactBuilder {
63 // TODO(johnniwinther): Do we benefit from lazy initialization of the 60 // TODO(johnniwinther): Do we benefit from lazy initialization of the
64 // [Setlet]s? 61 // [Setlet]s?
65 Setlet<DynamicUse> _dynamicUses; 62 Setlet<DynamicUse> _dynamicUses;
66 Setlet<StaticUse> _staticUses; 63 Setlet<StaticUse> _staticUses;
67 Setlet<TypeUse> _typeUses; 64 Setlet<TypeUse> _typeUses;
68 Setlet<LocalFunctionElement> _closures; 65 Setlet<LocalFunctionElement> _closures;
(...skipping 28 matching lines...) Expand all
97 assert(staticUse != null); 94 assert(staticUse != null);
98 if (_staticUses == null) { 95 if (_staticUses == null) {
99 _staticUses = new Setlet<StaticUse>(); 96 _staticUses = new Setlet<StaticUse>();
100 } 97 }
101 _staticUses.add(staticUse); 98 _staticUses.add(staticUse);
102 } 99 }
103 100
104 Iterable<StaticUse> get staticUses { 101 Iterable<StaticUse> get staticUses {
105 return _staticUses != null ? _staticUses : const <StaticUse>[]; 102 return _staticUses != null ? _staticUses : const <StaticUse>[];
106 } 103 }
107
108 void registerClosure(LocalFunctionElement element) {
109 if (_closures == null) {
110 _closures = new Setlet<LocalFunctionElement>();
111 }
112 _closures.add(element);
113 }
114
115 Iterable<LocalFunctionElement> get closures {
116 return _closures != null
117 ? _closures : const <LocalFunctionElement>[];
118 }
119 } 104 }
120 105
121 /// Mutable implementation of [WorldImpact] used to transform 106 /// Mutable implementation of [WorldImpact] used to transform
122 /// [ResolutionImpact] or [CodegenImpact] to [WorldImpact]. 107 /// [ResolutionImpact] or [CodegenImpact] to [WorldImpact].
123 class TransformedWorldImpact implements WorldImpact { 108 class TransformedWorldImpact implements WorldImpact {
124 final WorldImpact worldImpact; 109 final WorldImpact worldImpact;
125 110
126 Setlet<StaticUse> _staticUses; 111 Setlet<StaticUse> _staticUses;
127 Setlet<TypeUse> _typeUses; 112 Setlet<TypeUse> _typeUses;
128 Setlet<DynamicUse> _dynamicUses; 113 Setlet<DynamicUse> _dynamicUses;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 _staticUses.addAll(worldImpact.staticUses); 148 _staticUses.addAll(worldImpact.staticUses);
164 } 149 }
165 _staticUses.add(staticUse); 150 _staticUses.add(staticUse);
166 } 151 }
167 152
168 @override 153 @override
169 Iterable<StaticUse> get staticUses { 154 Iterable<StaticUse> get staticUses {
170 return _staticUses != null ? _staticUses : worldImpact.staticUses; 155 return _staticUses != null ? _staticUses : worldImpact.staticUses;
171 } 156 }
172 157
173 @override
174 Iterable<LocalFunctionElement> get closures => worldImpact.closures;
175
176 String toString() { 158 String toString() {
177 StringBuffer sb = new StringBuffer(); 159 StringBuffer sb = new StringBuffer();
178 sb.write('TransformedWorldImpact($worldImpact)'); 160 sb.write('TransformedWorldImpact($worldImpact)');
179 WorldImpact.printOn(sb, this); 161 WorldImpact.printOn(sb, this);
180 return sb.toString(); 162 return sb.toString();
181 } 163 }
182 } 164 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/use.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698