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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
8 String get name; | 8 String get name; |
9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
10 } | 10 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 return node.inputs[1]; | 212 return node.inputs[1]; |
213 } | 213 } |
214 return node; | 214 return node; |
215 } | 215 } |
216 | 216 |
217 bool isFixedSizeListConstructor(HInvokeStatic node) { | 217 bool isFixedSizeListConstructor(HInvokeStatic node) { |
218 Element element = node.target.element; | 218 Element element = node.target.element; |
219 DartType defaultClass = compiler.listClass.defaultClass; | 219 DartType defaultClass = compiler.listClass.defaultClass; |
220 // TODO(ngeoffray): make sure that the only reason the List class is | 220 // TODO(ngeoffray): make sure that the only reason the List class is |
221 // not resolved is because it's not being used. | 221 // not resolved is because it's not being used. |
222 return element.isConstructor() | 222 if (defaultClass == null) return false; |
223 && defaultClass != null | 223 if (!element.isConstructor()) return false; |
224 && element.enclosingElement.declaration == defaultClass.element | 224 // TODO(ngeoffray): cache constructor. |
225 && node.inputs.length == 2 | 225 if (element.enclosingElement.declaration != defaultClass.element) { |
226 && node.inputs[1].isInteger(types); | 226 return false; |
| 227 } |
| 228 FunctionElement fixedLengthListConstructor = |
| 229 compiler.listClass.lookupConstructor( |
| 230 new Selector.callConstructor(const SourceString("fixedLength"), |
| 231 compiler.listClass.getLibrary())); |
| 232 return element == fixedLengthListConstructor.defaultImplementation; |
227 } | 233 } |
228 | 234 |
229 HInstruction visitInvokeStatic(HInvokeStatic node) { | 235 HInstruction visitInvokeStatic(HInvokeStatic node) { |
230 if (isFixedSizeListConstructor(node)) { | 236 if (isFixedSizeListConstructor(node)) { |
231 node.guaranteedType = HType.FIXED_ARRAY; | 237 node.guaranteedType = HType.FIXED_ARRAY; |
232 } | 238 } |
233 return node; | 239 return node; |
234 } | 240 } |
235 | 241 |
236 HInstruction visitInvokeDynamic(HInvokeDynamic node) { | 242 HInstruction visitInvokeDynamic(HInvokeDynamic node) { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 if (!receiverType.isUseful()) return null; | 558 if (!receiverType.isUseful()) return null; |
553 if (receiverType.canBeNull()) return null; | 559 if (receiverType.canBeNull()) return null; |
554 DartType type = receiverType.computeType(compiler); | 560 DartType type = receiverType.computeType(compiler); |
555 if (type == null) return null; | 561 if (type == null) return null; |
556 return compiler.world.locateSingleField(type, selector); | 562 return compiler.world.locateSingleField(type, selector); |
557 } | 563 } |
558 | 564 |
559 HInstruction visitFieldGet(HFieldGet node) { | 565 HInstruction visitFieldGet(HFieldGet node) { |
560 if (node.element == backend.jsArrayLength) { | 566 if (node.element == backend.jsArrayLength) { |
561 if (node.receiver is HInvokeStatic) { | 567 if (node.receiver is HInvokeStatic) { |
562 // Try to recognize the length getter with input [:new List(int):]. | 568 // Try to recognize the length getter with input [:new List.fixedLength(
int):]. |
563 HInvokeStatic call = node.receiver; | 569 HInvokeStatic call = node.receiver; |
564 if (isFixedSizeListConstructor(call)) { | 570 if (isFixedSizeListConstructor(call)) { |
565 return call.inputs[1]; | 571 return call.inputs[1]; |
566 } | 572 } |
567 } | 573 } |
568 } | 574 } |
569 return node; | 575 return node; |
570 } | 576 } |
571 | 577 |
572 HInstruction optimizeLengthInterceptedCall(HInvokeDynamicGetter node) { | 578 HInstruction optimizeLengthInterceptedCall(HInvokeDynamicGetter node) { |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1364 } |
1359 | 1365 |
1360 // For other fields having setters in the generative constructor body, set | 1366 // For other fields having setters in the generative constructor body, set |
1361 // the type to UNKNOWN to avoid relying on the type set in the initializer | 1367 // the type to UNKNOWN to avoid relying on the type set in the initializer |
1362 // list. | 1368 // list. |
1363 allSetters.forEach((Element element) { | 1369 allSetters.forEach((Element element) { |
1364 backend.registerFieldConstructor(element, HType.UNKNOWN); | 1370 backend.registerFieldConstructor(element, HType.UNKNOWN); |
1365 }); | 1371 }); |
1366 } | 1372 } |
1367 } | 1373 } |
OLD | NEW |