Chromium Code Reviews| 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 'cache_strategy.dart'; | 9 import 'cache_strategy.dart'; |
| 10 import 'common/backend_api.dart' show Backend; | 10 import 'common/backend_api.dart' show Backend; |
| 11 import 'common/names.dart' show Identifiers; | 11 import 'common/resolution.dart' show Resolution; |
| 12 import 'common/resolution.dart' show Resolution, ResolutionWorkItem; | |
| 13 import 'common/tasks.dart' show CompilerTask; | 12 import 'common/tasks.dart' show CompilerTask; |
| 14 import 'common/work.dart' show WorkItem; | 13 import 'common/work.dart' show WorkItem; |
| 15 import 'common.dart'; | 14 import 'common.dart'; |
| 16 import 'compiler.dart' show Compiler, GlobalDependencyRegistry; | 15 import 'compiler.dart' show Compiler, GlobalDependencyRegistry; |
| 17 import 'options.dart'; | 16 import 'options.dart'; |
| 18 import 'dart_types.dart' show DartType, InterfaceType; | 17 import 'dart_types.dart' show DartType, InterfaceType; |
| 19 import 'elements/elements.dart' | 18 import 'elements/elements.dart' |
| 20 show | 19 show |
| 21 AnalyzableElement, | 20 AnalyzableElement, |
| 22 AstElement, | |
| 23 ClassElement, | 21 ClassElement, |
| 24 ConstructorElement, | 22 ConstructorElement, |
| 25 Element, | 23 Element, |
| 26 Entity, | 24 Entity, |
| 27 MemberElement; | 25 MemberElement; |
| 28 import 'elements/entities.dart'; | 26 import 'elements/entities.dart'; |
| 29 import 'native/native.dart' as native; | 27 import 'native/native.dart' as native; |
| 30 import 'types/types.dart' show TypeMaskStrategy; | 28 import 'types/types.dart' show TypeMaskStrategy; |
| 31 import 'universe/world_builder.dart'; | 29 import 'universe/world_builder.dart'; |
| 32 import 'universe/use.dart' | 30 import 'universe/use.dart' |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 final String name; | 128 final String name; |
| 131 final Resolution _resolution; | 129 final Resolution _resolution; |
| 132 final CompilerOptions _options; | 130 final CompilerOptions _options; |
| 133 final Backend backend; | 131 final Backend backend; |
| 134 final GlobalDependencyRegistry _globalDependencies; | 132 final GlobalDependencyRegistry _globalDependencies; |
| 135 final native.NativeEnqueuer nativeEnqueuer; | 133 final native.NativeEnqueuer nativeEnqueuer; |
| 136 | 134 |
| 137 final EnqueuerStrategy strategy; | 135 final EnqueuerStrategy strategy; |
| 138 final Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); | 136 final Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); |
| 139 final ResolutionWorldBuilderImpl _universe; | 137 final ResolutionWorldBuilderImpl _universe; |
| 138 final WorkItemBuilder _workItemBuilder; | |
| 140 | 139 |
| 141 bool queueIsClosed = false; | 140 bool queueIsClosed = false; |
| 142 | 141 |
| 143 WorldImpactVisitor _impactVisitor; | 142 WorldImpactVisitor _impactVisitor; |
| 144 | 143 |
| 145 /// All declaration elements that have been processed by the resolver. | 144 /// All declaration elements that have been processed by the resolver. |
| 146 final Set<Entity> _processedEntities = new Set<Entity>(); | 145 final Set<Entity> _processedEntities = new Set<Entity>(); |
| 147 | 146 |
| 148 final Queue<WorkItem> _queue = new Queue<WorkItem>(); | 147 final Queue<WorkItem> _queue = new Queue<WorkItem>(); |
| 149 | 148 |
| 150 /// Queue of deferred resolution actions to execute when the resolution queue | 149 /// Queue of deferred resolution actions to execute when the resolution queue |
| 151 /// has been emptied. | 150 /// has been emptied. |
| 152 final Queue<_DeferredAction> _deferredQueue = new Queue<_DeferredAction>(); | 151 final Queue<_DeferredAction> _deferredQueue = new Queue<_DeferredAction>(); |
| 153 | 152 |
| 154 ResolutionEnqueuer( | 153 ResolutionEnqueuer( |
| 155 this.task, | 154 this.task, |
| 156 this._options, | 155 this._options, |
| 157 Resolution resolution, | 156 Resolution resolution, |
| 158 this.strategy, | 157 this.strategy, |
| 159 this._globalDependencies, | 158 this._globalDependencies, |
| 160 Backend backend, | 159 Backend backend, |
| 161 CacheStrategy cacheStrategy, | 160 CacheStrategy cacheStrategy, |
| 162 [this.name = 'resolution enqueuer']) | 161 [this.name = 'resolution enqueuer']) |
| 163 : this.backend = backend, | 162 : this.backend = backend, |
| 164 this._resolution = resolution, | 163 this._resolution = resolution, |
| 165 this.nativeEnqueuer = backend.nativeResolutionEnqueuer(), | 164 this.nativeEnqueuer = backend.nativeResolutionEnqueuer(), |
| 166 _universe = new ResolutionWorldBuilderImpl( | 165 _universe = new ResolutionWorldBuilderImpl( |
| 167 backend, resolution, cacheStrategy, const TypeMaskStrategy()) { | 166 backend, resolution, cacheStrategy, const TypeMaskStrategy()), |
| 167 _workItemBuilder = new ResolutionWorkItemBuilder(resolution) { | |
| 168 _impactVisitor = new EnqueuerImplImpactVisitor(this); | 168 _impactVisitor = new EnqueuerImplImpactVisitor(this); |
| 169 } | 169 } |
| 170 | 170 |
| 171 ResolutionWorldBuilder get universe => _universe; | 171 ResolutionWorldBuilder get universe => _universe; |
| 172 | 172 |
| 173 OpenWorld get _openWorld => universe.openWorld; | 173 OpenWorld get _openWorld => universe.openWorld; |
| 174 | 174 |
| 175 bool get queueIsEmpty => _queue.isEmpty; | 175 bool get queueIsEmpty => _queue.isEmpty; |
| 176 | 176 |
| 177 DiagnosticReporter get _reporter => _resolution.reporter; | 177 DiagnosticReporter get _reporter => _resolution.reporter; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 String toString() => 'Enqueuer($name)'; | 351 String toString() => 'Enqueuer($name)'; |
| 352 | 352 |
| 353 Iterable<Entity> get processedEntities => _processedEntities; | 353 Iterable<Entity> get processedEntities => _processedEntities; |
| 354 | 354 |
| 355 ImpactUseCase get impactUse => IMPACT_USE; | 355 ImpactUseCase get impactUse => IMPACT_USE; |
| 356 | 356 |
| 357 bool get isResolutionQueue => true; | 357 bool get isResolutionQueue => true; |
| 358 | 358 |
| 359 /// Returns `true` if [element] has been processed by the resolution enqueuer. | 359 /// Returns `true` if [element] has been processed by the resolution enqueuer. |
| 360 // TODO(johnniwinther): Move this to the [OpenWorld]/[ResolutionWorldBuilder]. | 360 // TODO(johnniwinther): Move this to the [OpenWorld]/[ResolutionWorldBuilder]. |
| 361 bool hasBeenProcessed(Element element) { | 361 bool hasBeenProcessed(MemberElement element) { |
| 362 assert(invariant(element, element == element.analyzableElement.declaration, | 362 assert(invariant(element, element == element.analyzableElement.declaration, |
| 363 message: "Unexpected element $element")); | 363 message: "Unexpected element $element")); |
| 364 return _processedEntities.contains(element); | 364 return _processedEntities.contains(element); |
| 365 } | 365 } |
| 366 | 366 |
| 367 /// Registers [element] as processed by the resolution enqueuer. Used only for | 367 /// Registers [entity] as processed by the resolution enqueuer. Used only for |
| 368 /// testing. | 368 /// testing. |
| 369 void registerProcessedElementInternal(Entity entity) { | 369 void registerProcessedElementInternal(Entity entity) { |
| 370 _processedEntities.add(entity); | 370 _processedEntities.add(entity); |
| 371 } | 371 } |
| 372 | 372 |
| 373 /// Adds [element] to the work list if it has not already been processed. | 373 /// Create a [WorkItem] for [entity] and add it to the work list if it has not |
| 374 /// | 374 /// already been processed. |
| 375 /// Invariant: [element] must be a declaration element. | 375 void _addToWorkList(MemberEntity entity) { |
| 376 void _addToWorkList(Element element) { | 376 if (hasBeenProcessed(entity)) return; |
| 377 assert(invariant(element, element.isDeclaration)); | 377 WorkItem workItem = _workItemBuilder.createWorkItem(entity); |
| 378 if (element.isMalformed) return; | 378 if (workItem == null) return; |
| 379 | 379 |
| 380 assert(invariant(element, element is AnalyzableElement, | |
| 381 message: 'Element $element is not analyzable.')); | |
| 382 if (hasBeenProcessed(element)) return; | |
| 383 if (queueIsClosed) { | 380 if (queueIsClosed) { |
| 384 throw new SpannableAssertionFailure( | 381 throw new SpannableAssertionFailure( |
| 385 element, "Resolution work list is closed. Trying to add $element."); | 382 entity, "Resolution work list is closed. Trying to add $entity."); |
| 386 } | 383 } |
| 387 | 384 |
| 388 applyImpact(backend.registerUsedElement(element, forResolution: true)); | 385 applyImpact(backend.registerUsedElement(entity, forResolution: true)); |
| 389 _openWorld.registerUsedElement(element); | 386 _openWorld.registerUsedElement(entity); |
| 390 | |
| 391 ResolutionWorkItem workItem = _resolution.createWorkItem(element); | |
| 392 _queue.add(workItem); | 387 _queue.add(workItem); |
| 393 } | 388 } |
| 394 | 389 |
| 395 /// Adds an action to the deferred task queue. | 390 /// Adds an action to the deferred task queue. |
| 396 /// The action is performed the next time the resolution queue has been | 391 /// The action is performed the next time the resolution queue has been |
| 397 /// emptied. | 392 /// emptied. |
| 398 /// | 393 /// |
| 399 /// The queue is processed in FIFO order. | 394 /// The queue is processed in FIFO order. |
| 400 void addDeferredAction(Entity entity, void action()) { | 395 void addDeferredAction(Entity entity, void action()) { |
| 401 if (queueIsClosed) { | 396 if (queueIsClosed) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 } | 519 } |
| 525 | 520 |
| 526 typedef void _DeferredActionFunction(); | 521 typedef void _DeferredActionFunction(); |
| 527 | 522 |
| 528 class _DeferredAction { | 523 class _DeferredAction { |
| 529 final Element element; | 524 final Element element; |
| 530 final _DeferredActionFunction action; | 525 final _DeferredActionFunction action; |
| 531 | 526 |
| 532 _DeferredAction(this.element, this.action); | 527 _DeferredAction(this.element, this.action); |
| 533 } | 528 } |
| 529 | |
| 530 /// Interface for creating work items for enqueued member entities. | |
| 531 abstract class WorkItemBuilder { | |
| 532 WorkItem createWorkItem(MemberEntity entity); | |
|
Siggi Cherem (dart-lang)
2016/12/20 21:21:47
eventually, should we turn this into just a typede
Johnni Winther
2016/12/21 10:19:37
We could but it would make the descriptor of the b
| |
| 533 } | |
| 534 | |
| 535 /// Builder that creates work item necessary for the resolution of a | |
| 536 /// [MemberElement]. | |
| 537 class ResolutionWorkItemBuilder extends WorkItemBuilder { | |
| 538 final Resolution _resolution; | |
| 539 | |
| 540 ResolutionWorkItemBuilder(this._resolution); | |
| 541 | |
| 542 @override | |
| 543 WorkItem createWorkItem(MemberElement element) { | |
| 544 assert(invariant(element, element.isDeclaration)); | |
| 545 if (element.isMalformed) return null; | |
| 546 | |
| 547 assert(invariant(element, element is AnalyzableElement, | |
| 548 message: 'Element $element is not analyzable.')); | |
| 549 return _resolution.createWorkItem(element); | |
| 550 } | |
| 551 } | |
| OLD | NEW |