| 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> classesUsingTypeVariableExpression; |
| 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 classesUsingTypeVariableExpression = 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 classesUsingTypeVariableExpression.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 29 matching lines...) Expand all Loading... |
| 172 } | 180 } |
| 173 | 181 |
| 174 void registerRtiDependency(Element element, Element dependency) { | 182 void registerRtiDependency(Element element, Element dependency) { |
| 175 // We're not dealing with typedef for now. | 183 // We're not dealing with typedef for now. |
| 176 if (!element.isClass() || !dependency.isClass()) return; | 184 if (!element.isClass() || !dependency.isClass()) return; |
| 177 Set<ClassElement> classes = | 185 Set<ClassElement> classes = |
| 178 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); | 186 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); |
| 179 classes.add(dependency); | 187 classes.add(dependency); |
| 180 } | 188 } |
| 181 | 189 |
| 190 void registerClassUsingVariableExpression(ClassElement cls) { |
| 191 classesUsingTypeVariableExpression.add(cls); |
| 192 } |
| 193 |
| 182 bool needsRti(ClassElement cls) { | 194 bool needsRti(ClassElement cls) { |
| 183 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; | 195 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; |
| 184 } | 196 } |
| 185 | 197 |
| 186 bool hasAnyUserDefinedGetter(Selector selector) { | 198 bool hasAnyUserDefinedGetter(Selector selector) { |
| 187 return allFunctions.filter(selector).any((each) => each.isGetter()); | 199 return allFunctions.filter(selector).any((each) => each.isGetter()); |
| 188 } | 200 } |
| 189 | 201 |
| 190 bool hasAnyUserDefinedSetter(Selector selector) { | 202 bool hasAnyUserDefinedSetter(Selector selector) { |
| 191 return allFunctions.filter(selector).any((each) => each.isSetter()); | 203 return allFunctions.filter(selector).any((each) => each.isSetter()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (mask != null) { | 252 if (mask != null) { |
| 241 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); | 253 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); |
| 242 } | 254 } |
| 243 ClassElement objectClass = compiler.objectClass; | 255 ClassElement objectClass = compiler.objectClass; |
| 244 return allFunctions | 256 return allFunctions |
| 245 .filter(noSuchMethodSelector) | 257 .filter(noSuchMethodSelector) |
| 246 .map((Element member) => member.getEnclosingClass()) | 258 .map((Element member) => member.getEnclosingClass()) |
| 247 .where((ClassElement holder) => !identical(holder, objectClass)); | 259 .where((ClassElement holder) => !identical(holder, objectClass)); |
| 248 } | 260 } |
| 249 } | 261 } |
| OLD | NEW |