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

Side by Side Diff: pkg/compiler/lib/src/enqueue.dart

Issue 2558013002: Move handling of regular static use from ResolutionEnqueuer to ResolutionWorldBuilderImpl (Closed)
Patch Set: Updated cf. comments. Created 4 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.enqueue; 5 library dart2js.enqueue;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import 'cache_strategy.dart'; 9 import 'cache_strategy.dart';
10 import 'common/backend_api.dart' show Backend; 10 import 'common/backend_api.dart' show Backend;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 applyImpact(backend.registerImplementedClass(cls, forResolution: true)); 264 applyImpact(backend.registerImplementedClass(cls, forResolution: true));
265 } 265 }
266 } 266 }
267 267
268 void processDynamicUse(DynamicUse dynamicUse) { 268 void processDynamicUse(DynamicUse dynamicUse) {
269 task.measure(() { 269 task.measure(() {
270 _universe.registerDynamicUse(dynamicUse, _applyMemberUse); 270 _universe.registerDynamicUse(dynamicUse, _applyMemberUse);
271 }); 271 });
272 } 272 }
273 273
274 /// Callback for applying the use of a [member].
275 void _applyStaticMemberUse(Entity member, EnumSet<MemberUse> useSet) {
276 if (useSet.contains(MemberUse.NORMAL)) {
277 _addToWorkList(member);
278 }
279 if (useSet.contains(MemberUse.CLOSURIZE)) {
280 applyImpact(backend.registerGetOfStaticFunction());
281 }
282 }
283
274 void processStaticUse(StaticUse staticUse) { 284 void processStaticUse(StaticUse staticUse) {
275 Element element = staticUse.element; 285 _universe.registerStaticUse(staticUse, _applyStaticMemberUse);
276 assert(invariant(element, element.isDeclaration, 286 // TODO(johnniwinther): Add `ResolutionWorldBuilder.registerConstructorUse`
277 message: "Element ${element} is not the declaration.")); 287 // for these:
278 _universe.registerStaticUse(staticUse);
279 bool addElement = true;
280 switch (staticUse.kind) { 288 switch (staticUse.kind) {
281 case StaticUseKind.STATIC_TEAR_OFF:
282 applyImpact(backend.registerGetOfStaticFunction());
283 break;
284 case StaticUseKind.FIELD_GET:
285 case StaticUseKind.FIELD_SET:
286 case StaticUseKind.CLOSURE:
287 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and
288 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue.
289 // Also [CLOSURE] contains [LocalFunctionElement] which we cannot
290 // enqueue.
291 LocalFunctionElement closure = staticUse.element;
292 if (closure.type.containsTypeVariables) {
293 _universe.closuresWithFreeTypeVariables.add(closure);
294 }
295 addElement = false;
296 break;
297 case StaticUseKind.SUPER_FIELD_SET:
298 case StaticUseKind.SUPER_TEAR_OFF:
299 case StaticUseKind.GENERAL:
300 case StaticUseKind.DIRECT_USE:
301 break;
302 case StaticUseKind.CONSTRUCTOR_INVOKE: 289 case StaticUseKind.CONSTRUCTOR_INVOKE:
303 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: 290 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE:
304 _registerInstantiatedType(staticUse.type, 291 _registerInstantiatedType(staticUse.type,
305 constructor: staticUse.element, globalDependency: false); 292 constructor: staticUse.element, globalDependency: false);
306 break; 293 break;
307 case StaticUseKind.REDIRECTION: 294 case StaticUseKind.REDIRECTION:
308 _registerInstantiatedType(staticUse.type, 295 _registerInstantiatedType(staticUse.type,
309 constructor: staticUse.element, 296 constructor: staticUse.element,
310 globalDependency: false, 297 globalDependency: false,
311 isRedirection: true); 298 isRedirection: true);
312 break; 299 break;
313 case StaticUseKind.DIRECT_INVOKE: 300 default:
314 invariant(
315 element, 'Direct static use is not supported for resolution.');
316 break; 301 break;
317 } 302 }
318 if (addElement) {
319 _addToWorkList(element);
320 }
321 } 303 }
322 304
323 void processTypeUse(TypeUse typeUse) { 305 void processTypeUse(TypeUse typeUse) {
324 DartType type = typeUse.type; 306 DartType type = typeUse.type;
325 switch (typeUse.kind) { 307 switch (typeUse.kind) {
326 case TypeUseKind.INSTANTIATION: 308 case TypeUseKind.INSTANTIATION:
327 _registerInstantiatedType(type, globalDependency: false); 309 _registerInstantiatedType(type, globalDependency: false);
328 break; 310 break;
329 case TypeUseKind.MIRROR_INSTANTIATION: 311 case TypeUseKind.MIRROR_INSTANTIATION:
330 _registerInstantiatedType(type, 312 _registerInstantiatedType(type,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 _universe.closurizedMembers.add(element); 356 _universe.closurizedMembers.add(element);
375 } 357 }
376 358
377 void forEach(void f(WorkItem work)) { 359 void forEach(void f(WorkItem work)) {
378 do { 360 do {
379 while (_queue.isNotEmpty) { 361 while (_queue.isNotEmpty) {
380 // TODO(johnniwinther): Find an optimal process order. 362 // TODO(johnniwinther): Find an optimal process order.
381 WorkItem work = _queue.removeLast(); 363 WorkItem work = _queue.removeLast();
382 if (!_processedElements.contains(work.element)) { 364 if (!_processedElements.contains(work.element)) {
383 strategy.processWorkItem(f, work); 365 strategy.processWorkItem(f, work);
384 registerProcessedElement(work.element); 366 _processedElements.add(work.element);
385 } 367 }
386 } 368 }
387 List recents = _recentClasses.toList(growable: false); 369 List recents = _recentClasses.toList(growable: false);
388 _recentClasses.clear(); 370 _recentClasses.clear();
389 if (!_onQueueEmpty(recents)) { 371 if (!_onQueueEmpty(recents)) {
390 _recentClasses.addAll(recents); 372 _recentClasses.addAll(recents);
391 } 373 }
392 } while (_queue.isNotEmpty || _recentClasses.isNotEmpty); 374 } while (_queue.isNotEmpty || _recentClasses.isNotEmpty);
393 } 375 }
394 376
395 void logSummary(log(message)) { 377 void logSummary(log(message)) {
396 log('Resolved ${_processedElements.length} elements.'); 378 log('Resolved ${_processedElements.length} elements.');
397 nativeEnqueuer.logSummary(log); 379 nativeEnqueuer.logSummary(log);
398 } 380 }
399 381
400 String toString() => 'Enqueuer($name)'; 382 String toString() => 'Enqueuer($name)';
401 383
402 Iterable<Entity> get processedEntities => _processedElements; 384 Iterable<Entity> get processedEntities => _processedElements;
403 385
404 ImpactUseCase get impactUse => IMPACT_USE; 386 ImpactUseCase get impactUse => IMPACT_USE;
405 387
406 bool get isResolutionQueue => true; 388 bool get isResolutionQueue => true;
407 389
408 /// Returns `true` if [element] has been processed by the resolution enqueuer. 390 /// Returns `true` if [element] has been processed by the resolution enqueuer.
391 // TODO(johnniwinther): Move this to the [OpenWorld]/[ResolutionWorldBuilder].
409 bool hasBeenProcessed(Element element) { 392 bool hasBeenProcessed(Element element) {
410 return _processedElements.contains(element.analyzableElement.declaration); 393 assert(invariant(element, element == element.analyzableElement.declaration,
394 message: "Unexpected element $element"));
395 return _processedElements.contains(element);
411 } 396 }
412 397
413 /// Registers [element] as processed by the resolution enqueuer. 398 /// Registers [element] as processed by the resolution enqueuer. Used only for
414 void registerProcessedElement(AstElement element) { 399 /// testing.
400 void registerProcessedElementInternal(AstElement element) {
415 _processedElements.add(element); 401 _processedElements.add(element);
416 } 402 }
417 403
418 /// Adds [element] to the work list if it has not already been processed. 404 /// Adds [element] to the work list if it has not already been processed.
419 /// 405 ///
420 /// Invariant: [element] must be a declaration element. 406 /// Invariant: [element] must be a declaration element.
421 void _addToWorkList(Element element) { 407 void _addToWorkList(Element element) {
422 assert(invariant(element, element.isDeclaration)); 408 assert(invariant(element, element.isDeclaration));
423 if (element.isMalformed) return; 409 if (element.isMalformed) return;
424 410
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 } 594 }
609 595
610 typedef void _DeferredActionFunction(); 596 typedef void _DeferredActionFunction();
611 597
612 class _DeferredAction { 598 class _DeferredAction {
613 final Element element; 599 final Element element;
614 final _DeferredActionFunction action; 600 final _DeferredActionFunction action;
615 601
616 _DeferredAction(this.element, this.action); 602 _DeferredAction(this.element, this.action);
617 } 603 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/deferred_load.dart ('k') | pkg/compiler/lib/src/universe/world_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698