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

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

Issue 10694091: Collect the actual types for all field setters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 abstract List<CompilerTask> get tasks(); 51 abstract List<CompilerTask> get tasks();
52 } 52 }
53 53
54 class JavaScriptBackend extends Backend { 54 class JavaScriptBackend extends Backend {
55 SsaBuilderTask builder; 55 SsaBuilderTask builder;
56 SsaOptimizerTask optimizer; 56 SsaOptimizerTask optimizer;
57 SsaCodeGeneratorTask generator; 57 SsaCodeGeneratorTask generator;
58 CodeEmitterTask emitter; 58 CodeEmitterTask emitter;
59 final Map<Element, Map<Element, HType>> fieldInitializers; 59 final Map<Element, Map<Element, HType>> fieldInitializers;
60 final Map<Element, Map<Element, HType>> fieldConstructorSetters; 60 final Map<Element, Map<Element, HType>> fieldConstructorSetters;
61 final Map<Element, Map<Element, bool>> fieldIntegerSetters; 61 final Map<Element, Map<Element, HType>> fieldSettersType;
62 62
63 List<CompilerTask> get tasks() { 63 List<CompilerTask> get tasks() {
64 return <CompilerTask>[builder, optimizer, generator, emitter]; 64 return <CompilerTask>[builder, optimizer, generator, emitter];
65 } 65 }
66 66
67 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 67 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
68 : emitter = new CodeEmitterTask(compiler, generateSourceMap), 68 : emitter = new CodeEmitterTask(compiler, generateSourceMap),
69 fieldInitializers = new Map<Element, Map<Element, HType>>(), 69 fieldInitializers = new Map<Element, Map<Element, HType>>(),
70 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(), 70 fieldConstructorSetters = new Map<Element, Map<Element, HType>>(),
71 fieldIntegerSetters = new Map<Element, Map<Element, bool>>(), 71 fieldSettersType = new Map<Element, Map<Element, HType>>(),
72 super(compiler) { 72 super(compiler) {
73 builder = new SsaBuilderTask(this); 73 builder = new SsaBuilderTask(this);
74 optimizer = new SsaOptimizerTask(this); 74 optimizer = new SsaOptimizerTask(this);
75 generator = new SsaCodeGeneratorTask(this); 75 generator = new SsaCodeGeneratorTask(this);
76 } 76 }
77 77
78 void enqueueHelpers(Enqueuer world) { 78 void enqueueHelpers(Enqueuer world) {
79 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world); 79 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world);
80 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world); 80 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world);
81 for (var helper in [const SourceString('Closure'), 81 for (var helper in [const SourceString('Closure'),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return HType.UNKNOWN; 183 return HType.UNKNOWN;
184 } 184 }
185 } else if (fieldInitializers.containsKey(field.enclosingElement)) { 185 } else if (fieldInitializers.containsKey(field.enclosingElement)) {
186 HType type = fieldInitializers[field.enclosingElement][field]; 186 HType type = fieldInitializers[field.enclosingElement][field];
187 return type == null ? HType.UNKNOWN : type; 187 return type == null ? HType.UNKNOWN : type;
188 } else { 188 } else {
189 return HType.UNKNOWN; 189 return HType.UNKNOWN;
190 } 190 }
191 } 191 }
192 192
193 void updateFieldIntegerSetters(Element field, bool isInteger) { 193 void updateFieldSetters(Element field, HType type) {
194 assert(field.isField()); 194 assert(field.isField());
195 assert(field.enclosingElement.isClass()); 195 assert(field.enclosingElement.isClass());
196 Map<Element, bool> fields = 196 Map<Element, bool> fields =
197 fieldIntegerSetters.putIfAbsent( 197 fieldSettersType.putIfAbsent(
198 field.enclosingElement, () => new Map<Element, bool>()); 198 field.enclosingElement, () => new Map<Element, HType>());
199 if (!fields.containsKey(field)) { 199 if (!fields.containsKey(field)) {
200 fields[field] = isInteger; 200 fields[field] = type;
201 } else { 201 } else {
202 fields[field] = fields[field] && isInteger; 202 fields[field] = fields[field].union(type);
203 } 203 }
204 } 204 }
205 205
206 // Returns whether nothing but setters setting the field to an integer have 206 // Returns whether nothing but setters setting the field to an integer have
207 // been seen during compilation so far. 207 // been seen during compilation so far.
208 bool onlyFieldIntegerSettersSoFar(Element field) { 208 HType fieldSettersTypeSoFar(Element field) {
209 assert(field.isField()); 209 assert(field.isField());
210 assert(field.enclosingElement.isClass()); 210 assert(field.enclosingElement.isClass());
211 if (!fieldIntegerSetters.containsKey(field.enclosingElement)) return true; 211 if (!fieldSettersType.containsKey(field.enclosingElement)) {
212 Map<Element, bool> fields = fieldIntegerSetters[field.enclosingElement]; 212 return HType.UNKNOWN;
213 if (!fields.containsKey(field)) return false; 213 }
214 Map<Element, Htype> fields = fieldSettersType[field.enclosingElement];
215 if (!fields.containsKey(field)) return HType.UNKNOWN;
214 return fields[field]; 216 return fields[field];
215 } 217 }
216 } 218 }
217 219
218 class Compiler implements DiagnosticListener { 220 class Compiler implements DiagnosticListener {
219 final Map<String, LibraryElement> libraries; 221 final Map<String, LibraryElement> libraries;
220 int nextFreeClassId = 0; 222 int nextFreeClassId = 0;
221 World world; 223 World world;
222 String assembledCode; 224 String assembledCode;
223 Namer namer; 225 Namer namer;
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 f(int beginOffset, int endOffset)) { 994 f(int beginOffset, int endOffset)) {
993 final beginOffset = begin.charOffset; 995 final beginOffset = begin.charOffset;
994 final endOffset = end.charOffset + end.slowCharCount; 996 final endOffset = end.charOffset + end.slowCharCount;
995 997
996 // [begin] and [end] might be the same for the same empty token. This 998 // [begin] and [end] might be the same for the same empty token. This
997 // happens for instance when scanning '$$'. 999 // happens for instance when scanning '$$'.
998 assert(endOffset >= beginOffset); 1000 assert(endOffset >= beginOffset);
999 return f(beginOffset, endOffset); 1001 return f(beginOffset, endOffset);
1000 } 1002 }
1001 } 1003 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/codegen.dart » ('j') | lib/compiler/implementation/ssa/optimize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698