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

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: 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 855c539fa1d4a28b9b0a875062deca3965ceb5cf..e134016e95aea740b4fd788bd36e18564f0ba72a 100644
--- a/dart/lib/compiler/implementation/enqueue.dart
+++ b/dart/lib/compiler/implementation/enqueue.dart
@@ -22,7 +22,8 @@ class Enqueuer {
final Map<String, Link<Element>> instanceMembersByName;
final Set<ClassElement> seenClasses;
final Universe universe;
- final Queue<WorkItem> queue;
+ final Queue<WorkItem> _queue;
+ final Map<Element, TreeElements> resolvedElements;
bool queueIsClosed = false;
EnqueueTask task;
@@ -30,16 +31,39 @@ 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;
+
+ TreeElements getCachedElements(Element element) {
+ Element owner = element.getOutermostEnclosingMemberOrTopLevel();
+ return compiler.enqueuer.resolution.resolvedElements[owner];
+ }
void addToWorkList(Element element, [TreeElements elements]) {
- if (queueIsClosed) {
+ // int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION
+ // | ElementCategory.FACTORY;
+ // if (element is AbstractFieldElement) return;
+ // if (!element.isAccessor() && (element.kind.category & allowed) == 0) return;
+ // if (!element.isParameter() && !element.isTopLevel() && !element.enclosingElement.isClass()) return;
+ if (element.isForeign()) return;
+ if (queueIsClosed && !isFirstQueue) {
compiler.internalErrorOnElement(element, "Work list is closed.");
}
if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
registerInstantiatedClass(element.enclosingElement);
}
- queue.add(new WorkItem(element, elements));
+ if (elements === null) {
+ elements = getCachedElements(element);
+ if (!isFirstQueue && elements === null) {
+ if (element.getLibrary() !== compiler.interceptorsLibrary &&
+ element.getLibrary() !== compiler.jsHelperLibrary) {
+ // compiler.internalErrorOnElement(element, 'Unresolved element');
+ }
+ }
+ }
+ _queue.add(new WorkItem(element, elements));
}
void registerInstantiatedClass(ClassElement cls) {
@@ -86,6 +110,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;
@@ -227,4 +252,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