Chromium Code Reviews| 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 /** | 7 /** |
| 8 * A special element for the extra parameter taken by intercepted | 8 * A special element for the extra parameter taken by intercepted |
| 9 * methods. We need to override [Element.computeType] because our | 9 * methods. We need to override [Element.computeType] because our |
| 10 * optimizers may look at its declared type. | 10 * optimizers may look at its declared type. |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 builder.graph.thisInstruction = thisInstruction; | 296 builder.graph.thisInstruction = thisInstruction; |
| 297 builder.graph.entry.addAtEntry(thisInstruction); | 297 builder.graph.entry.addAtEntry(thisInstruction); |
| 298 updateLocal(closureData.closureElement, thisInstruction); | 298 updateLocal(closureData.closureElement, thisInstruction); |
| 299 } else if (element.isInstanceMember() | 299 } else if (element.isInstanceMember() |
| 300 || element.isGenerativeConstructor()) { | 300 || element.isGenerativeConstructor()) { |
| 301 // Once closures have been mapped to classes their instance members might | 301 // Once closures have been mapped to classes their instance members might |
| 302 // not have any thisElement if the closure was created inside a static | 302 // not have any thisElement if the closure was created inside a static |
| 303 // context. | 303 // context. |
| 304 ClassElement cls = element.getEnclosingClass(); | 304 ClassElement cls = element.getEnclosingClass(); |
| 305 DartType type = cls.computeType(builder.compiler); | 305 DartType type = cls.computeType(builder.compiler); |
| 306 HThis thisInstruction = new HThis(closureData.thisElement, | 306 HThis thisInstruction = new HThis( |
| 307 new HBoundedType.nonNull(type)); | 307 closureData.thisElement, |
| 308 new HBoundedType( | |
| 309 type, isExact: false, canBeNull: false, isInterfaceType: false)); | |
| 308 builder.graph.thisInstruction = thisInstruction; | 310 builder.graph.thisInstruction = thisInstruction; |
| 309 builder.graph.entry.addAtEntry(thisInstruction); | 311 builder.graph.entry.addAtEntry(thisInstruction); |
| 310 directLocals[closureData.thisElement] = thisInstruction; | 312 directLocals[closureData.thisElement] = thisInstruction; |
| 311 } | 313 } |
| 312 | 314 |
| 313 // If this method is an intercepted method, add the extra | 315 // If this method is an intercepted method, add the extra |
| 314 // parameter to it, that is the actual receiver. | 316 // parameter to it, that is the actual receiver. |
| 315 ClassElement cls = element.getEnclosingClass(); | 317 ClassElement cls = element.getEnclosingClass(); |
| 316 if (builder.backend.isInterceptorClass(cls)) { | 318 if (builder.backend.isInterceptorClass(cls)) { |
| 317 HType type = HType.UNKNOWN; | 319 HType type = HType.UNKNOWN; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 HType cachedTypeOfThis; | 421 HType cachedTypeOfThis; |
| 420 | 422 |
| 421 HInstruction readThis() { | 423 HInstruction readThis() { |
| 422 HInstruction res = readLocal(closureData.thisElement); | 424 HInstruction res = readLocal(closureData.thisElement); |
| 423 if (res.guaranteedType == null) { | 425 if (res.guaranteedType == null) { |
| 424 if (cachedTypeOfThis == null) { | 426 if (cachedTypeOfThis == null) { |
| 425 assert(closureData.isClosure()); | 427 assert(closureData.isClosure()); |
| 426 Element element = closureData.thisElement; | 428 Element element = closureData.thisElement; |
| 427 ClassElement cls = element.enclosingElement.getEnclosingClass(); | 429 ClassElement cls = element.enclosingElement.getEnclosingClass(); |
| 428 DartType type = cls.computeType(builder.compiler); | 430 DartType type = cls.computeType(builder.compiler); |
| 429 cachedTypeOfThis = new HBoundedType.nonNull(type); | 431 cachedTypeOfThis = new HBoundedType( |
| 432 type, | |
| 433 canBeNull: false, | |
| 434 isExact: false, | |
| 435 isInterfaceType: false); | |
|
kasperl
2013/02/11 08:18:12
This needs to take mixins into account. The type o
ngeoffray
2013/02/11 10:20:55
Done.
| |
| 430 } | 436 } |
| 431 res.guaranteedType = cachedTypeOfThis; | 437 res.guaranteedType = cachedTypeOfThis; |
| 432 } | 438 } |
| 433 return res; | 439 return res; |
| 434 } | 440 } |
| 435 | 441 |
| 436 HLocalValue getLocal(Element element) { | 442 HLocalValue getLocal(Element element) { |
| 437 // If the element is a parameter, we already have a | 443 // If the element is a parameter, we already have a |
| 438 // HParameterValue for it. We cannot create another one because | 444 // HParameterValue for it. We cannot create another one because |
| 439 // it could then have another name than the real parameter. And | 445 // it could then have another name than the real parameter. And |
| (...skipping 3573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4013 List<HInstruction> inputs = <HInstruction>[]; | 4019 List<HInstruction> inputs = <HInstruction>[]; |
| 4014 for (Link<Node> link = node.entries.nodes; | 4020 for (Link<Node> link = node.entries.nodes; |
| 4015 !link.isEmpty; | 4021 !link.isEmpty; |
| 4016 link = link.tail) { | 4022 link = link.tail) { |
| 4017 visit(link.head); | 4023 visit(link.head); |
| 4018 inputs.addLast(pop()); | 4024 inputs.addLast(pop()); |
| 4019 inputs.addLast(pop()); | 4025 inputs.addLast(pop()); |
| 4020 } | 4026 } |
| 4021 HLiteralList keyValuePairs = new HLiteralList(inputs); | 4027 HLiteralList keyValuePairs = new HLiteralList(inputs); |
| 4022 add(keyValuePairs); | 4028 add(keyValuePairs); |
| 4029 DartType mapType = compiler.mapLiteralClass.computeType(compiler); | |
| 4023 pushInvokeHelper1(backend.getMapMaker(), keyValuePairs, | 4030 pushInvokeHelper1(backend.getMapMaker(), keyValuePairs, |
|
kasperl
2013/02/11 08:18:12
A comment that explains why this type isn't exact
ngeoffray
2013/02/11 10:20:55
Done.
| |
| 4024 new HType.fromBoundedType(compiler.mapClass.computeType(compiler), | 4031 new HType.fromBoundedType(mapType, |
| 4025 compiler, | 4032 compiler, |
| 4026 false)); | 4033 canBeNull: false, |
| 4034 isExact: false, | |
| 4035 isInterfaceType: true)); | |
| 4027 } | 4036 } |
| 4028 | 4037 |
| 4029 visitLiteralMapEntry(LiteralMapEntry node) { | 4038 visitLiteralMapEntry(LiteralMapEntry node) { |
| 4030 visit(node.value); | 4039 visit(node.value); |
| 4031 visit(node.key); | 4040 visit(node.key); |
| 4032 } | 4041 } |
| 4033 | 4042 |
| 4034 visitNamedArgument(NamedArgument node) { | 4043 visitNamedArgument(NamedArgument node) { |
| 4035 visit(node.expression); | 4044 visit(node.expression); |
| 4036 } | 4045 } |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4604 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); | 4613 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); |
| 4605 } | 4614 } |
| 4606 | 4615 |
| 4607 visitTypeVariable(TypeVariable node) { | 4616 visitTypeVariable(TypeVariable node) { |
| 4608 compiler.internalError('SsaBuilder.visitTypeVariable'); | 4617 compiler.internalError('SsaBuilder.visitTypeVariable'); |
| 4609 } | 4618 } |
| 4610 | 4619 |
| 4611 HType mapBaseType(BaseType baseType) { | 4620 HType mapBaseType(BaseType baseType) { |
| 4612 if (!baseType.isClass()) return HType.UNKNOWN; | 4621 if (!baseType.isClass()) return HType.UNKNOWN; |
| 4613 ClassBaseType classBaseType = baseType; | 4622 ClassBaseType classBaseType = baseType; |
| 4614 return new HType.fromBoundedType( | 4623 ClassElement cls = classBaseType.element; |
| 4615 classBaseType.element.computeType(compiler), compiler, false); | 4624 // Special case the list and map classes that are used as types |
| 4625 // for literals in the type inferrer. | |
| 4626 if (cls == compiler.listClass) { | |
| 4627 return HType.READABLE_ARRAY; | |
| 4628 } else if (cls == compiler.mapClass) { | |
| 4629 return new HType.fromBoundedType( | |
|
kasperl
2013/02/11 08:18:12
How many different variants of this constructor ar
ngeoffray
2013/02/11 10:20:55
Done.
| |
| 4630 compiler.mapLiteralClass.computeType(compiler), | |
| 4631 compiler, | |
| 4632 canBeNull: false, | |
| 4633 isExact: false, | |
| 4634 isInterfaceType: true); | |
| 4635 } else { | |
| 4636 return new HType.fromBoundedType( | |
| 4637 cls.computeType(compiler), | |
| 4638 compiler, | |
| 4639 canBeNull: false, | |
| 4640 isExact: true, | |
| 4641 isInterfaceType: false); | |
| 4642 } | |
| 4616 } | 4643 } |
| 4617 | 4644 |
| 4618 HType mapInferredType(ConcreteType concreteType) { | 4645 HType mapInferredType(ConcreteType concreteType) { |
| 4619 if (concreteType == null) return HType.UNKNOWN; | 4646 if (concreteType == null) return HType.UNKNOWN; |
| 4620 HType ssaType = HType.CONFLICTING; | 4647 HType ssaType = HType.CONFLICTING; |
| 4621 for (BaseType baseType in concreteType.baseTypes) { | 4648 for (BaseType baseType in concreteType.baseTypes) { |
| 4622 ssaType = ssaType.union(mapBaseType(baseType), compiler); | 4649 ssaType = ssaType.union(mapBaseType(baseType), compiler); |
| 4623 } | 4650 } |
| 4624 assert(!ssaType.isConflicting()); | 4651 assert(!ssaType.isConflicting()); |
| 4625 return ssaType; | 4652 return ssaType; |
| 4626 } | 4653 } |
| 4627 | 4654 |
| 4628 HType mapNativeType(type) { | 4655 HType mapNativeType(type) { |
| 4629 if (type == native.SpecialType.JsObject) { | 4656 if (type == native.SpecialType.JsObject) { |
| 4630 return new HBoundedType.exact( | 4657 return new HBoundedType.exact( |
| 4631 compiler.objectClass.computeType(compiler)); | 4658 compiler.objectClass.computeType(compiler)); |
| 4632 } else if (type == native.SpecialType.JsArray) { | 4659 } else if (type == native.SpecialType.JsArray) { |
| 4633 return HType.READABLE_ARRAY; | 4660 return HType.READABLE_ARRAY; |
| 4634 } else { | 4661 } else { |
| 4635 return new HType.fromBoundedType(type, compiler, false); | 4662 return new HType.fromBoundedType( |
| 4663 type, | |
| 4664 compiler, | |
| 4665 canBeNull: false, | |
| 4666 isExact: false, | |
| 4667 isInterfaceType: false); | |
| 4636 } | 4668 } |
| 4637 } | 4669 } |
| 4638 | 4670 |
| 4639 HType mapNativeBehaviorType(native.NativeBehavior nativeBehavior) { | 4671 HType mapNativeBehaviorType(native.NativeBehavior nativeBehavior) { |
| 4640 if (nativeBehavior.typesInstantiated.isEmpty) return HType.UNKNOWN; | 4672 if (nativeBehavior.typesInstantiated.isEmpty) return HType.UNKNOWN; |
| 4641 | 4673 |
| 4642 HType ssaType = HType.CONFLICTING; | 4674 HType ssaType = HType.CONFLICTING; |
| 4643 for (final type in nativeBehavior.typesInstantiated) { | 4675 for (final type in nativeBehavior.typesInstantiated) { |
| 4644 ssaType = ssaType.union(mapNativeType(type), compiler); | 4676 ssaType = ssaType.union(mapNativeType(type), compiler); |
| 4645 } | 4677 } |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5025 new HSubGraphBlockInformation(elseBranch.graph)); | 5057 new HSubGraphBlockInformation(elseBranch.graph)); |
| 5026 | 5058 |
| 5027 HBasicBlock conditionStartBlock = conditionBranch.block; | 5059 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 5028 conditionStartBlock.setBlockFlow(info, joinBlock); | 5060 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 5029 SubGraph conditionGraph = conditionBranch.graph; | 5061 SubGraph conditionGraph = conditionBranch.graph; |
| 5030 HIf branch = conditionGraph.end.last; | 5062 HIf branch = conditionGraph.end.last; |
| 5031 assert(branch is HIf); | 5063 assert(branch is HIf); |
| 5032 branch.blockInformation = conditionStartBlock.blockFlow; | 5064 branch.blockInformation = conditionStartBlock.blockFlow; |
| 5033 } | 5065 } |
| 5034 } | 5066 } |
| OLD | NEW |