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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class World { | 7 class World { |
| 8 final Compiler compiler; | 8 final Compiler compiler; |
| 9 final Map<ClassElement, Set<ClassElement>> subtypes; | 9 final Map<ClassElement, Set<ClassElement>> subtypes; |
| 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; | 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; |
| 11 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; | 11 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; |
| 12 final Set<ClassElement> classesNeedingRti; | 12 final Set<ClassElement> classesNeedingRti; |
| 13 final Set<ClassElement> usedFactoriesOfAbstractClasses; | |
|
ngeoffray
2013/02/27 12:36:28
Store the factories instead, as implied by the nam
karlklose
2013/02/27 16:11:32
Obsolete.
| |
| 13 final Map<ClassElement, Set<ClassElement>> rtiDependencies; | 14 final Map<ClassElement, Set<ClassElement>> rtiDependencies; |
| 14 final FullFunctionSet allFunctions; | 15 final FullFunctionSet allFunctions; |
| 15 | 16 |
| 16 World(Compiler compiler) | 17 World(Compiler compiler) |
| 17 : subtypes = new Map<ClassElement, Set<ClassElement>>(), | 18 : subtypes = new Map<ClassElement, Set<ClassElement>>(), |
| 18 mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), | 19 mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), |
| 19 typesImplementedBySubclasses = | 20 typesImplementedBySubclasses = |
| 20 new Map<ClassElement, Set<ClassElement>>(), | 21 new Map<ClassElement, Set<ClassElement>>(), |
| 21 classesNeedingRti = new Set<ClassElement>(), | 22 classesNeedingRti = new Set<ClassElement>(), |
| 23 usedFactoriesOfAbstractClasses = new Set<ClassElement>(), | |
| 22 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), | 24 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), |
| 23 allFunctions = new FullFunctionSet(compiler), | 25 allFunctions = new FullFunctionSet(compiler), |
| 24 this.compiler = compiler; | 26 this.compiler = compiler; |
| 25 | 27 |
| 26 void populate() { | 28 void populate() { |
| 27 void addSubtypes(ClassElement cls) { | 29 void addSubtypes(ClassElement cls) { |
| 28 if (cls.resolutionState != STATE_DONE) { | 30 if (cls.resolutionState != STATE_DONE) { |
| 29 compiler.internalErrorOnElement( | 31 compiler.internalErrorOnElement( |
| 30 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); | 32 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); |
| 31 } | 33 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 74 } |
| 73 | 75 |
| 74 Set<ClassElement> dependencies = rtiDependencies[cls]; | 76 Set<ClassElement> dependencies = rtiDependencies[cls]; |
| 75 if (dependencies != null) { | 77 if (dependencies != null) { |
| 76 dependencies.forEach((ClassElement other) { | 78 dependencies.forEach((ClassElement other) { |
| 77 potentiallyAddForRti(other); | 79 potentiallyAddForRti(other); |
| 78 }); | 80 }); |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 | 83 |
| 84 Set<ClassElement> classesUsingTypeVariableTests = new Set<ClassElement>(); | |
| 82 compiler.resolverWorld.isChecks.forEach((DartType type) { | 85 compiler.resolverWorld.isChecks.forEach((DartType type) { |
| 83 if (type is InterfaceType) { | 86 if (type.kind == TypeKind.TYPE_VARIABLE) { |
| 87 TypeVariableElement variable = type.element; | |
| 88 classesUsingTypeVariableTests.add(variable.enclosingElement); | |
| 89 } | |
| 90 }); | |
| 91 compiler.resolverWorld.addImplicitChecks(classesUsingTypeVariableTests); | |
| 92 compiler.resolverWorld.isChecks.forEach((DartType type) { | |
| 93 if (type.kind == TypeKind.INTERFACE) { | |
| 84 InterfaceType itf = type; | 94 InterfaceType itf = type; |
| 85 if (!itf.isRaw) { | 95 if (!itf.isRaw) { |
| 86 potentiallyAddForRti(itf.element); | 96 potentiallyAddForRti(itf.element); |
| 87 } | 97 } |
| 98 } else if (type.kind == TypeKind.TYPE_VARIABLE) { | |
| 99 TypeVariableElement variable = type.element; | |
| 100 potentiallyAddForRti(variable.enclosingElement); | |
| 88 } | 101 } |
| 89 }); | 102 }); |
| 103 | |
| 104 // TODO(karlklose): if we know all targets of factories for the abstract | |
| 105 // class, we should check whether one of these targets needs runtime type | |
| 106 // information before adding the class. | |
| 107 usedFactoriesOfAbstractClasses.forEach((ClassElement cls) { | |
| 108 potentiallyAddForRti(cls); | |
| 109 }); | |
| 90 } | 110 } |
| 91 | 111 |
| 92 void registerMixinUse(MixinApplicationElement mixinApplication, | 112 void registerMixinUse(MixinApplicationElement mixinApplication, |
| 93 ClassElement mixin) { | 113 ClassElement mixin) { |
| 94 Set<MixinApplicationElement> users = | 114 Set<MixinApplicationElement> users = |
| 95 mixinUses.putIfAbsent(mixin, () => | 115 mixinUses.putIfAbsent(mixin, () => |
| 96 new Set<MixinApplicationElement>()); | 116 new Set<MixinApplicationElement>()); |
| 97 users.add(mixinApplication); | 117 users.add(mixinApplication); |
| 98 } | 118 } |
| 99 | 119 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 if (receiverType != null) { | 183 if (receiverType != null) { |
| 164 noSuchMethodSelector = new TypedSelector( | 184 noSuchMethodSelector = new TypedSelector( |
| 165 receiverType, selector.typeKind, noSuchMethodSelector); | 185 receiverType, selector.typeKind, noSuchMethodSelector); |
| 166 } | 186 } |
| 167 ClassElement objectClass = compiler.objectClass; | 187 ClassElement objectClass = compiler.objectClass; |
| 168 return allFunctions | 188 return allFunctions |
| 169 .filter(noSuchMethodSelector) | 189 .filter(noSuchMethodSelector) |
| 170 .map((Element member) => member.getEnclosingClass()) | 190 .map((Element member) => member.getEnclosingClass()) |
| 171 .where((ClassElement holder) => !identical(holder, objectClass)); | 191 .where((ClassElement holder) => !identical(holder, objectClass)); |
| 172 } | 192 } |
| 193 | |
| 194 void registerUsedFactoriesOfAbstractClasses(ClassElement cls) { | |
| 195 usedFactoriesOfAbstractClasses.add(cls); | |
| 196 } | |
| 173 } | 197 } |
| OLD | NEW |