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

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

Issue 10700122: Generalize the use of type information for setters and initializers (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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 Map<Element, HType> fields = 114 Map<Element, HType> fields =
115 fieldInitializers.putIfAbsent( 115 fieldInitializers.putIfAbsent(
116 field.enclosingElement, () => new Map<Element, HType>()); 116 field.enclosingElement, () => new Map<Element, HType>());
117 if (!fields.containsKey(field)) { 117 if (!fields.containsKey(field)) {
118 fields[field] = propagatedType; 118 fields[field] = propagatedType;
119 } else { 119 } else {
120 fields[field] = fields[field].union(propagatedType); 120 fields[field] = fields[field].union(propagatedType);
121 } 121 }
122 } 122 }
123 123
124 bool couldHaveFieldSingleTypeInitializers(Element field, 124 HType typeFromInitializersSoFar(Element field) {
125 HType requestedType) {
126 assert(field.isField()); 125 assert(field.isField());
127 assert(field.enclosingElement.isClass()); 126 assert(field.enclosingElement.isClass());
128 // If there is no information on the initializer it might still be 127 if (!fieldInitializers.containsKey(field.enclosingElement)) {
129 // initialized to integers only. 128 return HType.UNKNOWN;
130 if (!fieldInitializers.containsKey(field.enclosingElement)) return true; 129 }
131 Map<Element, HType> fields = fieldInitializers[field.enclosingElement]; 130 Map<Element, HType> fields = fieldInitializers[field.enclosingElement];
132 HType propagatedType = fields[field]; 131 return fields[field];
133 if (propagatedType == null) return true;
134 return propagatedType == requestedType;
135 }
136
137 bool hasFieldSingleTypeInitializers(Element field, HType requestedType) {
138 assert(field.isField());
139 assert(field.enclosingElement.isClass());
140 if (!fieldInitializers.containsKey(field.enclosingElement)) return false;
141 Map<Element, HType> fields = fieldInitializers[field.enclosingElement];
142 HType propagatedType = fields[field];
143 if (propagatedType == null) return false;
144 return propagatedType == requestedType;
145 } 132 }
146 133
147 void updateFieldConstructorSetters(Element field, HType type) { 134 void updateFieldConstructorSetters(Element field, HType type) {
148 assert(field.isField()); 135 assert(field.isField());
149 assert(field.enclosingElement.isClass()); 136 assert(field.enclosingElement.isClass());
150 Map<Element, HType> fields = 137 Map<Element, HType> fields =
151 fieldConstructorSetters.putIfAbsent( 138 fieldConstructorSetters.putIfAbsent(
152 field.enclosingElement, () => new Map<Element, HType>()); 139 field.enclosingElement, () => new Map<Element, HType>());
153 if (!fields.containsKey(field)) { 140 if (!fields.containsKey(field)) {
154 fields[field] = type; 141 fields[field] = type;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Map<Element, HType> fields = 183 Map<Element, HType> fields =
197 fieldSettersType.putIfAbsent( 184 fieldSettersType.putIfAbsent(
198 field.enclosingElement, () => new Map<Element, HType>()); 185 field.enclosingElement, () => new Map<Element, HType>());
199 if (!fields.containsKey(field)) { 186 if (!fields.containsKey(field)) {
200 fields[field] = type; 187 fields[field] = type;
201 } else { 188 } else {
202 fields[field] = fields[field].union(type); 189 fields[field] = fields[field].union(type);
203 } 190 }
204 } 191 }
205 192
206 // Returns whether nothing but setters setting the field to an integer have 193 // Returns the type that field setters are setting the field to based on what
207 // been seen during compilation so far. 194 // have been seen during compilation so far.
208 HType fieldSettersTypeSoFar(Element field) { 195 HType fieldSettersTypeSoFar(Element field) {
209 assert(field.isField()); 196 assert(field.isField());
210 assert(field.enclosingElement.isClass()); 197 assert(field.enclosingElement.isClass());
211 if (!fieldSettersType.containsKey(field.enclosingElement)) { 198 if (!fieldSettersType.containsKey(field.enclosingElement)) {
212 return HType.UNKNOWN; 199 return HType.UNKNOWN;
213 } 200 }
214 Map<Element, HType> fields = fieldSettersType[field.enclosingElement]; 201 Map<Element, HType> fields = fieldSettersType[field.enclosingElement];
215 if (!fields.containsKey(field)) return HType.UNKNOWN; 202 if (!fields.containsKey(field)) return HType.UNKNOWN;
216 return fields[field]; 203 return fields[field];
217 } 204 }
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 f(int beginOffset, int endOffset)) { 981 f(int beginOffset, int endOffset)) {
995 final beginOffset = begin.charOffset; 982 final beginOffset = begin.charOffset;
996 final endOffset = end.charOffset + end.slowCharCount; 983 final endOffset = end.charOffset + end.slowCharCount;
997 984
998 // [begin] and [end] might be the same for the same empty token. This 985 // [begin] and [end] might be the same for the same empty token. This
999 // happens for instance when scanning '$$'. 986 // happens for instance when scanning '$$'.
1000 assert(endOffset >= beginOffset); 987 assert(endOffset >= beginOffset);
1001 return f(beginOffset, endOffset); 988 return f(beginOffset, endOffset);
1002 } 989 }
1003 } 990 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/optimize.dart » ('j') | lib/compiler/implementation/ssa/optimize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698