Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/ssa/builder.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/ssa/builder.dart (revision 18306) |
| +++ sdk/lib/_internal/compiler/implementation/ssa/builder.dart (working copy) |
| @@ -248,6 +248,18 @@ |
| updateLocal(boxElement, newBox); |
| } |
| + HType computeTypeOfThis() { |
| + Element element = closureData.thisElement; |
| + ClassElement cls = element.enclosingElement.getEnclosingClass(); |
| + DartType type = cls.computeType(builder.compiler); |
| + Compiler compiler = builder.compiler; |
| + if (compiler.world.isUsedAsMixin(cls)) { |
|
kasperl
2013/02/11 14:30:34
Add comment to explain why this is done?
ngeoffray
2013/02/11 14:53:29
Done.
|
| + return new HType.nonNullSubtype(type, compiler); |
| + } else { |
| + return new HType.nonNullSubclass(type, compiler); |
| + } |
| + } |
| + |
| /** |
| * Documentation wanted -- johnniwinther |
| * |
| @@ -301,10 +313,8 @@ |
| // Once closures have been mapped to classes their instance members might |
| // not have any thisElement if the closure was created inside a static |
| // context. |
| - ClassElement cls = element.getEnclosingClass(); |
| - DartType type = cls.computeType(builder.compiler); |
| - HThis thisInstruction = new HThis(closureData.thisElement, |
| - new HBoundedType.nonNull(type)); |
| + HThis thisInstruction = new HThis( |
| + closureData.thisElement, computeTypeOfThis()); |
| builder.graph.thisInstruction = thisInstruction; |
| builder.graph.entry.addAtEntry(thisInstruction); |
| directLocals[closureData.thisElement] = thisInstruction; |
| @@ -423,10 +433,7 @@ |
| if (res.guaranteedType == null) { |
| if (cachedTypeOfThis == null) { |
| assert(closureData.isClosure()); |
| - Element element = closureData.thisElement; |
| - ClassElement cls = element.enclosingElement.getEnclosingClass(); |
| - DartType type = cls.computeType(builder.compiler); |
| - cachedTypeOfThis = new HBoundedType.nonNull(type); |
| + cachedTypeOfThis = computeTypeOfThis(); |
| } |
| res.guaranteedType = cachedTypeOfThis; |
| } |
| @@ -4020,10 +4027,11 @@ |
| } |
| HLiteralList keyValuePairs = new HLiteralList(inputs); |
| add(keyValuePairs); |
| + DartType mapType = compiler.mapLiteralClass.computeType(compiler); |
| + // TODO(ngeoffray): Use the actual implementation type of a map |
| + // literal. |
| pushInvokeHelper1(backend.getMapMaker(), keyValuePairs, |
| - new HType.fromBoundedType(compiler.mapClass.computeType(compiler), |
| - compiler, |
| - false)); |
| + new HType.nonNullSubtype(mapType, compiler)); |
| } |
| visitLiteralMapEntry(LiteralMapEntry node) { |
| @@ -4611,8 +4619,20 @@ |
| HType mapBaseType(BaseType baseType) { |
| if (!baseType.isClass()) return HType.UNKNOWN; |
| ClassBaseType classBaseType = baseType; |
| - return new HType.fromBoundedType( |
| - classBaseType.element.computeType(compiler), compiler, false); |
| + ClassElement cls = classBaseType.element; |
| + // Special case the list and map classes that are used as types |
| + // for literals in the type inferrer. |
| + if (cls == compiler.listClass) { |
| + return HType.READABLE_ARRAY; |
| + } else if (cls == compiler.mapClass) { |
| + // TODO(ngeoffray): get the actual implementation of a map |
| + // literal. |
| + return new HType.nonNullSubtype( |
| + compiler.mapLiteralClass.computeType(compiler), compiler); |
|
kasperl
2013/02/11 14:30:34
It's very common that you call computeType as part
ngeoffray
2013/02/11 14:53:29
Sometimes, you do have the DartType available and
|
| + } else { |
| + return new HType.nonNullExactClass( |
| + cls.computeType(compiler), compiler); |
| + } |
| } |
| HType mapInferredType(ConcreteType concreteType) { |
| @@ -4627,12 +4647,12 @@ |
| HType mapNativeType(type) { |
|
kasperl
2013/02/11 14:30:34
What is the type of type?
ngeoffray
2013/02/11 14:53:29
It can be of different classes (DartType or ad-hoc
|
| if (type == native.SpecialType.JsObject) { |
| - return new HBoundedType.exact( |
| - compiler.objectClass.computeType(compiler)); |
| + return new HType.nonNullExactClass( |
| + compiler.objectClass.computeType(compiler), compiler); |
| } else if (type == native.SpecialType.JsArray) { |
| return HType.READABLE_ARRAY; |
| } else { |
| - return new HType.fromBoundedType(type, compiler, false); |
| + return new HType.nonNullSubclass(type, compiler); |
| } |
| } |