| OLD | NEW |
| 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 'common/resolution.dart' show Resolution; | 9 import 'common/resolution.dart' show Resolution; |
| 10 import 'common/tasks.dart' show CompilerTask; | 10 import 'common/tasks.dart' show CompilerTask; |
| 11 import 'common/work.dart' show WorkItem; | 11 import 'common/work.dart' show WorkItem; |
| 12 import 'common.dart'; | 12 import 'common.dart'; |
| 13 import 'common_elements.dart' show ElementEnvironment; |
| 13 import 'constants/values.dart'; | 14 import 'constants/values.dart'; |
| 14 import 'compiler.dart' show Compiler; | 15 import 'compiler.dart' show Compiler; |
| 15 import 'options.dart'; | 16 import 'options.dart'; |
| 16 import 'elements/elements.dart' | 17 import 'elements/elements.dart' show AnalyzableElement, MemberElement; |
| 17 show AnalyzableElement, ClassElement, MemberElement; | |
| 18 import 'elements/entities.dart'; | 18 import 'elements/entities.dart'; |
| 19 import 'elements/resolution_types.dart' show ResolutionTypedefType; | 19 import 'elements/resolution_types.dart' show ResolutionTypedefType; |
| 20 import 'elements/types.dart'; | 20 import 'elements/types.dart'; |
| 21 import 'universe/world_builder.dart'; | 21 import 'universe/world_builder.dart'; |
| 22 import 'universe/use.dart' | 22 import 'universe/use.dart' |
| 23 show | 23 show |
| 24 ConstantUse, | 24 ConstantUse, |
| 25 DynamicUse, | 25 DynamicUse, |
| 26 StaticUse, | 26 StaticUse, |
| 27 StaticUseKind, | 27 StaticUseKind, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 bool get queueIsEmpty; | 78 bool get queueIsEmpty; |
| 79 | 79 |
| 80 ImpactUseCase get impactUse; | 80 ImpactUseCase get impactUse; |
| 81 | 81 |
| 82 void forEach(void f(WorkItem work)); | 82 void forEach(void f(WorkItem work)); |
| 83 | 83 |
| 84 /// Apply the [worldImpact] to this enqueuer. If the [impactSource] is | 84 /// Apply the [worldImpact] to this enqueuer. If the [impactSource] is |
| 85 /// provided the impact strategy will remove it from the element impact cache, | 85 /// provided the impact strategy will remove it from the element impact cache, |
| 86 /// if it is no longer needed. | 86 /// if it is no longer needed. |
| 87 void applyImpact(WorldImpact worldImpact, {var impactSource}); | 87 void applyImpact(WorldImpact worldImpact, {var impactSource}); |
| 88 bool checkNoEnqueuedInvokedInstanceMethods(); | 88 bool checkNoEnqueuedInvokedInstanceMethods( |
| 89 ElementEnvironment elementEnvironment); |
| 89 | 90 |
| 90 /// Check the enqueuer queue is empty or fail otherwise. | 91 /// Check the enqueuer queue is empty or fail otherwise. |
| 91 void checkQueueIsEmpty(); | 92 void checkQueueIsEmpty(); |
| 92 void logSummary(void log(String message)); | 93 void logSummary(void log(String message)); |
| 93 | 94 |
| 94 Iterable<MemberEntity> get processedEntities; | 95 Iterable<MemberEntity> get processedEntities; |
| 95 | 96 |
| 96 Iterable<ClassEntity> get processedClasses; | 97 Iterable<ClassEntity> get processedClasses; |
| 97 } | 98 } |
| 98 | 99 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 task.measure(() { | 249 task.measure(() { |
| 249 _worldBuilder.registerTypeInstantiation(type, _applyClassUse, | 250 _worldBuilder.registerTypeInstantiation(type, _applyClassUse, |
| 250 constructor: constructor, | 251 constructor: constructor, |
| 251 byMirrors: mirrorUsage, | 252 byMirrors: mirrorUsage, |
| 252 isRedirection: isRedirection); | 253 isRedirection: isRedirection); |
| 253 listener.registerInstantiatedType(type, | 254 listener.registerInstantiatedType(type, |
| 254 isGlobal: globalDependency && !mirrorUsage, nativeUsage: nativeUsage); | 255 isGlobal: globalDependency && !mirrorUsage, nativeUsage: nativeUsage); |
| 255 }); | 256 }); |
| 256 } | 257 } |
| 257 | 258 |
| 258 bool checkNoEnqueuedInvokedInstanceMethods() { | 259 bool checkNoEnqueuedInvokedInstanceMethods( |
| 259 return strategy.checkEnqueuerConsistency(this); | 260 ElementEnvironment elementEnvironment) { |
| 261 return strategy.checkEnqueuerConsistency(this, elementEnvironment); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void checkClass(ClassEntity cls) { | 264 void checkClass(ClassEntity cls) { |
| 263 _worldBuilder.processClassMembers(cls, | 265 _worldBuilder.processClassMembers(cls, |
| 264 (MemberEntity member, EnumSet<MemberUse> useSet) { | 266 (MemberEntity member, EnumSet<MemberUse> useSet) { |
| 265 if (useSet.isNotEmpty) { | 267 if (useSet.isNotEmpty) { |
| 266 _reporter.internalError(member, | 268 _reporter.internalError(member, |
| 267 'Unenqueued use of $member: ${useSet.iterable(MemberUse.values)}'); | 269 'Unenqueued use of $member: ${useSet.iterable(MemberUse.values)}'); |
| 268 } | 270 } |
| 269 }); | 271 }); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 /// Process a type use in live code. | 501 /// Process a type use in live code. |
| 500 void processTypeUse(EnqueuerImpl enqueuer, TypeUse typeUse) {} | 502 void processTypeUse(EnqueuerImpl enqueuer, TypeUse typeUse) {} |
| 501 | 503 |
| 502 /// Process a dynamic use for a call site in live code. | 504 /// Process a dynamic use for a call site in live code. |
| 503 void processDynamicUse(EnqueuerImpl enqueuer, DynamicUse dynamicUse) {} | 505 void processDynamicUse(EnqueuerImpl enqueuer, DynamicUse dynamicUse) {} |
| 504 | 506 |
| 505 /// Process a constant use in live code. | 507 /// Process a constant use in live code. |
| 506 void processConstantUse(EnqueuerImpl enqueuer, ConstantUse constantUse) {} | 508 void processConstantUse(EnqueuerImpl enqueuer, ConstantUse constantUse) {} |
| 507 | 509 |
| 508 /// Check enqueuer consistency after the queue has been closed. | 510 /// Check enqueuer consistency after the queue has been closed. |
| 509 bool checkEnqueuerConsistency(EnqueuerImpl enqueuer) => true; | 511 bool checkEnqueuerConsistency( |
| 512 EnqueuerImpl enqueuer, ElementEnvironment elementEnvironment) => |
| 513 true; |
| 510 | 514 |
| 511 /// Process [work] using [f]. | 515 /// Process [work] using [f]. |
| 512 void processWorkItem(void f(WorkItem work), WorkItem work) { | 516 void processWorkItem(void f(WorkItem work), WorkItem work) { |
| 513 f(work); | 517 f(work); |
| 514 } | 518 } |
| 515 } | 519 } |
| 516 | 520 |
| 517 /// Strategy that only enqueues directly used elements. | 521 /// Strategy that only enqueues directly used elements. |
| 518 class DirectEnqueuerStrategy extends EnqueuerStrategy { | 522 class DirectEnqueuerStrategy extends EnqueuerStrategy { |
| 519 const DirectEnqueuerStrategy(); | 523 const DirectEnqueuerStrategy(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 542 void processDynamicUse(EnqueuerImpl enqueuer, DynamicUse dynamicUse) { | 546 void processDynamicUse(EnqueuerImpl enqueuer, DynamicUse dynamicUse) { |
| 543 enqueuer.processDynamicUse(dynamicUse); | 547 enqueuer.processDynamicUse(dynamicUse); |
| 544 } | 548 } |
| 545 | 549 |
| 546 @override | 550 @override |
| 547 void processConstantUse(EnqueuerImpl enqueuer, ConstantUse constantUse) { | 551 void processConstantUse(EnqueuerImpl enqueuer, ConstantUse constantUse) { |
| 548 enqueuer.processConstantUse(constantUse); | 552 enqueuer.processConstantUse(constantUse); |
| 549 } | 553 } |
| 550 | 554 |
| 551 /// Check enqueuer consistency after the queue has been closed. | 555 /// Check enqueuer consistency after the queue has been closed. |
| 552 bool checkEnqueuerConsistency(EnqueuerImpl enqueuer) { | 556 bool checkEnqueuerConsistency( |
| 557 EnqueuerImpl enqueuer, ElementEnvironment elementEnvironment) { |
| 553 enqueuer.task.measure(() { | 558 enqueuer.task.measure(() { |
| 554 // Run through the classes and see if we need to enqueue more methods. | 559 // Run through the classes and see if we need to enqueue more methods. |
| 555 for (ClassElement classElement | 560 for (ClassEntity classElement |
| 556 in enqueuer.worldBuilder.directlyInstantiatedClasses) { | 561 in enqueuer.worldBuilder.directlyInstantiatedClasses) { |
| 557 for (ClassElement currentClass = classElement; | 562 for (ClassEntity currentClass = classElement; |
| 558 currentClass != null; | 563 currentClass != null; |
| 559 currentClass = currentClass.superclass) { | 564 currentClass = elementEnvironment.getSuperClass(currentClass)) { |
| 560 enqueuer.checkClass(currentClass); | 565 enqueuer.checkClass(currentClass); |
| 561 } | 566 } |
| 562 } | 567 } |
| 563 }); | 568 }); |
| 564 return true; | 569 return true; |
| 565 } | 570 } |
| 566 } | 571 } |
| 567 | 572 |
| 568 class EnqueuerImplImpactVisitor implements WorldImpactVisitor { | 573 class EnqueuerImplImpactVisitor implements WorldImpactVisitor { |
| 569 final EnqueuerImpl enqueuer; | 574 final EnqueuerImpl enqueuer; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 @override | 620 @override |
| 616 WorkItem createWorkItem(MemberElement element) { | 621 WorkItem createWorkItem(MemberElement element) { |
| 617 assert(invariant(element, element.isDeclaration)); | 622 assert(invariant(element, element.isDeclaration)); |
| 618 if (element.isMalformed) return null; | 623 if (element.isMalformed) return null; |
| 619 | 624 |
| 620 assert(invariant(element, element is AnalyzableElement, | 625 assert(invariant(element, element is AnalyzableElement, |
| 621 message: 'Element $element is not analyzable.')); | 626 message: 'Element $element is not analyzable.')); |
| 622 return _resolution.createWorkItem(element); | 627 return _resolution.createWorkItem(element); |
| 623 } | 628 } |
| 624 } | 629 } |
| OLD | NEW |