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

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

Issue 10917285: Stub implementation of patch invariants for the patch refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments 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('codegen enqueuer', compiler,
13 compiler.backend.createItemCompilationContext), 13 compiler.backend.createItemCompilationContext),
14 resolution = new Enqueuer(compiler, 14 resolution = new Enqueuer('resolution 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 { 22 class RecompilationQueue {
23 final Function itemCompilationContextCreator; 23 final Function itemCompilationContextCreator;
24 final Queue<WorkItem> queue; 24 final Queue<WorkItem> queue;
(...skipping 17 matching lines...) Expand all
42 42
43 WorkItem next() { 43 WorkItem next() {
44 WorkItem item = queue.removeLast(); 44 WorkItem item = queue.removeLast();
45 queueElements.remove(item.element); 45 queueElements.remove(item.element);
46 processed++; 46 processed++;
47 return item; 47 return item;
48 } 48 }
49 } 49 }
50 50
51 class Enqueuer { 51 class Enqueuer {
52 final String name;
52 final Compiler compiler; // TODO(ahe): Remove this dependency. 53 final Compiler compiler; // TODO(ahe): Remove this dependency.
53 final Function itemCompilationContextCreator; 54 final Function itemCompilationContextCreator;
54 final Map<String, Link<Element>> instanceMembersByName; 55 final Map<String, Link<Element>> instanceMembersByName;
55 final Set<ClassElement> seenClasses; 56 final Set<ClassElement> seenClasses;
56 final Universe universe; 57 final Universe universe;
57 final Queue<WorkItem> queue; 58 final Queue<WorkItem> queue;
59 // Invariant: Key elements are declarations.
58 final Map<Element, TreeElements> resolvedElements; 60 final Map<Element, TreeElements> resolvedElements;
59 final RecompilationQueue recompilationCandidates; 61 final RecompilationQueue recompilationCandidates;
60 62
61 bool queueIsClosed = false; 63 bool queueIsClosed = false;
62 EnqueueTask task; 64 EnqueueTask task;
63 65
64 Enqueuer(this.compiler, 66 Enqueuer(this.name, this.compiler,
65 ItemCompilationContext itemCompilationContextCreator()) 67 ItemCompilationContext itemCompilationContextCreator())
66 : this.itemCompilationContextCreator = itemCompilationContextCreator, 68 : this.itemCompilationContextCreator = itemCompilationContextCreator,
67 instanceMembersByName = new Map<String, Link<Element>>(), 69 instanceMembersByName = new Map<String, Link<Element>>(),
68 seenClasses = new Set<ClassElement>(), 70 seenClasses = new Set<ClassElement>(),
69 universe = new Universe(), 71 universe = new Universe(),
70 queue = new Queue<WorkItem>(), 72 queue = new Queue<WorkItem>(),
71 resolvedElements = new Map<Element, TreeElements>(), 73 resolvedElements = new Map<Element, TreeElements>(),
72 recompilationCandidates = 74 recompilationCandidates =
73 new RecompilationQueue(itemCompilationContextCreator); 75 new RecompilationQueue(itemCompilationContextCreator);
74 76
75 bool get isResolutionQueue => compiler.enqueuer.resolution === this; 77 bool get isResolutionQueue => compiler.enqueuer.resolution === this;
76 78
77 TreeElements getCachedElements(Element element) { 79 TreeElements getCachedElements(Element element) {
78 // TODO(ngeoffray): Get rid of this check. 80 // TODO(ngeoffray): Get rid of this check.
79 if (element.enclosingElement.isClosure()) { 81 if (element.enclosingElement.isClosure()) {
80 closureMapping.ClosureClassElement cls = element.enclosingElement; 82 closureMapping.ClosureClassElement cls = element.enclosingElement;
81 element = cls.methodElement; 83 element = cls.methodElement;
82 } 84 }
83 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); 85 Element owner = element.getOutermostEnclosingMemberOrTopLevel();
84 return compiler.enqueuer.resolution.resolvedElements[owner]; 86 return compiler.enqueuer.resolution.resolvedElements[owner.declaration];
85 } 87 }
86 88
87 String lookupCode(Element element) => 89 /**
88 universe.generatedCode[element].toString(); 90 * Documentation wanted -- johnniwinther
91 *
92 * Invariant: [element] must be a declaration element.
93 */
94 String lookupCode(Element element) {
95 assert(invariant(element, element.isDeclaration));
96 return universe.generatedCode[element].toString();
97 }
89 98
99 /**
100 * Documentation wanted -- johnniwinther
101 *
102 * Invariant: [element] must be a declaration element.
103 */
90 void addToWorkList(Element element, [TreeElements elements]) { 104 void addToWorkList(Element element, [TreeElements elements]) {
105 assert(invariant(element, element.isDeclaration));
91 if (element.isForeign()) return; 106 if (element.isForeign()) return;
92 if (compiler.phase == Compiler.PHASE_RECOMPILING) return; 107 if (compiler.phase == Compiler.PHASE_RECOMPILING) return;
93 if (queueIsClosed) { 108 if (queueIsClosed) {
94 if (isResolutionQueue && getCachedElements(element) !== null) return; 109 if (isResolutionQueue && getCachedElements(element) !== null) return;
95 compiler.internalErrorOnElement(element, "Work list is closed."); 110 compiler.internalErrorOnElement(element, "Work list is closed.");
96 } 111 }
97 if (!isResolutionQueue && 112 if (!isResolutionQueue &&
98 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 113 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
99 registerInstantiatedClass(element.getEnclosingClass()); 114 registerInstantiatedClass(element.getEnclosingClass());
100 } 115 }
(...skipping 13 matching lines...) Expand all
114 129
115 // Enable isolate support if we start using something from the 130 // Enable isolate support if we start using something from the
116 // isolate library. 131 // isolate library.
117 LibraryElement library = element.getLibrary(); 132 LibraryElement library = element.getLibrary();
118 if (!compiler.hasIsolateSupport() 133 if (!compiler.hasIsolateSupport()
119 && library.uri.toString() == 'dart:isolate') { 134 && library.uri.toString() == 'dart:isolate') {
120 compiler.enableIsolateSupport(library); 135 compiler.enableIsolateSupport(library);
121 } 136 }
122 } 137 }
123 138
139 /**
140 * Documentation wanted -- johnniwinther
141 *
142 * Invariant: [element] must be an declaration element.
143 */
124 void eagerRecompile(Element element) { 144 void eagerRecompile(Element element) {
145 assert(invariant(element, element.isDeclaration));
125 universe.generatedCode.remove(element); 146 universe.generatedCode.remove(element);
126 universe.generatedBailoutCode.remove(element); 147 universe.generatedBailoutCode.remove(element);
127 addToWorkList(element); 148 addToWorkList(element);
128 } 149 }
129 150
130 void registerRecompilationCandidate(Element element, 151 void registerRecompilationCandidate(Element element,
131 [TreeElements elements]) { 152 [TreeElements elements]) {
132 if (queueIsClosed) { 153 if (queueIsClosed) {
133 compiler.internalErrorOnElement(element, "Work list is closed."); 154 compiler.internalErrorOnElement(element, "$name work list is closed.");
134 } 155 }
135 recompilationCandidates.add(element, elements); 156 recompilationCandidates.add(element, elements);
136 } 157 }
137 158
138 void registerInstantiatedClass(ClassElement cls) { 159 void registerInstantiatedClass(ClassElement cls) {
139 if (cls.isInterface()) { 160 if (cls.isInterface()) {
140 compiler.internalErrorOnElement( 161 compiler.internalErrorOnElement(
141 // Use the current element, as this is where cls is referenced from. 162 // Use the current element, as this is where cls is referenced from.
142 compiler.currentElement, 163 compiler.currentElement,
143 'Expected a class, but $cls is an interface.'); 164 'Expected a class, but $cls is an interface.');
(...skipping 13 matching lines...) Expand all
157 } 178 }
158 } 179 }
159 }); 180 });
160 return true; 181 return true;
161 } 182 }
162 183
163 void processInstantiatedClass(ClassElement cls) { 184 void processInstantiatedClass(ClassElement cls) {
164 cls.localMembers.forEach(processInstantiatedClassMember); 185 cls.localMembers.forEach(processInstantiatedClassMember);
165 } 186 }
166 187
188 /**
189 * Documentation wanted -- johnniwinther
190 */
167 void processInstantiatedClassMember(Element member) { 191 void processInstantiatedClassMember(Element member) {
192 assert(invariant(member, member.isDeclaration));
168 if (universe.generatedCode.containsKey(member)) return; 193 if (universe.generatedCode.containsKey(member)) return;
169 if (resolvedElements[member] !== null) return; 194 if (resolvedElements[member] !== null) return;
170 if (!member.isInstanceMember()) return; 195 if (!member.isInstanceMember()) return;
171 if (member.isField()) return; 196 if (member.isField()) return;
172 197
173 String memberName = member.name.slowToString(); 198 String memberName = member.name.slowToString();
174 Link<Element> members = instanceMembersByName.putIfAbsent( 199 Link<Element> members = instanceMembersByName.putIfAbsent(
175 memberName, () => const EmptyLink<Element>()); 200 memberName, () => const EmptyLink<Element>());
176 instanceMembersByName[memberName] = members.prepend(member); 201 instanceMembersByName[memberName] = members.prepend(member);
177 202
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 void handleUnseenSelector(SourceString methodName, Selector selector) { 318 void handleUnseenSelector(SourceString methodName, Selector selector) {
294 processInstanceMembers(methodName, (Element member) { 319 processInstanceMembers(methodName, (Element member) {
295 if (selector.applies(member, compiler)) { 320 if (selector.applies(member, compiler)) {
296 addToWorkList(member); 321 addToWorkList(member);
297 return true; 322 return true;
298 } 323 }
299 return false; 324 return false;
300 }); 325 });
301 } 326 }
302 327
328 /**
329 * Documentation wanted -- johnniwinther
330 *
331 * Invariant: [element] must be a declaration element.
332 */
303 void registerStaticUse(Element element) { 333 void registerStaticUse(Element element) {
304 if (element !== null) addToWorkList(element); 334 if (element == null) return;
335 assert(invariant(element, element.isDeclaration));
336 addToWorkList(element);
305 } 337 }
306 338
307 void registerGetOfStaticFunction(FunctionElement element) { 339 void registerGetOfStaticFunction(FunctionElement element) {
308 registerStaticUse(element); 340 registerStaticUse(element);
309 universe.staticFunctionsNeedingGetter.add(element); 341 universe.staticFunctionsNeedingGetter.add(element);
310 } 342 }
311 343
312 void registerDynamicInvocation(SourceString methodName, Selector selector) { 344 void registerDynamicInvocation(SourceString methodName, Selector selector) {
313 assert(selector !== null); 345 assert(selector !== null);
314 registerInvocation(methodName, selector); 346 registerInvocation(methodName, selector);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 382
351 void registerIsCheck(DartType type) { 383 void registerIsCheck(DartType type) {
352 universe.isChecks.add(type); 384 universe.isChecks.add(type);
353 } 385 }
354 386
355 void forEach(f(WorkItem work)) { 387 void forEach(f(WorkItem work)) {
356 while (!queue.isEmpty()) { 388 while (!queue.isEmpty()) {
357 f(queue.removeLast()); // TODO(kasperl): Why isn't this removeFirst? 389 f(queue.removeLast()); // TODO(kasperl): Why isn't this removeFirst?
358 } 390 }
359 } 391 }
392
393 String toString() => 'Enqueuer($name)';
360 } 394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698