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

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

Issue 10964016: Change the type inference for fields in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes and rebased Created 8 years, 3 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 compiler.backend.createItemCompilationContext), 13 compiler.backend.createItemCompilationContext),
14 resolution = new Enqueuer(compiler, 14 resolution = new Enqueuer(compiler,
15 compiler.backend.createItemCompilationContext), 15 compiler.backend.createItemCompilationContext),
16 super(compiler) { 16 super(compiler) {
17 codegen.task = this; 17 codegen.task = this;
18 resolution.task = this; 18 resolution.task = this;
19 } 19 }
20 } 20 }
21 21
22 class RecompilationQueue {
23 final Function itemCompilationContextCreator;
24 final Queue<WorkItem> queue;
25 final Set<Element> queueElements;
26 int processed = 0;
27
28 RecompilationQueue(ItemCompilationContext itemCompilationContextCreator())
29 : this.itemCompilationContextCreator = itemCompilationContextCreator,
30 queue = new Queue<WorkItem>(),
31 queueElements = new Set<Element>();
32
33 void add(Element element, TreeElements elements) {
34 if (queueElements.contains(element)) return;
35 queueElements.add(element);
36 queue.add(new WorkItem(element, elements, itemCompilationContextCreator()));
37 }
38
39 int get length => queue.length;
40
41 bool isEmpty() => queue.isEmpty();
42
43 WorkItem next() {
44 WorkItem item = queue.removeLast();
45 queueElements.remove(item.element);
46 processed++;
47 return item;
48 }
49 }
50
51 class Enqueuer { 22 class Enqueuer {
52 final Compiler compiler; // TODO(ahe): Remove this dependency. 23 final Compiler compiler; // TODO(ahe): Remove this dependency.
53 final Function itemCompilationContextCreator; 24 final Function itemCompilationContextCreator;
54 final Map<String, Link<Element>> instanceMembersByName; 25 final Map<String, Link<Element>> instanceMembersByName;
55 final Set<ClassElement> seenClasses; 26 final Set<ClassElement> seenClasses;
56 final Universe universe; 27 final Universe universe;
57 final Queue<WorkItem> queue; 28 final Queue<WorkItem> queue;
58 final Map<Element, TreeElements> resolvedElements; 29 final Map<Element, TreeElements> resolvedElements;
59 final RecompilationQueue recompilationCandidates;
60 30
61 bool queueIsClosed = false; 31 bool queueIsClosed = false;
62 EnqueueTask task; 32 EnqueueTask task;
63 33
64 Enqueuer(this.compiler, 34 Enqueuer(this.compiler,
65 ItemCompilationContext itemCompilationContextCreator()) 35 ItemCompilationContext itemCompilationContextCreator())
66 : this.itemCompilationContextCreator = itemCompilationContextCreator, 36 : this.itemCompilationContextCreator = itemCompilationContextCreator,
67 instanceMembersByName = new Map<String, Link<Element>>(), 37 instanceMembersByName = new Map<String, Link<Element>>(),
68 seenClasses = new Set<ClassElement>(), 38 seenClasses = new Set<ClassElement>(),
69 universe = new Universe(), 39 universe = new Universe(),
70 queue = new Queue<WorkItem>(), 40 queue = new Queue<WorkItem>(),
71 resolvedElements = new Map<Element, TreeElements>(), 41 resolvedElements = new Map<Element, TreeElements>();
72 recompilationCandidates =
73 new RecompilationQueue(itemCompilationContextCreator);
74 42
75 bool get isResolutionQueue => compiler.enqueuer.resolution === this; 43 bool get isResolutionQueue => compiler.enqueuer.resolution === this;
76 44
77 TreeElements getCachedElements(Element element) { 45 TreeElements getCachedElements(Element element) {
78 // TODO(ngeoffray): Get rid of this check. 46 // TODO(ngeoffray): Get rid of this check.
79 if (element.enclosingElement.isClosure()) { 47 if (element.enclosingElement.isClosure()) {
80 closureMapping.ClosureClassElement cls = element.enclosingElement; 48 closureMapping.ClosureClassElement cls = element.enclosingElement;
81 element = cls.methodElement; 49 element = cls.methodElement;
82 } 50 }
83 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); 51 Element owner = element.getOutermostEnclosingMemberOrTopLevel();
84 return compiler.enqueuer.resolution.resolvedElements[owner]; 52 return compiler.enqueuer.resolution.resolvedElements[owner];
85 } 53 }
86 54
87 String lookupCode(Element element) => 55 String lookupCode(Element element) =>
88 universe.generatedCode[element].toString(); 56 universe.generatedCode[element].toString();
89 57
90 void addToWorkList(Element element, [TreeElements elements]) { 58 void addToWorkList(Element element, [TreeElements elements]) {
91 if (element.isForeign()) return; 59 if (element.isForeign()) return;
92 if (compiler.phase == Compiler.PHASE_RECOMPILING) return;
93 if (queueIsClosed) { 60 if (queueIsClosed) {
94 if (isResolutionQueue && getCachedElements(element) !== null) return; 61 if (isResolutionQueue && getCachedElements(element) !== null) return;
95 compiler.internalErrorOnElement(element, "Work list is closed."); 62 compiler.internalErrorOnElement(element, "Work list is closed.");
96 } 63 }
97 if (!isResolutionQueue && 64 if (!isResolutionQueue &&
98 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 65 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
99 registerInstantiatedClass(element.getEnclosingClass()); 66 registerInstantiatedClass(element.getEnclosingClass());
100 } 67 }
101 if (elements === null) { 68 if (elements === null) {
102 elements = getCachedElements(element); 69 elements = getCachedElements(element);
(...skipping 17 matching lines...) Expand all
120 compiler.enableIsolateSupport(library); 87 compiler.enableIsolateSupport(library);
121 } 88 }
122 } 89 }
123 90
124 void eagerRecompile(Element element) { 91 void eagerRecompile(Element element) {
125 universe.generatedCode.remove(element); 92 universe.generatedCode.remove(element);
126 universe.generatedBailoutCode.remove(element); 93 universe.generatedBailoutCode.remove(element);
127 addToWorkList(element); 94 addToWorkList(element);
128 } 95 }
129 96
130 void registerRecompilationCandidate(Element element,
131 [TreeElements elements]) {
132 if (queueIsClosed) {
133 compiler.internalErrorOnElement(element, "Work list is closed.");
134 }
135 recompilationCandidates.add(element, elements);
136 }
137
138 void registerInstantiatedClass(ClassElement cls) { 97 void registerInstantiatedClass(ClassElement cls) {
139 if (cls.isInterface()) { 98 if (cls.isInterface()) {
140 compiler.internalErrorOnElement( 99 compiler.internalErrorOnElement(
141 // Use the current element, as this is where cls is referenced from. 100 // Use the current element, as this is where cls is referenced from.
142 compiler.currentElement, 101 compiler.currentElement,
143 'Expected a class, but $cls is an interface.'); 102 'Expected a class, but $cls is an interface.');
144 } 103 }
145 universe.instantiatedClasses.add(cls); 104 universe.instantiatedClasses.add(cls);
146 onRegisterInstantiatedClass(cls); 105 onRegisterInstantiatedClass(cls);
147 } 106 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 250 }
292 251
293 void handleUnseenSelector(SourceString methodName, Selector selector) { 252 void handleUnseenSelector(SourceString methodName, Selector selector) {
294 processInstanceMembers(methodName, (Element member) { 253 processInstanceMembers(methodName, (Element member) {
295 if (selector.applies(member, compiler)) { 254 if (selector.applies(member, compiler)) {
296 addToWorkList(member); 255 addToWorkList(member);
297 return true; 256 return true;
298 } 257 }
299 return false; 258 return false;
300 }); 259 });
260 // TODO(sgjesse): Add subscription to the enqueuer to deliver this
261 // information to the JavaScript backend instead of this hardcoded hack.
262 if (compiler.backend is js_backend.JavaScriptBackend) {
263 compiler.backend.addedDynamicSetter(selector);
ngeoffray 2012/09/20 14:43:01 I don't understand why you have to do that here. I
Søren Gjesse 2012/09/21 13:49:44 Having it here ensures that we get just one call w
264 }
301 } 265 }
302 266
303 void registerStaticUse(Element element) { 267 void registerStaticUse(Element element) {
304 if (element !== null) addToWorkList(element); 268 if (element !== null) addToWorkList(element);
305 } 269 }
306 270
307 void registerGetOfStaticFunction(FunctionElement element) { 271 void registerGetOfStaticFunction(FunctionElement element) {
308 registerStaticUse(element); 272 registerStaticUse(element);
309 universe.staticFunctionsNeedingGetter.add(element); 273 universe.staticFunctionsNeedingGetter.add(element);
310 } 274 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 void registerIsCheck(DartType type) { 315 void registerIsCheck(DartType type) {
352 universe.isChecks.add(type); 316 universe.isChecks.add(type);
353 } 317 }
354 318
355 void forEach(f(WorkItem work)) { 319 void forEach(f(WorkItem work)) {
356 while (!queue.isEmpty()) { 320 while (!queue.isEmpty()) {
357 f(queue.removeLast()); // TODO(kasperl): Why isn't this removeFirst? 321 f(queue.removeLast()); // TODO(kasperl): Why isn't this removeFirst?
358 } 322 }
359 } 323 }
360 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698