| 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 28 matching lines...) Expand all Loading... |
| 39 /// Compute the required type checkes and substitutions for the given | 39 /// Compute the required type checkes and substitutions for the given |
| 40 /// instantitated and checked classes. | 40 /// instantitated and checked classes. |
| 41 TypeChecks computeChecks( | 41 TypeChecks computeChecks( |
| 42 Set<ClassElement> instantiated, Set<ClassElement> checked); | 42 Set<ClassElement> instantiated, Set<ClassElement> checked); |
| 43 | 43 |
| 44 /// Compute type arguments of classes that use one of their type variables in | 44 /// Compute type arguments of classes that use one of their type variables in |
| 45 /// is-checks and add the is-checks that they imply. | 45 /// is-checks and add the is-checks that they imply. |
| 46 /// | 46 /// |
| 47 /// This function must be called after all is-checks have been registered. | 47 /// This function must be called after all is-checks have been registered. |
| 48 void addImplicitChecks( | 48 void addImplicitChecks( |
| 49 Universe universe, Iterable<ClassElement> classesUsingChecks); | 49 WorldBuilder universe, Iterable<ClassElement> classesUsingChecks); |
| 50 | 50 |
| 51 /// Return all classes that are referenced in the type of the function, i.e., | 51 /// Return all classes that are referenced in the type of the function, i.e., |
| 52 /// in the return type or the argument types. | 52 /// in the return type or the argument types. |
| 53 Set<ClassElement> getReferencedClasses(FunctionType type); | 53 Set<ClassElement> getReferencedClasses(FunctionType type); |
| 54 | 54 |
| 55 /// Return all classes that are uses a type arguments. | 55 /// Return all classes that are uses a type arguments. |
| 56 Set<ClassElement> getRequiredArgumentClasses(JavaScriptBackend backend); | 56 Set<ClassElement> getRequiredArgumentClasses(JavaScriptBackend backend); |
| 57 | 57 |
| 58 bool isTrivialSubstitution(ClassElement cls, ClassElement check); | 58 bool isTrivialSubstitution(ClassElement cls, ClassElement check); |
| 59 | 59 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 * Compute type arguments of classes that use one of their type variables in | 163 * Compute type arguments of classes that use one of their type variables in |
| 164 * is-checks and add the is-checks that they imply. | 164 * is-checks and add the is-checks that they imply. |
| 165 * | 165 * |
| 166 * This function must be called after all is-checks have been registered. | 166 * This function must be called after all is-checks have been registered. |
| 167 * | 167 * |
| 168 * TODO(karlklose): move these computations into a function producing an | 168 * TODO(karlklose): move these computations into a function producing an |
| 169 * immutable datastructure. | 169 * immutable datastructure. |
| 170 */ | 170 */ |
| 171 @override | 171 @override |
| 172 void addImplicitChecks( | 172 void addImplicitChecks( |
| 173 Universe universe, Iterable<ClassElement> classesUsingChecks) { | 173 WorldBuilder universe, Iterable<ClassElement> classesUsingChecks) { |
| 174 // If there are no classes that use their variables in checks, there is | 174 // If there are no classes that use their variables in checks, there is |
| 175 // nothing to do. | 175 // nothing to do. |
| 176 if (classesUsingChecks.isEmpty) return; | 176 if (classesUsingChecks.isEmpty) return; |
| 177 Set<DartType> instantiatedTypes = universe.instantiatedTypes; | 177 Set<DartType> instantiatedTypes = universe.instantiatedTypes; |
| 178 if (cannotDetermineInstantiatedTypesPrecisely) { | 178 if (cannotDetermineInstantiatedTypesPrecisely) { |
| 179 for (DartType type in instantiatedTypes) { | 179 for (DartType type in instantiatedTypes) { |
| 180 if (type.kind != TypeKind.INTERFACE) continue; | 180 if (type.kind != TypeKind.INTERFACE) continue; |
| 181 InterfaceType interface = type; | 181 InterfaceType interface = type; |
| 182 do { | 182 do { |
| 183 for (DartType argument in interface.typeArguments) { | 183 for (DartType argument in interface.typeArguments) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 Set<DartType> isChecks = compiler.codegenWorld.isChecks; | 357 Set<DartType> isChecks = compiler.codegenWorld.isChecks; |
| 358 // These types are needed for is-checks against function types. | 358 // These types are needed for is-checks against function types. |
| 359 Set<DartType> instantiatedTypesAndClosures = | 359 Set<DartType> instantiatedTypesAndClosures = |
| 360 computeInstantiatedTypesAndClosures(compiler.codegenWorld); | 360 computeInstantiatedTypesAndClosures(compiler.codegenWorld); |
| 361 computeInstantiatedArguments(instantiatedTypesAndClosures, isChecks); | 361 computeInstantiatedArguments(instantiatedTypesAndClosures, isChecks); |
| 362 computeCheckedArguments(instantiatedTypesAndClosures, isChecks); | 362 computeCheckedArguments(instantiatedTypesAndClosures, isChecks); |
| 363 cachedRequiredChecks = | 363 cachedRequiredChecks = |
| 364 computeChecks(allInstantiatedArguments, checkedArguments); | 364 computeChecks(allInstantiatedArguments, checkedArguments); |
| 365 } | 365 } |
| 366 | 366 |
| 367 Set<DartType> computeInstantiatedTypesAndClosures(CodegenUniverse universe) { | 367 Set<DartType> computeInstantiatedTypesAndClosures( |
| 368 CodegenWorldBuilder universe) { |
| 368 Set<DartType> instantiatedTypes = | 369 Set<DartType> instantiatedTypes = |
| 369 new Set<DartType>.from(universe.instantiatedTypes); | 370 new Set<DartType>.from(universe.instantiatedTypes); |
| 370 for (DartType instantiatedType in universe.instantiatedTypes) { | 371 for (DartType instantiatedType in universe.instantiatedTypes) { |
| 371 if (instantiatedType.isInterfaceType) { | 372 if (instantiatedType.isInterfaceType) { |
| 372 InterfaceType interface = instantiatedType; | 373 InterfaceType interface = instantiatedType; |
| 373 FunctionType callType = interface.callType; | 374 FunctionType callType = interface.callType; |
| 374 if (callType != null) { | 375 if (callType != null) { |
| 375 instantiatedTypes.add(callType); | 376 instantiatedTypes.add(callType); |
| 376 } | 377 } |
| 377 } | 378 } |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 * substition for this check. | 1034 * substition for this check. |
| 1034 */ | 1035 */ |
| 1035 class TypeCheck { | 1036 class TypeCheck { |
| 1036 final ClassElement cls; | 1037 final ClassElement cls; |
| 1037 final Substitution substitution; | 1038 final Substitution substitution; |
| 1038 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); | 1039 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); |
| 1039 static int _nextHash = 0; | 1040 static int _nextHash = 0; |
| 1040 | 1041 |
| 1041 TypeCheck(this.cls, this.substitution); | 1042 TypeCheck(this.cls, this.substitution); |
| 1042 } | 1043 } |
| OLD | NEW |