| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 js_backend.backend; | 5 part of js_backend.backend; |
| 6 | 6 |
| 7 /// For each class, stores the possible class subtype tests that could succeed. | 7 /// For each class, stores the possible class subtype tests that could succeed. |
| 8 abstract class TypeChecks { | 8 abstract class TypeChecks { |
| 9 /// Get the set of checks required for class [element]. | 9 /// Get the set of checks required for class [element]. |
| 10 Iterable<TypeCheck> operator [](ClassElement element); | 10 Iterable<TypeCheck> operator [](ClassElement element); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 /// to get the runtime type. | 27 /// to get the runtime type. |
| 28 Iterable<ClassElement> get classesUsingTypeVariableExpression; | 28 Iterable<ClassElement> get classesUsingTypeVariableExpression; |
| 29 | 29 |
| 30 void registerClassUsingTypeVariableExpression(ClassElement cls); | 30 void registerClassUsingTypeVariableExpression(ClassElement cls); |
| 31 void registerRtiDependency(Element element, Element dependency); | 31 void registerRtiDependency(Element element, Element dependency); |
| 32 void registerTypeVariableBoundsSubtypeCheck( | 32 void registerTypeVariableBoundsSubtypeCheck( |
| 33 DartType typeArgument, DartType bound); | 33 DartType typeArgument, DartType bound); |
| 34 | 34 |
| 35 Set<ClassElement> getClassesUsedInSubstitutions( | 35 Set<ClassElement> getClassesUsedInSubstitutions( |
| 36 JavaScriptBackend backend, TypeChecks checks); | 36 JavaScriptBackend backend, TypeChecks checks); |
| 37 void computeClassesNeedingRti(); | 37 void computeClassesNeedingRti( |
| 38 ResolutionWorldBuilder resolverWorld, ClosedWorld closedWorld); |
| 38 | 39 |
| 39 /// Compute the required type checkes and substitutions for the given | 40 /// Compute the required type checkes and substitutions for the given |
| 40 /// instantitated and checked classes. | 41 /// instantitated and checked classes. |
| 41 TypeChecks computeChecks( | 42 TypeChecks computeChecks( |
| 42 Set<ClassElement> instantiated, Set<ClassElement> checked); | 43 Set<ClassElement> instantiated, Set<ClassElement> checked); |
| 43 | 44 |
| 44 /// Compute type arguments of classes that use one of their type variables in | 45 /// Compute type arguments of classes that use one of their type variables in |
| 45 /// is-checks and add the is-checks that they imply. | 46 /// is-checks and add the is-checks that they imply. |
| 46 /// | 47 /// |
| 47 /// This function must be called after all is-checks have been registered. | 48 /// This function must be called after all is-checks have been registered. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 universe.registerIsCheck(argument); | 208 universe.registerIsCheck(argument); |
| 208 } | 209 } |
| 209 current = current.element.supertype; | 210 current = current.element.supertype; |
| 210 } while (current != null && !instantiatedTypes.contains(current)); | 211 } while (current != null && !instantiatedTypes.contains(current)); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 @override | 217 @override |
| 217 void computeClassesNeedingRti() { | 218 void computeClassesNeedingRti( |
| 219 ResolutionWorldBuilder resolverWorld, ClosedWorld closedWorld) { |
| 218 // Find the classes that need runtime type information. Such | 220 // Find the classes that need runtime type information. Such |
| 219 // classes are: | 221 // classes are: |
| 220 // (1) used in a is check with type variables, | 222 // (1) used in a is check with type variables, |
| 221 // (2) dependencies of classes in (1), | 223 // (2) dependencies of classes in (1), |
| 222 // (3) subclasses of (2) and (3). | 224 // (3) subclasses of (2) and (3). |
| 223 void potentiallyAddForRti(ClassElement cls) { | 225 void potentiallyAddForRti(ClassElement cls) { |
| 224 assert(invariant(cls, cls.isDeclaration)); | 226 assert(invariant(cls, cls.isDeclaration)); |
| 225 if (cls.typeVariables.isEmpty) return; | 227 if (cls.typeVariables.isEmpty) return; |
| 226 if (classesNeedingRti.contains(cls)) return; | 228 if (classesNeedingRti.contains(cls)) return; |
| 227 classesNeedingRti.add(cls); | 229 classesNeedingRti.add(cls); |
| 228 | 230 |
| 229 // TODO(ngeoffray): This should use subclasses, not subtypes. | 231 // TODO(ngeoffray): This should use subclasses, not subtypes. |
| 230 compiler.closedWorld.forEachStrictSubtypeOf(cls, (ClassElement sub) { | 232 closedWorld.forEachStrictSubtypeOf(cls, (ClassElement sub) { |
| 231 potentiallyAddForRti(sub); | 233 potentiallyAddForRti(sub); |
| 232 }); | 234 }); |
| 233 | 235 |
| 234 Set<ClassElement> dependencies = rtiDependencies[cls]; | 236 Set<ClassElement> dependencies = rtiDependencies[cls]; |
| 235 if (dependencies != null) { | 237 if (dependencies != null) { |
| 236 dependencies.forEach((ClassElement other) { | 238 dependencies.forEach((ClassElement other) { |
| 237 potentiallyAddForRti(other); | 239 potentiallyAddForRti(other); |
| 238 }); | 240 }); |
| 239 } | 241 } |
| 240 } | 242 } |
| 241 | 243 |
| 242 Set<ClassElement> classesUsingTypeVariableTests = new Set<ClassElement>(); | 244 Set<ClassElement> classesUsingTypeVariableTests = new Set<ClassElement>(); |
| 243 compiler.resolverWorld.isChecks.forEach((DartType type) { | 245 resolverWorld.isChecks.forEach((DartType type) { |
| 244 if (type.isTypeVariable) { | 246 if (type.isTypeVariable) { |
| 245 TypeVariableElement variable = type.element; | 247 TypeVariableElement variable = type.element; |
| 246 // GENERIC_METHODS: When generic method support is complete enough to | 248 // GENERIC_METHODS: When generic method support is complete enough to |
| 247 // include a runtime value for method type variables, this may need to | 249 // include a runtime value for method type variables, this may need to |
| 248 // be updated: It simply ignores method type arguments. | 250 // be updated: It simply ignores method type arguments. |
| 249 if (variable.typeDeclaration is ClassElement) { | 251 if (variable.typeDeclaration is ClassElement) { |
| 250 classesUsingTypeVariableTests.add(variable.typeDeclaration); | 252 classesUsingTypeVariableTests.add(variable.typeDeclaration); |
| 251 } | 253 } |
| 252 } | 254 } |
| 253 }); | 255 }); |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 * substition for this check. | 1036 * substition for this check. |
| 1035 */ | 1037 */ |
| 1036 class TypeCheck { | 1038 class TypeCheck { |
| 1037 final ClassElement cls; | 1039 final ClassElement cls; |
| 1038 final Substitution substitution; | 1040 final Substitution substitution; |
| 1039 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); | 1041 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); |
| 1040 static int _nextHash = 0; | 1042 static int _nextHash = 0; |
| 1041 | 1043 |
| 1042 TypeCheck(this.cls, this.substitution); | 1044 TypeCheck(this.cls, this.substitution); |
| 1043 } | 1045 } |
| OLD | NEW |