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

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

Issue 10827180: Move types out of the HInstructions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cosmetic change (updated comment). Created 8 years, 4 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, compiler.backend),
13 resolution = new Enqueuer(compiler), 13 resolution = new Enqueuer(compiler, compiler.backend),
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 { 20 class RecompilationQueue {
21 final Backend backend;
21 final Queue<WorkItem> queue; 22 final Queue<WorkItem> queue;
22 final Set<Element> queueElements; 23 final Set<Element> queueElements;
23 int processed = 0; 24 int processed = 0;
24 25
25 RecompilationQueue() 26 RecompilationQueue(this.backend)
26 : queue = new Queue<WorkItem>(), 27 : queue = new Queue<WorkItem>(),
27 queueElements = new Set<Element>(); 28 queueElements = new Set<Element>();
28 29
29 void add(Element element, TreeElements elements) { 30 void add(Element element, TreeElements elements) {
30 if (queueElements.contains(element)) return; 31 if (queueElements.contains(element)) return;
31 queueElements.add(element); 32 queueElements.add(element);
32 queue.add(new WorkItem(element, elements)); 33 queue.add(backend.createWorkItem(element, elements));
33 } 34 }
34 35
35 int get length() => queue.length; 36 int get length() => queue.length;
36 37
37 bool isEmpty() => queue.isEmpty(); 38 bool isEmpty() => queue.isEmpty();
38 39
39 WorkItem next() { 40 WorkItem next() {
40 WorkItem item = queue.removeLast(); 41 WorkItem item = queue.removeLast();
41 queueElements.remove(item.element); 42 queueElements.remove(item.element);
42 processed++; 43 processed++;
43 return item; 44 return item;
44 } 45 }
45 } 46 }
46 47
47 class Enqueuer { 48 class Enqueuer {
48 final Compiler compiler; // TODO(ahe): Remove this dependency. 49 final Compiler compiler; // TODO(ahe): Remove this dependency.
50 final Backend backend;
49 final Map<String, Link<Element>> instanceMembersByName; 51 final Map<String, Link<Element>> instanceMembersByName;
50 final Set<ClassElement> seenClasses; 52 final Set<ClassElement> seenClasses;
51 final Universe universe; 53 final Universe universe;
52 final Queue<WorkItem> queue; 54 final Queue<WorkItem> queue;
53 final Map<Element, TreeElements> resolvedElements; 55 final Map<Element, TreeElements> resolvedElements;
54 final RecompilationQueue recompilationCandidates; 56 final RecompilationQueue recompilationCandidates;
55 57
56 bool queueIsClosed = false; 58 bool queueIsClosed = false;
57 EnqueueTask task; 59 EnqueueTask task;
58 60
59 Enqueuer(this.compiler) 61 Enqueuer(this.compiler, Backend backend)
60 : instanceMembersByName = new Map<String, Link<Element>>(), 62 : this.backend = backend,
63 instanceMembersByName = new Map<String, Link<Element>>(),
61 seenClasses = new Set<ClassElement>(), 64 seenClasses = new Set<ClassElement>(),
62 universe = new Universe(), 65 universe = new Universe(),
63 queue = new Queue<WorkItem>(), 66 queue = new Queue<WorkItem>(),
64 resolvedElements = new Map<Element, TreeElements>(), 67 resolvedElements = new Map<Element, TreeElements>(),
65 recompilationCandidates = new RecompilationQueue(); 68 recompilationCandidates = new RecompilationQueue(backend);
66 69
67 bool get isResolutionQueue() => compiler.enqueuer.resolution === this; 70 bool get isResolutionQueue() => compiler.enqueuer.resolution === this;
68 71
69 TreeElements getCachedElements(Element element) { 72 TreeElements getCachedElements(Element element) {
70 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); 73 Element owner = element.getOutermostEnclosingMemberOrTopLevel();
71 return compiler.enqueuer.resolution.resolvedElements[owner]; 74 return compiler.enqueuer.resolution.resolvedElements[owner];
72 } 75 }
73 76
74 void addToWorkList(Element element, [TreeElements elements]) { 77 void addToWorkList(Element element, [TreeElements elements]) {
75 if (element.isForeign()) return; 78 if (element.isForeign()) return;
76 if (compiler.phase == Compiler.PHASE_RECOMPILING) return; 79 if (compiler.phase == Compiler.PHASE_RECOMPILING) return;
77 if (queueIsClosed) { 80 if (queueIsClosed) {
78 if (isResolutionQueue && getCachedElements(element) !== null) return; 81 if (isResolutionQueue && getCachedElements(element) !== null) return;
79 compiler.internalErrorOnElement(element, "Work list is closed."); 82 compiler.internalErrorOnElement(element, "Work list is closed.");
80 } 83 }
81 if (!isResolutionQueue && 84 if (!isResolutionQueue &&
82 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 85 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
83 registerInstantiatedClass(element.enclosingElement); 86 registerInstantiatedClass(element.enclosingElement);
84 } 87 }
85 if (elements === null) { 88 if (elements === null) {
86 elements = getCachedElements(element); 89 elements = getCachedElements(element);
87 } 90 }
88 queue.add(new WorkItem(element, elements)); 91 queue.add(backend.createWorkItem(element, elements));
Lasse Reichstein Nielsen 2012/08/08 07:44:53 If you only use 'backend' for 'createWorkItem', ju
floitsch 2012/08/08 19:18:37 Done.
89 } 92 }
90 93
91 bool canBeRecompiled(Element element) { 94 bool canBeRecompiled(Element element) {
92 // Only member functions can be recompiled. An exception to this is members 95 // Only member functions can be recompiled. An exception to this is members
93 // of closures. They are processed as part of the enclosing function and not 96 // of closures. They are processed as part of the enclosing function and not
94 // present as a separate element (the call to the closure will be a member 97 // present as a separate element (the call to the closure will be a member
95 // function). 98 // function).
96 return element.isMember() && !element.getEnclosingClass().isClosure(); 99 return element.isMember() && !element.getEnclosingClass().isClosure();
97 } 100 }
98 101
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void registerIsCheck(Element element) { 317 void registerIsCheck(Element element) {
315 universe.isChecks.add(element); 318 universe.isChecks.add(element);
316 } 319 }
317 320
318 void forEach(f(WorkItem work)) { 321 void forEach(f(WorkItem work)) {
319 while (!queue.isEmpty()) { 322 while (!queue.isEmpty()) {
320 f(queue.removeLast()); 323 f(queue.removeLast());
321 } 324 }
322 } 325 }
323 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698