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

Unified Diff: pkg/compiler/lib/src/enqueue.dart

Issue 2590913002: Add WorkItemBuilder to abstract WorkItem creation from the enqueuers. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/enqueue.dart
diff --git a/pkg/compiler/lib/src/enqueue.dart b/pkg/compiler/lib/src/enqueue.dart
index 6454c0de3918ed4cdb9833268f16199e2e8fa006..c54208c94861ea4928bc4e97f0aaf4f8f5fcb028 100644
--- a/pkg/compiler/lib/src/enqueue.dart
+++ b/pkg/compiler/lib/src/enqueue.dart
@@ -8,8 +8,7 @@ import 'dart:collection' show Queue;
import 'cache_strategy.dart';
import 'common/backend_api.dart' show Backend;
-import 'common/names.dart' show Identifiers;
-import 'common/resolution.dart' show Resolution, ResolutionWorkItem;
+import 'common/resolution.dart' show Resolution;
import 'common/tasks.dart' show CompilerTask;
import 'common/work.dart' show WorkItem;
import 'common.dart';
@@ -19,7 +18,6 @@ import 'dart_types.dart' show DartType, InterfaceType;
import 'elements/elements.dart'
show
AnalyzableElement,
- AstElement,
ClassElement,
ConstructorElement,
Element,
@@ -137,6 +135,7 @@ class ResolutionEnqueuer extends EnqueuerImpl {
final EnqueuerStrategy strategy;
final Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>();
final ResolutionWorldBuilderImpl _universe;
+ final WorkItemBuilder _workItemBuilder;
bool queueIsClosed = false;
@@ -164,7 +163,8 @@ class ResolutionEnqueuer extends EnqueuerImpl {
this._resolution = resolution,
this.nativeEnqueuer = backend.nativeResolutionEnqueuer(),
_universe = new ResolutionWorldBuilderImpl(
- backend, resolution, cacheStrategy, const TypeMaskStrategy()) {
+ backend, resolution, cacheStrategy, const TypeMaskStrategy()),
+ _workItemBuilder = new ResolutionWorkItemBuilder(resolution) {
_impactVisitor = new EnqueuerImplImpactVisitor(this);
}
@@ -358,37 +358,32 @@ class ResolutionEnqueuer extends EnqueuerImpl {
/// Returns `true` if [element] has been processed by the resolution enqueuer.
// TODO(johnniwinther): Move this to the [OpenWorld]/[ResolutionWorldBuilder].
- bool hasBeenProcessed(Element element) {
+ bool hasBeenProcessed(MemberElement element) {
assert(invariant(element, element == element.analyzableElement.declaration,
message: "Unexpected element $element"));
return _processedEntities.contains(element);
}
- /// Registers [element] as processed by the resolution enqueuer. Used only for
+ /// Registers [entity] as processed by the resolution enqueuer. Used only for
/// testing.
void registerProcessedElementInternal(Entity entity) {
_processedEntities.add(entity);
}
- /// Adds [element] to the work list if it has not already been processed.
- ///
- /// Invariant: [element] must be a declaration element.
- void _addToWorkList(Element element) {
- assert(invariant(element, element.isDeclaration));
- if (element.isMalformed) return;
+ /// Create a [WorkItem] for [entity] and add it to the work list if it has not
+ /// already been processed.
+ void _addToWorkList(MemberEntity entity) {
+ if (hasBeenProcessed(entity)) return;
+ WorkItem workItem = _workItemBuilder.createWorkItem(entity);
+ if (workItem == null) return;
- assert(invariant(element, element is AnalyzableElement,
- message: 'Element $element is not analyzable.'));
- if (hasBeenProcessed(element)) return;
if (queueIsClosed) {
throw new SpannableAssertionFailure(
- element, "Resolution work list is closed. Trying to add $element.");
+ entity, "Resolution work list is closed. Trying to add $entity.");
}
- applyImpact(backend.registerUsedElement(element, forResolution: true));
- _openWorld.registerUsedElement(element);
-
- ResolutionWorkItem workItem = _resolution.createWorkItem(element);
+ applyImpact(backend.registerUsedElement(entity, forResolution: true));
+ _openWorld.registerUsedElement(entity);
_queue.add(workItem);
}
@@ -531,3 +526,26 @@ class _DeferredAction {
_DeferredAction(this.element, this.action);
}
+
+/// Interface for creating work items for enqueued member entities.
+abstract class WorkItemBuilder {
+ 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
+}
+
+/// Builder that creates work item necessary for the resolution of a
+/// [MemberElement].
+class ResolutionWorkItemBuilder extends WorkItemBuilder {
+ final Resolution _resolution;
+
+ ResolutionWorkItemBuilder(this._resolution);
+
+ @override
+ WorkItem createWorkItem(MemberElement element) {
+ assert(invariant(element, element.isDeclaration));
+ if (element.isMalformed) return null;
+
+ assert(invariant(element, element is AnalyzableElement,
+ message: 'Element $element is not analyzable.'));
+ return _resolution.createWorkItem(element);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698