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

Side by Side Diff: lib/compiler/implementation/js_backend/backend.dart

Issue 10854140: Fix type inference for self-recursive functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add method for retreiving generated code for dart2js tests 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 InvocationInfo { 5 class InvocationInfo {
6 int parameterCount; 6 int parameterCount;
7 List<HType> providedTypes; 7 List<HType> providedTypes;
8 List<Element> compiledFunctions; 8 List<Element> compiledFunctions;
9 9
10 InvocationInfo(List<HType> types) 10 InvocationInfo(List<HType> types)
(...skipping 13 matching lines...) Expand all
24 SsaBuilderTask builder; 24 SsaBuilderTask builder;
25 SsaOptimizerTask optimizer; 25 SsaOptimizerTask optimizer;
26 SsaCodeGeneratorTask generator; 26 SsaCodeGeneratorTask generator;
27 CodeEmitterTask emitter; 27 CodeEmitterTask emitter;
28 final Map<Element, Map<Element, HType>> fieldInitializers; 28 final Map<Element, Map<Element, HType>> fieldInitializers;
29 final Map<Element, Map<Element, HType>> fieldConstructorSetters; 29 final Map<Element, Map<Element, HType>> fieldConstructorSetters;
30 final Map<Element, Map<Element, HType>> fieldSettersType; 30 final Map<Element, Map<Element, HType>> fieldSettersType;
31 31
32 final Map<SourceString, Map<Selector, InvocationInfo>> invocationInfo; 32 final Map<SourceString, Map<Selector, InvocationInfo>> invocationInfo;
33 33
34 final List<Element> invalidateAfterCodegen;
35
34 List<CompilerTask> get tasks() { 36 List<CompilerTask> get tasks() {
35 return <CompilerTask>[builder, optimizer, generator, emitter]; 37 return <CompilerTask>[builder, optimizer, generator, emitter];
36 } 38 }
37 39
38 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 40 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
39 : emitter = new CodeEmitterTask(compiler, generateSourceMap), 41 : emitter = new CodeEmitterTask(compiler, generateSourceMap),
40 fieldInitializers = new Map<Element, Map<Element, HType>>(), 42 fieldInitializers = new Map<Element, Map<Element, HType>>(),
41 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(), 43 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(),
42 fieldSettersType = new Map<Element, Map<Element, HType>>(), 44 fieldSettersType = new Map<Element, Map<Element, HType>>(),
43 invocationInfo = new Map<SourceString, Map<Selector, InvocationInfo>>(), 45 invocationInfo = new Map<SourceString, Map<Selector, InvocationInfo>>(),
46 invalidateAfterCodegen = new List<Element>(),
44 super(compiler) { 47 super(compiler) {
45 builder = new SsaBuilderTask(this); 48 builder = new SsaBuilderTask(this);
46 optimizer = new SsaOptimizerTask(this); 49 optimizer = new SsaOptimizerTask(this);
47 generator = new SsaCodeGeneratorTask(this); 50 generator = new SsaCodeGeneratorTask(this);
48 } 51 }
49 52
50 void enqueueHelpers(Enqueuer world) { 53 void enqueueHelpers(Enqueuer world) {
51 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world); 54 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world);
52 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world); 55 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world);
53 for (var helper in [const SourceString('Closure'), 56 for (var helper in [const SourceString('Closure'),
54 const SourceString('ConstantMap'), 57 const SourceString('ConstantMap'),
55 const SourceString('ConstantProtoMap')]) { 58 const SourceString('ConstantProtoMap')]) {
56 var e = compiler.findHelper(helper); 59 var e = compiler.findHelper(helper);
57 if (e !== null) world.registerInstantiatedClass(e); 60 if (e !== null) world.registerInstantiatedClass(e);
58 } 61 }
59 } 62 }
60 63
61 CodeBuffer codegen(WorkItem work) { 64 void codegen(WorkItem work) {
62 HGraph graph = builder.build(work); 65 HGraph graph = builder.build(work);
63 optimizer.optimize(work, graph); 66 optimizer.optimize(work, graph);
64 if (work.allowSpeculativeOptimization 67 if (work.allowSpeculativeOptimization
65 && optimizer.trySpeculativeOptimizations(work, graph)) { 68 && optimizer.trySpeculativeOptimizations(work, graph)) {
66 CodeBuffer codeBuffer = generator.generateBailoutMethod(work, graph); 69 CodeBuffer codeBuffer = generator.generateBailoutMethod(work, graph);
67 compiler.codegenWorld.addBailoutCode(work, codeBuffer); 70 compiler.codegenWorld.addBailoutCode(work, codeBuffer);
68 optimizer.prepareForSpeculativeOptimizations(work, graph); 71 optimizer.prepareForSpeculativeOptimizations(work, graph);
69 optimizer.optimize(work, graph); 72 optimizer.optimize(work, graph);
70 } 73 }
71 return generator.generateMethod(work, graph); 74 CodeBuffer codeBuffer = generator.generateMethod(work, graph);
75 compiler.codegenWorld.addGeneratedCode(work, codeBuffer);
76 invalidateAfterCodegen.forEach(
77 compiler.enqueuer.codegen.eagerRecompile);
78 invalidateAfterCodegen.clear();
72 } 79 }
73 80
74 void processNativeClasses(Enqueuer world, 81 void processNativeClasses(Enqueuer world,
75 Collection<LibraryElement> libraries) { 82 Collection<LibraryElement> libraries) {
76 native.processNativeClasses(world, emitter, libraries); 83 native.processNativeClasses(world, emitter, libraries);
77 } 84 }
78 85
79 void assembleProgram() { 86 void assembleProgram() {
80 emitter.assembleProgram(); 87 emitter.assembleProgram();
81 } 88 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (newType != types[i]) { 209 if (newType != types[i]) {
203 typesChanged = true; 210 typesChanged = true;
204 types[i] = newType; 211 types[i] = newType;
205 } 212 }
206 if (types[i] != HType.UNKNOWN) allUnknown = false; 213 if (types[i] != HType.UNKNOWN) allUnknown = false;
207 } 214 }
208 // If the provided types change we need to recompile all functions which 215 // If the provided types change we need to recompile all functions which
209 // have been compiled under the now invalidated assumptions. 216 // have been compiled under the now invalidated assumptions.
210 if (typesChanged && info.compiledFunctions.length != 0) { 217 if (typesChanged && info.compiledFunctions.length != 0) {
211 if (compiler.phase == Compiler.PHASE_COMPILING) { 218 if (compiler.phase == Compiler.PHASE_COMPILING) {
212 info.compiledFunctions.forEach( 219 info.compiledFunctions.forEach(invalidateAfterCodegen.add);
213 compiler.enqueuer.codegen.eagerRecompile);
214 info.compiledFunctions.clear(); 220 info.compiledFunctions.clear();
215 } 221 }
216 } 222 }
217 // If all information is lost no need to keep it around. 223 // If all information is lost no need to keep it around.
218 if (allUnknown) info.clearTypeInformation(); 224 if (allUnknown) info.clearTypeInformation();
219 } else { 225 } else {
220 // Gather the type information provided. If the types contains no useful 226 // Gather the type information provided. If the types contains no useful
221 // information there is no need to actually store them. 227 // information there is no need to actually store them.
222 bool allUnknown = true; 228 bool allUnknown = true;
223 for (int i = 1; i < node.inputs.length; i++) { 229 for (int i = 1; i < node.inputs.length; i++) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (foundCount == 1 && found.hasTypeInformation) { 270 if (foundCount == 1 && found.hasTypeInformation) {
265 FunctionSignature signature = element.computeSignature(compiler); 271 FunctionSignature signature = element.computeSignature(compiler);
266 if (signature.parameterCount == found.parameterCount) { 272 if (signature.parameterCount == found.parameterCount) {
267 found.addCompiledFunction(element); 273 found.addCompiledFunction(element);
268 return found.providedTypes; 274 return found.providedTypes;
269 } 275 }
270 } 276 }
271 return null; 277 return null;
272 } 278 }
273 } 279 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | tests/compiler/dart2js/call_site_type_inferer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698