Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
|
ngeoffray
2012/06/14 12:42:24
Why don't we handle them right now?
Søren Gjesse
2012/06/15 09:25:02
I can't remember the exact problem. I will get bac
| |
| 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 bool canBeRecompiled(Element element) { | |
| 92 // Only member functions can be recompiled. An exception to this is members | |
|
ngeoffray
2012/06/14 12:42:24
Why not static methods?
Søren Gjesse
2012/06/15 09:25:02
Doesn't isMember cover static functions as well? A
ngeoffray
2012/06/15 20:06:14
you are right that isMember covers static function
| |
| 93 // 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 | |
| 95 // function). | |
| 96 var closure = const SourceString("Closure"); | |
| 97 return element.isMember() && element.getEnclosingClass().name != closure; | |
|
ahe
2012/06/14 13:23:54
This should be:
element.getEnclosingClass() !== c
Søren Gjesse
2012/06/15 09:25:02
Done.
| |
| 98 } | |
| 99 | |
| 100 void registerRecompilationCandidate(Element element, | |
| 101 [TreeElements elements]) { | |
| 102 if (!canBeRecompiled(element)) return; | |
| 103 if (queueIsClosed) { | |
| 104 compiler.internalErrorOnElement(element, "Work list is closed."); | |
| 105 } | |
| 106 recompilationCandidates.add(element, elements); | |
| 107 } | |
| 108 | |
| 59 void registerInstantiatedClass(ClassElement cls) { | 109 void registerInstantiatedClass(ClassElement cls) { |
| 60 if (cls.isInterface()) { | 110 if (cls.isInterface()) { |
| 61 compiler.internalErrorOnElement( | 111 compiler.internalErrorOnElement( |
| 62 // Use the current element, as this is where cls is referenced from. | 112 // Use the current element, as this is where cls is referenced from. |
| 63 compiler.currentElement, | 113 compiler.currentElement, |
| 64 'Expected a class, but $cls is an interface.'); | 114 'Expected a class, but $cls is an interface.'); |
| 65 } | 115 } |
| 66 universe.instantiatedClasses.add(cls); | 116 universe.instantiatedClasses.add(cls); |
| 67 onRegisterInstantiatedClass(cls); | 117 onRegisterInstantiatedClass(cls); |
| 68 } | 118 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 void registerIsCheck(Element element) { | 314 void registerIsCheck(Element element) { |
| 265 universe.isChecks.add(element); | 315 universe.isChecks.add(element); |
| 266 } | 316 } |
| 267 | 317 |
| 268 void forEach(f(WorkItem work)) { | 318 void forEach(f(WorkItem work)) { |
| 269 while (!queue.isEmpty()) { | 319 while (!queue.isEmpty()) { |
| 270 f(queue.removeLast()); | 320 f(queue.removeLast()); |
| 271 } | 321 } |
| 272 } | 322 } |
| 273 } | 323 } |
| OLD | NEW |