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 { | 20 class RecompilationQueue { |
| 21 final Queue<WorkItem> queue; | 21 final Queue<WorkItem> queue; |
| 22 final Set<Element> queueElements; | 22 final Set<Element> queueElements; |
| 23 int processed = 0; | |
| 23 | 24 |
| 24 RecompilationQueue() | 25 RecompilationQueue() |
| 25 : queue = new Queue<WorkItem>(), | 26 : queue = new Queue<WorkItem>(), |
| 26 queueElements = new Set<Element>(); | 27 queueElements = new Set<Element>(); |
| 27 | 28 |
| 28 void add(Element element, TreeElements elements) { | 29 void add(Element element, TreeElements elements) { |
| 29 if (queueElements.contains(element)) return; | 30 if (queueElements.contains(element)) return; |
| 30 // TODO(sgjesse): Make this handle constructor bodies as well. | 31 // TODO(sgjesse): Make this handle constructor bodies as well. |
| 31 if (element.kind !== ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 32 if (element.kind !== ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 32 queueElements.add(element); | 33 queueElements.add(element); |
| 33 queue.add(new WorkItem(element, elements)); | 34 queue.add(new WorkItem(element, elements)); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 37 int get length() => queue.length; | 38 int get length() => queue.length; |
| 38 | 39 |
| 39 bool isEmpty() => queue.isEmpty(); | 40 bool isEmpty() => queue.isEmpty(); |
| 40 | 41 |
| 41 WorkItem next() { | 42 WorkItem next() { |
| 42 WorkItem item = queue.removeLast(); | 43 WorkItem item = queue.removeLast(); |
| 43 queueElements.remove(item.element); | 44 queueElements.remove(item.element); |
| 45 processed++; | |
| 44 return item; | 46 return item; |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 | 49 |
| 48 class Enqueuer { | 50 class Enqueuer { |
| 49 final Compiler compiler; // TODO(ahe): Remove this dependency. | 51 final Compiler compiler; // TODO(ahe): Remove this dependency. |
| 50 final Map<String, Link<Element>> instanceMembersByName; | 52 final Map<String, Link<Element>> instanceMembersByName; |
| 51 final Set<ClassElement> seenClasses; | 53 final Set<ClassElement> seenClasses; |
| 52 final Universe universe; | 54 final Universe universe; |
| 53 final Queue<WorkItem> queue; | 55 final Queue<WorkItem> queue; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 | 69 |
| 68 bool get isResolutionQueue() => compiler.enqueuer.resolution === this; | 70 bool get isResolutionQueue() => compiler.enqueuer.resolution === this; |
| 69 | 71 |
| 70 TreeElements getCachedElements(Element element) { | 72 TreeElements getCachedElements(Element element) { |
| 71 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); | 73 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); |
| 72 return compiler.enqueuer.resolution.resolvedElements[owner]; | 74 return compiler.enqueuer.resolution.resolvedElements[owner]; |
| 73 } | 75 } |
| 74 | 76 |
| 75 void addToWorkList(Element element, [TreeElements elements]) { | 77 void addToWorkList(Element element, [TreeElements elements]) { |
| 76 if (element.isForeign()) return; | 78 if (element.isForeign()) return; |
| 77 if (compiler.pass == 2) return; | 79 if (compiler.phase == Compiler.PHASE_RECOMPILING) return; |
| 78 if (queueIsClosed) { | 80 if (queueIsClosed) { |
| 79 if (isResolutionQueue && getCachedElements(element) !== null) return; | 81 if (isResolutionQueue && getCachedElements(element) !== null) return; |
| 80 compiler.internalErrorOnElement(element, "Work list is closed."); | 82 compiler.internalErrorOnElement(element, "Work list is closed."); |
| 81 } | 83 } |
| 82 if (!isResolutionQueue && | 84 if (!isResolutionQueue && |
| 83 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { | 85 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 84 registerInstantiatedClass(element.enclosingElement); | 86 registerInstantiatedClass(element.enclosingElement); |
| 85 } | 87 } |
| 86 if (elements === null) { | 88 if (elements === null) { |
| 87 elements = getCachedElements(element); | 89 elements = getCachedElements(element); |
| 88 } | 90 } |
| 89 queue.add(new WorkItem(element, elements)); | 91 queue.add(new WorkItem(element, elements)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 bool canBeRecompiled(Element element) { | 94 bool canBeRecompiled(Element element) { |
| 93 // 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 |
| 94 // 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 |
| 95 // 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 |
| 96 // function). | 98 // function). |
| 97 var closure = const SourceString("Closure"); | 99 var closure = const SourceString("Closure"); |
| 98 return element.isMember() && element.getEnclosingClass().name != closure; | 100 return element.isMember() && |
| 101 element.getEnclosingClass() != compiler.closureClass; | |
|
Søren Gjesse
2012/06/18 07:00:29
Turned out that comparing with compiler.closureCla
ahe
2012/06/18 07:38:50
It MUST work. If it doesn't, then something is wro
Søren Gjesse
2012/06/18 07:44:10
Then something is wrong. Comparing with compiler.c
ahe
2012/06/18 07:55:00
I don't know. All I know is testing for names does
| |
| 99 } | 102 } |
| 100 | 103 |
| 101 void registerRecompilationCandidate(Element element, | 104 void registerRecompilationCandidate(Element element, |
| 102 [TreeElements elements]) { | 105 [TreeElements elements]) { |
| 103 if (!canBeRecompiled(element)) return; | 106 if (!canBeRecompiled(element)) return; |
| 104 if (queueIsClosed) { | 107 if (queueIsClosed) { |
| 105 compiler.internalErrorOnElement(element, "Work list is closed."); | 108 compiler.internalErrorOnElement(element, "Work list is closed."); |
| 106 } | 109 } |
| 107 recompilationCandidates.add(element, elements); | 110 recompilationCandidates.add(element, elements); |
| 108 } | 111 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 void registerIsCheck(Element element) { | 318 void registerIsCheck(Element element) { |
| 316 universe.isChecks.add(element); | 319 universe.isChecks.add(element); |
| 317 } | 320 } |
| 318 | 321 |
| 319 void forEach(f(WorkItem work)) { | 322 void forEach(f(WorkItem work)) { |
| 320 while (!queue.isEmpty()) { | 323 while (!queue.isEmpty()) { |
| 321 f(queue.removeLast()); | 324 f(queue.removeLast()); |
| 322 } | 325 } |
| 323 } | 326 } |
| 324 } | 327 } |
| OLD | NEW |