| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 world_builder; | 5 part of world_builder; |
| 6 | 6 |
| 7 abstract class ResolutionWorldBuilder implements WorldBuilder, OpenWorld { | 7 abstract class ResolutionWorldBuilder implements WorldBuilder, OpenWorld { |
| 8 /// Set of all local functions in the program. Used by the mirror tracking | 8 /// Set of all local functions in the program. Used by the mirror tracking |
| 9 /// system to find all live closure instances. | 9 /// system to find all live closure instances. |
| 10 Iterable<Local> get localFunctions; | 10 Iterable<Local> get localFunctions; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 312 |
| 313 /// Map containing instance methods of live classes that are not yet | 313 /// Map containing instance methods of live classes that are not yet |
| 314 /// closurized. | 314 /// closurized. |
| 315 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = | 315 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = |
| 316 <String, Set<_MemberUsage>>{}; | 316 <String, Set<_MemberUsage>>{}; |
| 317 | 317 |
| 318 /// Fields set. | 318 /// Fields set. |
| 319 final Set<FieldEntity> fieldSetters = new Set<FieldEntity>(); | 319 final Set<FieldEntity> fieldSetters = new Set<FieldEntity>(); |
| 320 final Set<DartType> isChecks = new Set<DartType>(); | 320 final Set<DartType> isChecks = new Set<DartType>(); |
| 321 | 321 |
| 322 _ClassEnsurer _classEnsurer; | |
| 323 | |
| 324 /// Set of all closures in the program. Used by the mirror tracking system | 322 /// Set of all closures in the program. Used by the mirror tracking system |
| 325 /// to find all live closure instances. | 323 /// to find all live closure instances. |
| 326 final Set<Local> localFunctions = new Set<Local>(); | 324 final Set<Local> localFunctions = new Set<Local>(); |
| 327 | 325 |
| 328 /// Set of live local functions (closures) whose signatures reference type | 326 /// Set of live local functions (closures) whose signatures reference type |
| 329 /// variables. | 327 /// variables. |
| 330 /// | 328 /// |
| 331 /// A local function is considered live if the enclosing member function is | 329 /// A local function is considered live if the enclosing member function is |
| 332 /// live. | 330 /// live. |
| 333 final Set<Local> localFunctionsWithFreeTypeVariables = new Set<Local>(); | 331 final Set<Local> localFunctionsWithFreeTypeVariables = new Set<Local>(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 this._elementEnvironment, | 385 this._elementEnvironment, |
| 388 this._dartTypes, | 386 this._dartTypes, |
| 389 this._commonElements, | 387 this._commonElements, |
| 390 this._constantSystem, | 388 this._constantSystem, |
| 391 this._nativeBasicData, | 389 this._nativeBasicData, |
| 392 this._nativeDataBuilder, | 390 this._nativeDataBuilder, |
| 393 this._interceptorDataBuilder, | 391 this._interceptorDataBuilder, |
| 394 this._backendUsageBuilder, | 392 this._backendUsageBuilder, |
| 395 this._rtiNeedBuilder, | 393 this._rtiNeedBuilder, |
| 396 this._nativeResolutionEnqueuer, | 394 this._nativeResolutionEnqueuer, |
| 397 this.selectorConstraintsStrategy) { | 395 this.selectorConstraintsStrategy); |
| 398 _classEnsurer = new _ClassEnsurer(this); | |
| 399 } | |
| 400 | 396 |
| 401 Iterable<ClassEntity> get processedClasses => _processedClasses.keys | 397 Iterable<ClassEntity> get processedClasses => _processedClasses.keys |
| 402 .where((cls) => _processedClasses[cls].isInstantiated); | 398 .where((cls) => _processedClasses[cls].isInstantiated); |
| 403 | 399 |
| 404 bool isMemberProcessed(MemberEntity member) => | 400 bool isMemberProcessed(MemberEntity member) => |
| 405 _processedMembers.contains(member); | 401 _processedMembers.contains(member); |
| 406 void registerProcessedMember(MemberEntity member) { | 402 void registerProcessedMember(MemberEntity member) { |
| 407 _processedMembers.add(member); | 403 _processedMembers.add(member); |
| 408 } | 404 } |
| 409 | 405 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 superclass = getSuperClass(superclass); | 937 superclass = getSuperClass(superclass); |
| 942 } | 938 } |
| 943 } | 939 } |
| 944 | 940 |
| 945 // Use the [:seenClasses:] set to include non-instantiated | 941 // Use the [:seenClasses:] set to include non-instantiated |
| 946 // classes: if the superclass of these classes require RTI, then | 942 // classes: if the superclass of these classes require RTI, then |
| 947 // they also need RTI, so that a constructor passes the type | 943 // they also need RTI, so that a constructor passes the type |
| 948 // variables to the super constructor. | 944 // variables to the super constructor. |
| 949 forEachInstantiatedClass(addSubtypes); | 945 forEachInstantiatedClass(addSubtypes); |
| 950 | 946 |
| 951 instantiatedTypes.forEach((type) { | |
| 952 var callType = _dartTypes.getCallType(type); | |
| 953 if (callType != null) { | |
| 954 _classEnsurer.ensureClassesInType(callType); | |
| 955 } | |
| 956 }); | |
| 957 localFunctions.forEach((function) { | |
| 958 _classEnsurer.ensureClassesInType( | |
| 959 _elementEnvironment.getLocalFunctionType(function)); | |
| 960 }); | |
| 961 isChecks.forEach(_classEnsurer.ensureClassesInType); | |
| 962 closurizedMembers.forEach((function) { | |
| 963 _classEnsurer | |
| 964 .ensureClassesInType(_elementEnvironment.getFunctionType(function)); | |
| 965 }); | |
| 966 | |
| 967 _classHierarchyNodes.keys.toList().forEach(_ensureClassSet); | 947 _classHierarchyNodes.keys.toList().forEach(_ensureClassSet); |
| 968 | 948 |
| 969 return typesImplementedBySubclasses; | 949 return typesImplementedBySubclasses; |
| 970 } | 950 } |
| 971 | 951 |
| 972 Iterable<MemberEntity> computeAssignedInstanceMembers() { | 952 Iterable<MemberEntity> computeAssignedInstanceMembers() { |
| 973 Set<MemberEntity> assignedInstanceMembers = new Set<MemberEntity>(); | 953 Set<MemberEntity> assignedInstanceMembers = new Set<MemberEntity>(); |
| 974 for (MemberEntity instanceMember in _liveInstanceMembers) { | 954 for (MemberEntity instanceMember in _liveInstanceMembers) { |
| 975 if (hasInvokedSetter(instanceMember)) { | 955 if (hasInvokedSetter(instanceMember)) { |
| 976 assignedInstanceMembers.add(instanceMember); | 956 assignedInstanceMembers.add(instanceMember); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 typesImplementedBySubclasses: typesImplementedBySubclasses, | 1023 typesImplementedBySubclasses: typesImplementedBySubclasses, |
| 1044 classHierarchyNodes: _classHierarchyNodes, | 1024 classHierarchyNodes: _classHierarchyNodes, |
| 1045 classSets: _classSets); | 1025 classSets: _classSets); |
| 1046 } | 1026 } |
| 1047 | 1027 |
| 1048 @override | 1028 @override |
| 1049 void registerClass(ClassEntity cls) { | 1029 void registerClass(ClassEntity cls) { |
| 1050 throw new UnimplementedError('KernelResolutionWorldBuilder.registerClass'); | 1030 throw new UnimplementedError('KernelResolutionWorldBuilder.registerClass'); |
| 1051 } | 1031 } |
| 1052 } | 1032 } |
| 1053 | |
| 1054 // TODO(het): Make this have a type of BaseDartTypeVisitor<void, Null> | |
| 1055 class _ClassEnsurer extends BaseDartTypeVisitor<dynamic, Null> { | |
| 1056 final ResolutionWorldBuilderBase worldBuilder; | |
| 1057 | |
| 1058 _ClassEnsurer(this.worldBuilder); | |
| 1059 | |
| 1060 void ensureClassesInType(DartType type) { | |
| 1061 type.accept(this, null); | |
| 1062 } | |
| 1063 | |
| 1064 @override | |
| 1065 visitType(DartType type, _) {} | |
| 1066 | |
| 1067 @override | |
| 1068 visitFunctionType(FunctionType type, _) { | |
| 1069 type.returnType.accept(this, null); | |
| 1070 type.parameterTypes.forEach((t) { | |
| 1071 t.accept(this, null); | |
| 1072 }); | |
| 1073 type.optionalParameterTypes.forEach((t) { | |
| 1074 t.accept(this, null); | |
| 1075 }); | |
| 1076 type.namedParameterTypes.forEach((t) { | |
| 1077 t.accept(this, null); | |
| 1078 }); | |
| 1079 } | |
| 1080 | |
| 1081 @override | |
| 1082 visitInterfaceType(InterfaceType type, _) { | |
| 1083 worldBuilder._ensureClassSet(type.element); | |
| 1084 type.typeArguments.forEach((t) { | |
| 1085 t.accept(this, null); | |
| 1086 }); | |
| 1087 } | |
| 1088 } | |
| OLD | NEW |