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

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

Issue 1464773002: Remove WorldImpact from caches when no longer needed. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Make deferred uncaching global. Created 5 years 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/js_backend/js_backend.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 void apply(WorldImpactVisitor visitor) {
38 staticUses.forEach(visitor.visitStaticUse);
39 dynamicUses.forEach(visitor.visitDynamicUse);
40 typeUses.forEach(visitor.visitTypeUse);
41 }
42
37 String toString() => dump(this); 43 String toString() => dump(this);
38 44
39 static String dump(WorldImpact worldImpact) { 45 static String dump(WorldImpact worldImpact) {
40 StringBuffer sb = new StringBuffer(); 46 StringBuffer sb = new StringBuffer();
41 printOn(sb, worldImpact); 47 printOn(sb, worldImpact);
42 return sb.toString(); 48 return sb.toString();
43 } 49 }
44 50
45 static void printOn(StringBuffer sb, WorldImpact worldImpact) { 51 static void printOn(StringBuffer sb, WorldImpact worldImpact) {
46 void add(String title, Iterable iterable) { 52 void add(String title, Iterable iterable) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 _staticUses.addAll(worldImpact.staticUses); 153 _staticUses.addAll(worldImpact.staticUses);
148 } 154 }
149 _staticUses.add(staticUse); 155 _staticUses.add(staticUse);
150 } 156 }
151 157
152 @override 158 @override
153 Iterable<StaticUse> get staticUses { 159 Iterable<StaticUse> get staticUses {
154 return _staticUses != null ? _staticUses : worldImpact.staticUses; 160 return _staticUses != null ? _staticUses : worldImpact.staticUses;
155 } 161 }
156 162
163 void apply(WorldImpactVisitor visitor) {
164 staticUses.forEach(visitor.visitStaticUse);
165 dynamicUses.forEach(visitor.visitDynamicUse);
166 typeUses.forEach(visitor.visitTypeUse);
167 }
168
157 String toString() { 169 String toString() {
158 StringBuffer sb = new StringBuffer(); 170 StringBuffer sb = new StringBuffer();
159 sb.write('TransformedWorldImpact($worldImpact)'); 171 sb.write('TransformedWorldImpact($worldImpact)');
160 WorldImpact.printOn(sb, this); 172 WorldImpact.printOn(sb, this);
161 return sb.toString(); 173 return sb.toString();
162 } 174 }
163 } 175 }
176
177 /// Constant used to denote a specific use of a [WorldImpact].
178 class ImpactUseCase {
179 final String name;
180
181 const ImpactUseCase(this.name);
182
183 String toString() => 'ImpactUseCase($name)';
184 }
185
186 /// Strategy used for processing [WorldImpact] object in various use cases.
187 class ImpactStrategy {
188 const ImpactStrategy();
189
190 /// Applies [impact] to [visitor] for the [impactUseCase] of [element].
191 void visitImpact(Element element,
192 WorldImpact impact,
193 WorldImpactVisitor visitor,
194 ImpactUseCase impactUseCase) {
195 // Apply unconditionally.
196 impact.apply(visitor);
197 }
198
199 /// Notifies the strategy that no more impacts of [impactUseCase] will be
200 /// applied.
201 void onImpactUsed(ImpactUseCase impactUseCase) {
202 // Do nothing.
203 }
204 }
205
206 /// Visitor used to process the uses of a [WorldImpact].
207 abstract class WorldImpactVisitor {
208 void visitStaticUse(StaticUse staticUse);
209 void visitDynamicUse(DynamicUse dynamicUse);
210 void visitTypeUse(TypeUse typeUse);
211 }
212
213 // TODO(johnniwinther): Remove these when we get anonymous local classes.
214 typedef void VisitUse<U>(U use);
215
216 class WorldImpactVisitorImpl implements WorldImpactVisitor {
217 final VisitUse<StaticUse> _visitStaticUse;
218 final VisitUse<DynamicUse> _visitDynamicUse;
219 final VisitUse<TypeUse> _visitTypeUse;
220
221 WorldImpactVisitorImpl(
222 {VisitUse<StaticUse> visitStaticUse,
223 VisitUse<DynamicUse> visitDynamicUse,
224 VisitUse<TypeUse> visitTypeUse})
225 : _visitStaticUse = visitStaticUse,
226 _visitDynamicUse = visitDynamicUse,
227 _visitTypeUse = visitTypeUse;
228
229 @override
230 void visitStaticUse(StaticUse use) {
231 if (_visitStaticUse != null) {
232 _visitStaticUse(use);
233 }
234 }
235
236 @override
237 void visitDynamicUse(DynamicUse use) {
238 if (_visitDynamicUse != null) {
239 _visitDynamicUse(use);
240 }
241 }
242
243 @override
244 void visitTypeUse(TypeUse use) {
245 if (_visitTypeUse != null) {
246 _visitTypeUse(use);
247 }
248 }
249 }
250
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698