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<MixinApplicationElement>> mixinUses; | 9 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; |
| 10 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; | 10 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; |
| 11 final Set<ClassElement> classesNeedingRti; | 11 final Set<ClassElement> classesNeedingRti; |
| 12 final Map<ClassElement, Set<ClassElement>> rtiDependencies; | 12 final Map<ClassElement, Set<ClassElement>> rtiDependencies; |
| 13 final FullFunctionSet allFunctions; | 13 final FullFunctionSet allFunctions; |
| 14 | 14 |
| 15 // The set of classes that use one of their type variables as expressions | |
| 16 // to get the runtime type. | |
| 17 final Set<ClassElement> classesUsingVariableExpression; | |
|
ngeoffray
2013/03/11 10:24:06
Isn't that just an rtiDependency? So could you ju
karlklose
2013/03/12 09:05:02
No, this class and its subclasses need RTI because
| |
| 18 | |
| 15 // We keep track of subtype and subclass relationships in four | 19 // We keep track of subtype and subclass relationships in four |
| 16 // distinct sets to make class hierarchy analysis faster. | 20 // distinct sets to make class hierarchy analysis faster. |
| 17 final Map<ClassElement, Set<ClassElement>> subclasses = | 21 final Map<ClassElement, Set<ClassElement>> subclasses = |
| 18 new Map<ClassElement, Set<ClassElement>>(); | 22 new Map<ClassElement, Set<ClassElement>>(); |
| 19 final Map<ClassElement, Set<ClassElement>> superclasses = | 23 final Map<ClassElement, Set<ClassElement>> superclasses = |
| 20 new Map<ClassElement, Set<ClassElement>>(); | 24 new Map<ClassElement, Set<ClassElement>>(); |
| 21 final Map<ClassElement, Set<ClassElement>> subtypes = | 25 final Map<ClassElement, Set<ClassElement>> subtypes = |
| 22 new Map<ClassElement, Set<ClassElement>>(); | 26 new Map<ClassElement, Set<ClassElement>>(); |
| 23 final Map<ClassElement, Set<ClassElement>> supertypes = | 27 final Map<ClassElement, Set<ClassElement>> supertypes = |
| 24 new Map<ClassElement, Set<ClassElement>>(); | 28 new Map<ClassElement, Set<ClassElement>>(); |
| 25 | 29 |
| 26 World(Compiler compiler) | 30 World(Compiler compiler) |
| 27 : mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), | 31 : mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), |
| 28 typesImplementedBySubclasses = | 32 typesImplementedBySubclasses = |
| 29 new Map<ClassElement, Set<ClassElement>>(), | 33 new Map<ClassElement, Set<ClassElement>>(), |
| 30 classesNeedingRti = new Set<ClassElement>(), | 34 classesNeedingRti = new Set<ClassElement>(), |
| 31 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), | 35 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), |
| 32 allFunctions = new FullFunctionSet(compiler), | 36 allFunctions = new FullFunctionSet(compiler), |
| 37 classesUsingVariableExpression = new Set<ClassElement>(), | |
| 33 this.compiler = compiler; | 38 this.compiler = compiler; |
| 34 | 39 |
| 35 void populate() { | 40 void populate() { |
| 36 void addSubtypes(ClassElement cls) { | 41 void addSubtypes(ClassElement cls) { |
| 37 if (cls.resolutionState != STATE_DONE) { | 42 if (cls.resolutionState != STATE_DONE) { |
| 38 compiler.internalErrorOnElement( | 43 compiler.internalErrorOnElement( |
| 39 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); | 44 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); |
| 40 } | 45 } |
| 41 | 46 |
| 42 for (DartType type in cls.allSupertypes) { | 47 for (DartType type in cls.allSupertypes) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 if (type.kind == TypeKind.INTERFACE) { | 128 if (type.kind == TypeKind.INTERFACE) { |
| 124 InterfaceType itf = type; | 129 InterfaceType itf = type; |
| 125 if (!itf.isRaw) { | 130 if (!itf.isRaw) { |
| 126 potentiallyAddForRti(itf.element); | 131 potentiallyAddForRti(itf.element); |
| 127 } | 132 } |
| 128 } else if (type.kind == TypeKind.TYPE_VARIABLE) { | 133 } else if (type.kind == TypeKind.TYPE_VARIABLE) { |
| 129 TypeVariableElement variable = type.element; | 134 TypeVariableElement variable = type.element; |
| 130 potentiallyAddForRti(variable.enclosingElement); | 135 potentiallyAddForRti(variable.enclosingElement); |
| 131 } | 136 } |
| 132 }); | 137 }); |
| 138 // Add the classes that need RTI because they use a type variable as | |
| 139 // expression. | |
| 140 classesUsingVariableExpression.forEach(potentiallyAddForRti); | |
| 133 } | 141 } |
| 134 | 142 |
| 135 Iterable<ClassElement> commonSupertypesOf(ClassElement x, ClassElement y) { | 143 Iterable<ClassElement> commonSupertypesOf(ClassElement x, ClassElement y) { |
| 136 Set<ClassElement> xSet = supertypes[x]; | 144 Set<ClassElement> xSet = supertypes[x]; |
| 137 if (xSet == null) return const <ClassElement>[]; | 145 if (xSet == null) return const <ClassElement>[]; |
| 138 Set<ClassElement> ySet = supertypes[y]; | 146 Set<ClassElement> ySet = supertypes[y]; |
| 139 if (ySet == null) return const <ClassElement>[]; | 147 if (ySet == null) return const <ClassElement>[]; |
| 140 Set<ClassElement> smallSet, largeSet; | 148 Set<ClassElement> smallSet, largeSet; |
| 141 if (xSet.length <= ySet.length) { | 149 if (xSet.length <= ySet.length) { |
| 142 smallSet = xSet; | 150 smallSet = xSet; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 if (mask != null) { | 238 if (mask != null) { |
| 231 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); | 239 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); |
| 232 } | 240 } |
| 233 ClassElement objectClass = compiler.objectClass; | 241 ClassElement objectClass = compiler.objectClass; |
| 234 return allFunctions | 242 return allFunctions |
| 235 .filter(noSuchMethodSelector) | 243 .filter(noSuchMethodSelector) |
| 236 .map((Element member) => member.getEnclosingClass()) | 244 .map((Element member) => member.getEnclosingClass()) |
| 237 .where((ClassElement holder) => !identical(holder, objectClass)); | 245 .where((ClassElement holder) => !identical(holder, objectClass)); |
| 238 } | 246 } |
| 239 } | 247 } |
| OLD | NEW |