| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import '../common/backend_api.dart'; | |
| 6 import '../common_elements.dart' show CommonElements, ElementEnvironment; | 5 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
| 7 import '../elements/elements.dart'; | 6 import '../elements/elements.dart'; |
| 8 import '../elements/entities.dart'; | 7 import '../elements/entities.dart'; |
| 9 import '../elements/resolution_types.dart'; | 8 import '../elements/resolution_types.dart'; |
| 10 import '../elements/types.dart'; | 9 import '../elements/types.dart'; |
| 11 import '../js_backend/backend_usage.dart' show BackendUsageBuilder; | 10 import '../js_backend/backend_usage.dart' show BackendUsageBuilder; |
| 12 import '../js_backend/native_data.dart' show NativeData; | 11 import '../js_backend/native_data.dart' show NativeData; |
| 13 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter; | 12 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter; |
| 14 import '../options.dart'; | 13 import '../options.dart'; |
| 15 import '../universe/use.dart' show StaticUse, TypeUse; | 14 import '../universe/use.dart' show StaticUse, TypeUse; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 46 final Set<ClassEntity> _unusedClasses = new Set<ClassEntity>(); | 45 final Set<ClassEntity> _unusedClasses = new Set<ClassEntity>(); |
| 47 | 46 |
| 48 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; | 47 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; |
| 49 | 48 |
| 50 /// Log message reported if all native types are used. | 49 /// Log message reported if all native types are used. |
| 51 String _allUsedMessage; | 50 String _allUsedMessage; |
| 52 | 51 |
| 53 final CompilerOptions _options; | 52 final CompilerOptions _options; |
| 54 final ElementEnvironment _elementEnvironment; | 53 final ElementEnvironment _elementEnvironment; |
| 55 final CommonElements _commonElements; | 54 final CommonElements _commonElements; |
| 56 final BackendClasses _backendClasses; | |
| 57 | 55 |
| 58 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 56 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 59 NativeEnqueuerBase(this._options, this._elementEnvironment, | 57 NativeEnqueuerBase( |
| 60 this._commonElements, this._backendClasses); | 58 this._options, this._elementEnvironment, this._commonElements); |
| 61 | 59 |
| 62 bool get enableLiveTypeAnalysis => _options.enableNativeLiveTypeAnalysis; | 60 bool get enableLiveTypeAnalysis => _options.enableNativeLiveTypeAnalysis; |
| 63 | 61 |
| 64 void onInstantiatedType(InterfaceType type) { | 62 void onInstantiatedType(InterfaceType type) { |
| 65 if (_unusedClasses.remove(type.element)) { | 63 if (_unusedClasses.remove(type.element)) { |
| 66 _registeredClasses.add(type.element); | 64 _registeredClasses.add(type.element); |
| 67 } | 65 } |
| 68 } | 66 } |
| 69 | 67 |
| 70 /// Register [classes] as natively instantiated in [impactBuilder]. | 68 /// Register [classes] as natively instantiated in [impactBuilder]. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (type is InterfaceType) { | 103 if (type is InterfaceType) { |
| 106 if (type == _commonElements.numType) { | 104 if (type == _commonElements.numType) { |
| 107 registerInstantiation(_commonElements.doubleType); | 105 registerInstantiation(_commonElements.doubleType); |
| 108 registerInstantiation(_commonElements.intType); | 106 registerInstantiation(_commonElements.intType); |
| 109 } else if (type == _commonElements.intType || | 107 } else if (type == _commonElements.intType || |
| 110 type == _commonElements.doubleType || | 108 type == _commonElements.doubleType || |
| 111 type == _commonElements.stringType || | 109 type == _commonElements.stringType || |
| 112 type == _commonElements.nullType || | 110 type == _commonElements.nullType || |
| 113 type == _commonElements.boolType || | 111 type == _commonElements.boolType || |
| 114 _elementEnvironment.isSubtype(type, | 112 _elementEnvironment.isSubtype(type, |
| 115 _elementEnvironment.getRawType(_backendClasses.listClass))) { | 113 _elementEnvironment.getRawType(_commonElements.jsArrayClass))) { |
| 116 registerInstantiation(type); | 114 registerInstantiation(type); |
| 117 } | 115 } |
| 118 // TODO(johnniwinther): Improve spec string precision to handle type | 116 // TODO(johnniwinther): Improve spec string precision to handle type |
| 119 // arguments and implements relations that preserve generics. Currently | 117 // arguments and implements relations that preserve generics. Currently |
| 120 // we cannot distinguish between `List`, `List<dynamic>`, and | 118 // we cannot distinguish between `List`, `List<dynamic>`, and |
| 121 // `List<int>` and take all to mean `List<E>`; in effect not including | 119 // `List<int>` and take all to mean `List<E>`; in effect not including |
| 122 // any native subclasses of generic classes. | 120 // any native subclasses of generic classes. |
| 123 // TODO(johnniwinther,sra): Find and replace uses of `List` with the | 121 // TODO(johnniwinther,sra): Find and replace uses of `List` with the |
| 124 // actual implementation classes such as `JSArray` et al. | 122 // actual implementation classes such as `JSArray` et al. |
| 125 matchingClasses | 123 matchingClasses |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 final BackendUsageBuilder _backendUsageBuilder; | 188 final BackendUsageBuilder _backendUsageBuilder; |
| 191 | 189 |
| 192 /// The set of all native classes. Each native class is in [nativeClasses] | 190 /// The set of all native classes. Each native class is in [nativeClasses] |
| 193 /// and exactly one of [unusedClasses] and [registeredClasses]. | 191 /// and exactly one of [unusedClasses] and [registeredClasses]. |
| 194 final Set<ClassEntity> _nativeClasses = new Set<ClassEntity>(); | 192 final Set<ClassEntity> _nativeClasses = new Set<ClassEntity>(); |
| 195 | 193 |
| 196 NativeResolutionEnqueuer( | 194 NativeResolutionEnqueuer( |
| 197 CompilerOptions options, | 195 CompilerOptions options, |
| 198 ElementEnvironment elementEnvironment, | 196 ElementEnvironment elementEnvironment, |
| 199 CommonElements commonElements, | 197 CommonElements commonElements, |
| 200 BackendClasses backendClasses, | |
| 201 this._backendUsageBuilder, | 198 this._backendUsageBuilder, |
| 202 this._nativeClassResolver) | 199 this._nativeClassResolver) |
| 203 : super(options, elementEnvironment, commonElements, backendClasses); | 200 : super(options, elementEnvironment, commonElements); |
| 204 | 201 |
| 205 void _registerBackendUse(FunctionEntity element) { | 202 void _registerBackendUse(FunctionEntity element) { |
| 206 _backendUsageBuilder.registerBackendFunctionUse(element); | 203 _backendUsageBuilder.registerBackendFunctionUse(element); |
| 207 _backendUsageBuilder.registerGlobalFunctionDependency(element); | 204 _backendUsageBuilder.registerGlobalFunctionDependency(element); |
| 208 } | 205 } |
| 209 | 206 |
| 210 WorldImpact processNativeClasses(Iterable<LibraryEntity> libraries) { | 207 WorldImpact processNativeClasses(Iterable<LibraryEntity> libraries) { |
| 211 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); | 208 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 212 Iterable<ClassEntity> nativeClasses = | 209 Iterable<ClassEntity> nativeClasses = |
| 213 _nativeClassResolver.computeNativeClasses(libraries); | 210 _nativeClassResolver.computeNativeClasses(libraries); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 230 final CodeEmitterTask _emitter; | 227 final CodeEmitterTask _emitter; |
| 231 final NativeResolutionEnqueuer _resolutionEnqueuer; | 228 final NativeResolutionEnqueuer _resolutionEnqueuer; |
| 232 final NativeData _nativeData; | 229 final NativeData _nativeData; |
| 233 | 230 |
| 234 final Set<ClassEntity> _doneAddSubtypes = new Set<ClassEntity>(); | 231 final Set<ClassEntity> _doneAddSubtypes = new Set<ClassEntity>(); |
| 235 | 232 |
| 236 NativeCodegenEnqueuer( | 233 NativeCodegenEnqueuer( |
| 237 CompilerOptions options, | 234 CompilerOptions options, |
| 238 ElementEnvironment elementEnvironment, | 235 ElementEnvironment elementEnvironment, |
| 239 CommonElements commonElements, | 236 CommonElements commonElements, |
| 240 BackendClasses backendClasses, | |
| 241 this._emitter, | 237 this._emitter, |
| 242 this._resolutionEnqueuer, | 238 this._resolutionEnqueuer, |
| 243 this._nativeData) | 239 this._nativeData) |
| 244 : super(options, elementEnvironment, commonElements, backendClasses); | 240 : super(options, elementEnvironment, commonElements); |
| 245 | 241 |
| 246 WorldImpact processNativeClasses(Iterable<LibraryElement> libraries) { | 242 WorldImpact processNativeClasses(Iterable<LibraryElement> libraries) { |
| 247 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); | 243 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 248 _unusedClasses.addAll(_resolutionEnqueuer._nativeClasses); | 244 _unusedClasses.addAll(_resolutionEnqueuer._nativeClasses); |
| 249 | 245 |
| 250 if (!enableLiveTypeAnalysis) { | 246 if (!enableLiveTypeAnalysis) { |
| 251 _registerTypeUses( | 247 _registerTypeUses( |
| 252 impactBuilder, _resolutionEnqueuer._nativeClasses, 'forced'); | 248 impactBuilder, _resolutionEnqueuer._nativeClasses, 'forced'); |
| 253 } | 249 } |
| 254 | 250 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); | 301 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); |
| 306 directSubtypes.add(cls); | 302 directSubtypes.add(cls); |
| 307 } | 303 } |
| 308 | 304 |
| 309 void logSummary(void log(String message)) { | 305 void logSummary(void log(String message)) { |
| 310 super.logSummary(log); | 306 super.logSummary(log); |
| 311 log('Compiled ${_registeredClasses.length} native classes, ' | 307 log('Compiled ${_registeredClasses.length} native classes, ' |
| 312 '${_unusedClasses.length} native classes omitted.'); | 308 '${_unusedClasses.length} native classes omitted.'); |
| 313 } | 309 } |
| 314 } | 310 } |
| OLD | NEW |