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

Unified Diff: dart/lib/compiler/implementation/enqueue.dart

Issue 10542073: RFC: Resolution based tree-shaking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor tweaks for the unit tests Created 8 years, 6 months 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: dart/lib/compiler/implementation/enqueue.dart
diff --git a/dart/lib/compiler/implementation/enqueue.dart b/dart/lib/compiler/implementation/enqueue.dart
index 7ea54ad59f9748ea238929acbb3f917367ff1efb..a0a453af6be5b08e14bf3beae2e3f81602e759f5 100644
--- a/dart/lib/compiler/implementation/enqueue.dart
+++ b/dart/lib/compiler/implementation/enqueue.dart
@@ -23,6 +23,7 @@ class Enqueuer {
final Set<ClassElement> seenClasses;
final Universe universe;
final Queue<WorkItem> queue;
+ final Map<Element, TreeElements> resolvedElements;
bool queueIsClosed = false;
EnqueueTask task;
@@ -30,19 +31,38 @@ class Enqueuer {
: instanceMembersByName = new Map<String, Link<Element>>(),
seenClasses = new Set<ClassElement>(),
universe = new Universe(),
- queue = new Queue<WorkItem>();
+ queue = new Queue<WorkItem>(),
+ resolvedElements = new Map<Element, TreeElements>();
+
+ bool get isFirstQueue() => compiler.enqueuer.resolution === this;
ngeoffray 2012/06/12 12:44:14 isResolutionQueue?
ahe 2012/06/12 18:47:13 Done.
+
+ TreeElements getCachedElements(Element element) {
+ Element owner = element.getOutermostEnclosingMemberOrTopLevel();
+ return compiler.enqueuer.resolution.resolvedElements[owner];
+ }
void addToWorkList(Element element, [TreeElements elements]) {
+ if (element.isForeign()) return;
if (queueIsClosed) {
+ if (isFirstQueue && getCachedElements(element) !== null) return;
compiler.internalErrorOnElement(element, "Work list is closed.");
}
- if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
+ if (!isFirstQueue && element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
registerInstantiatedClass(element.enclosingElement);
}
+ if (elements === null) {
+ elements = getCachedElements(element);
+ }
queue.add(new WorkItem(element, elements));
}
void registerInstantiatedClass(ClassElement cls) {
+ if (cls.isInterface()) {
+ compiler.internalErrorOnElement(
+ // Use the current element, as this is where cls is referenced from.
+ compiler.currentElement,
+ 'Expected a class, but $cls is an interface.');
+ }
universe.instantiatedClasses.add(cls);
onRegisterInstantiatedClass(cls);
}
@@ -86,6 +106,7 @@ class Enqueuer {
void processInstantiatedClassMember(Element member) {
if (universe.generatedCode.containsKey(member)) return;
+ if (resolvedElements[member] !== null) return;
if (!member.isInstanceMember()) return;
if (member.isField()) return;
@@ -243,4 +264,10 @@ class Enqueuer {
void registerIsCheck(Element element) {
universe.isChecks.add(element);
}
+
+ void forEach(f(WorkItem work)) {
+ while (!queue.isEmpty()) {
+ f(queue.removeLast());
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698