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

Side by Side Diff: lib/compiler/implementation/enqueue.dart

Issue 10537025: Prototype re-compiling methods in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added comment 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class EnqueueTask extends CompilerTask { 5 class EnqueueTask extends CompilerTask {
6 final Enqueuer codegen; 6 final Enqueuer codegen;
7 final Enqueuer resolution; 7 final Enqueuer resolution;
8 8
9 String get name() => 'Enqueue'; 9 String get name() => 'Enqueue';
10 10
11 EnqueueTask(Compiler compiler) 11 EnqueueTask(Compiler compiler)
12 : codegen = new Enqueuer(compiler), 12 : codegen = new Enqueuer(compiler),
13 resolution = new Enqueuer(compiler), 13 resolution = new Enqueuer(compiler),
14 super(compiler) { 14 super(compiler) {
15 codegen.task = this; 15 codegen.task = this;
16 resolution.task = this; 16 resolution.task = this;
17 } 17 }
18 } 18 }
19 19
20 class RecompilationQueue {
21 final Queue<WorkItem> queue;
22 final Set<Element> queueElements;
23
24 RecompilationQueue()
25 : queue = new Queue<WorkItem>(),
26 queueElements = new Set<Element>();
27
28 void add(Element element, TreeElements elements) {
29 if (queueElements.contains(element)) return;
30 // TODO(sgjesse): Make this handle constructor bodies as well.
31 if (element.kind !== ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
32 queueElements.add(element);
33 queue.add(new WorkItem(element, elements));
34 }
35 }
36
37 int get length() => queue.length;
38
39 bool isEmpty() => queue.isEmpty();
40
41 WorkItem next() {
42 WorkItem item = queue.removeLast();
43 queueElements.remove(item.element);
44 return item;
45 }
46 }
47
20 class Enqueuer { 48 class Enqueuer {
21 final Compiler compiler; // TODO(ahe): Remove this dependency. 49 final Compiler compiler; // TODO(ahe): Remove this dependency.
22 final Map<String, Link<Element>> instanceMembersByName; 50 final Map<String, Link<Element>> instanceMembersByName;
23 final Set<ClassElement> seenClasses; 51 final Set<ClassElement> seenClasses;
24 final Universe universe; 52 final Universe universe;
25 final Queue<WorkItem> queue; 53 final Queue<WorkItem> queue;
26 final Map<Element, TreeElements> resolvedElements; 54 final Map<Element, TreeElements> resolvedElements;
55 final RecompilationQueue recompilationCandidates;
56
27 bool queueIsClosed = false; 57 bool queueIsClosed = false;
28 EnqueueTask task; 58 EnqueueTask task;
29 59
30 Enqueuer(this.compiler) 60 Enqueuer(this.compiler)
31 : instanceMembersByName = new Map<String, Link<Element>>(), 61 : instanceMembersByName = new Map<String, Link<Element>>(),
32 seenClasses = new Set<ClassElement>(), 62 seenClasses = new Set<ClassElement>(),
33 universe = new Universe(), 63 universe = new Universe(),
34 queue = new Queue<WorkItem>(), 64 queue = new Queue<WorkItem>(),
35 resolvedElements = new Map<Element, TreeElements>(); 65 resolvedElements = new Map<Element, TreeElements>(),
66 recompilationCandidates = new RecompilationQueue();
36 67
37 bool get isFirstQueue() => compiler.enqueuer.resolution === this; 68 bool get isFirstQueue() => compiler.enqueuer.resolution === this;
38 69
39 TreeElements getCachedElements(Element element) { 70 TreeElements getCachedElements(Element element) {
40 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); 71 Element owner = element.getOutermostEnclosingMemberOrTopLevel();
41 return compiler.enqueuer.resolution.resolvedElements[owner]; 72 return compiler.enqueuer.resolution.resolvedElements[owner];
42 } 73 }
43 74
44 void addToWorkList(Element element, [TreeElements elements]) { 75 void addToWorkList(Element element, [TreeElements elements]) {
45 if (element.isForeign()) return; 76 if (element.isForeign()) return;
77 if (compiler.pass == 2) return;
46 if (queueIsClosed) { 78 if (queueIsClosed) {
47 if (isFirstQueue && getCachedElements(element) !== null) return; 79 if (isFirstQueue && getCachedElements(element) !== null) return;
48 compiler.internalErrorOnElement(element, "Work list is closed."); 80 compiler.internalErrorOnElement(element, "Work list is closed.");
49 } 81 }
50 if (!isFirstQueue && element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 82 if (!isFirstQueue && element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
51 registerInstantiatedClass(element.enclosingElement); 83 registerInstantiatedClass(element.enclosingElement);
52 } 84 }
53 if (elements === null) { 85 if (elements === null) {
54 elements = getCachedElements(element); 86 elements = getCachedElements(element);
55 } 87 }
56 queue.add(new WorkItem(element, elements)); 88 queue.add(new WorkItem(element, elements));
57 } 89 }
58 90
91 void addToRecompilationCandidates(Element element, [TreeElements elements]) {
floitsch 2012/06/13 12:51:10 maybe addRecompilationCandidate registerRecompilat
Søren Gjesse 2012/06/14 06:37:10 Changed to registerRecompilationCandidate.
92 if (element.isMember() &&
93 element.getEnclosingClass().name == const SourceString("Closure")) {
floitsch 2012/06/13 12:51:10 explain why.
Søren Gjesse 2012/06/14 06:37:10 Added a function canByRecompiled and placed the ex
94 return;
95 }
96 if (queueIsClosed) {
97 compiler.internalErrorOnElement(element, "Work list is closed.");
98 }
99 recompilationCandidates.add(element, elements);
100 }
101
59 void registerInstantiatedClass(ClassElement cls) { 102 void registerInstantiatedClass(ClassElement cls) {
60 if (cls.isInterface()) { 103 if (cls.isInterface()) {
61 compiler.internalErrorOnElement( 104 compiler.internalErrorOnElement(
62 // Use the current element, as this is where cls is referenced from. 105 // Use the current element, as this is where cls is referenced from.
63 compiler.currentElement, 106 compiler.currentElement,
64 'Expected a class, but $cls is an interface.'); 107 'Expected a class, but $cls is an interface.');
65 } 108 }
66 universe.instantiatedClasses.add(cls); 109 universe.instantiatedClasses.add(cls);
67 onRegisterInstantiatedClass(cls); 110 onRegisterInstantiatedClass(cls);
68 } 111 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 void registerIsCheck(Element element) { 307 void registerIsCheck(Element element) {
265 universe.isChecks.add(element); 308 universe.isChecks.add(element);
266 } 309 }
267 310
268 void forEach(f(WorkItem work)) { 311 void forEach(f(WorkItem work)) {
269 while (!queue.isEmpty()) { 312 while (!queue.isEmpty()) {
270 f(queue.removeLast()); 313 f(queue.removeLast());
271 } 314 }
272 } 315 }
273 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698