| 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common_elements.dart'; | 6 import '../common_elements.dart'; |
| 7 import '../elements/elements.dart' show Element; | 7 import '../elements/elements.dart' show Element; |
| 8 import '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
| 9 import '../elements/types.dart'; | 9 import '../elements/types.dart'; |
| 10 import '../util/util.dart' show Setlet; | 10 import '../util/util.dart' show Setlet; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 /// `true` of `Object.runtimeType` is used. | 34 /// `true` of `Object.runtimeType` is used. |
| 35 bool get isRuntimeTypeUsed; | 35 bool get isRuntimeTypeUsed; |
| 36 | 36 |
| 37 /// `true` if the `dart:isolate` library is in use. | 37 /// `true` if the `dart:isolate` library is in use. |
| 38 bool get isIsolateInUse; | 38 bool get isIsolateInUse; |
| 39 | 39 |
| 40 /// `true` if `Function.apply` is used. | 40 /// `true` if `Function.apply` is used. |
| 41 bool get isFunctionApplyUsed; | 41 bool get isFunctionApplyUsed; |
| 42 | 42 |
| 43 /// `true` if 'dart:mirrors' features are used. |
| 44 bool get isMirrorsUsed; |
| 45 |
| 43 /// `true` if `noSuchMethod` is used. | 46 /// `true` if `noSuchMethod` is used. |
| 44 bool get isNoSuchMethodUsed; | 47 bool get isNoSuchMethodUsed; |
| 45 } | 48 } |
| 46 | 49 |
| 47 abstract class BackendUsageBuilder { | 50 abstract class BackendUsageBuilder { |
| 48 /// The backend must *always* call this method when enqueuing an function | 51 /// The backend must *always* call this method when enqueuing an function |
| 49 /// element. Calls done by the backend are not seen by global | 52 /// element. Calls done by the backend are not seen by global |
| 50 /// optimizations, so they would make these optimizations unsound. | 53 /// optimizations, so they would make these optimizations unsound. |
| 51 /// Therefore we need to collect the list of methods the backend may | 54 /// Therefore we need to collect the list of methods the backend may |
| 52 /// call. | 55 /// call. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 111 |
| 109 /// `true` of `Object.runtimeType` is used. | 112 /// `true` of `Object.runtimeType` is used. |
| 110 bool isRuntimeTypeUsed = false; | 113 bool isRuntimeTypeUsed = false; |
| 111 | 114 |
| 112 /// `true` if the `dart:isolate` library is in use. | 115 /// `true` if the `dart:isolate` library is in use. |
| 113 bool isIsolateInUse = false; | 116 bool isIsolateInUse = false; |
| 114 | 117 |
| 115 /// `true` if `Function.apply` is used. | 118 /// `true` if `Function.apply` is used. |
| 116 bool isFunctionApplyUsed = false; | 119 bool isFunctionApplyUsed = false; |
| 117 | 120 |
| 121 /// `true` if 'dart:mirrors' features are used. |
| 122 bool isMirrorsUsed = false; |
| 123 |
| 118 /// `true` if `noSuchMethod` is used. | 124 /// `true` if `noSuchMethod` is used. |
| 119 bool isNoSuchMethodUsed = false; | 125 bool isNoSuchMethodUsed = false; |
| 120 | 126 |
| 121 BackendUsageBuilderImpl(this._commonElements); | 127 BackendUsageBuilderImpl(this._commonElements); |
| 122 | 128 |
| 123 @override | 129 @override |
| 124 void registerBackendFunctionUse(FunctionEntity element) { | 130 void registerBackendFunctionUse(FunctionEntity element) { |
| 125 assert(_isValidBackendUse(element), | 131 assert(_isValidBackendUse(element), |
| 126 failedAt(element, "Backend use of $element is not allowed.")); | 132 failedAt(element, "Backend use of $element is not allowed.")); |
| 127 _helperFunctionsUsed.add(element); | 133 _helperFunctionsUsed.add(element); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 240 |
| 235 void registerUsedMember(MemberEntity member) { | 241 void registerUsedMember(MemberEntity member) { |
| 236 if (member == _commonElements.getIsolateAffinityTagMarker) { | 242 if (member == _commonElements.getIsolateAffinityTagMarker) { |
| 237 _needToInitializeIsolateAffinityTag = true; | 243 _needToInitializeIsolateAffinityTag = true; |
| 238 } else if (member == _commonElements.requiresPreambleMarker) { | 244 } else if (member == _commonElements.requiresPreambleMarker) { |
| 239 requiresPreamble = true; | 245 requiresPreamble = true; |
| 240 } else if (member == _commonElements.invokeOnMethod) { | 246 } else if (member == _commonElements.invokeOnMethod) { |
| 241 isInvokeOnUsed = true; | 247 isInvokeOnUsed = true; |
| 242 } else if (_commonElements.isFunctionApplyMethod(member)) { | 248 } else if (_commonElements.isFunctionApplyMethod(member)) { |
| 243 isFunctionApplyUsed = true; | 249 isFunctionApplyUsed = true; |
| 250 } else if (member.library == _commonElements.mirrorsLibrary) { |
| 251 isMirrorsUsed = true; |
| 244 } | 252 } |
| 245 } | 253 } |
| 246 | 254 |
| 247 void registerGlobalFunctionDependency(FunctionEntity element) { | 255 void registerGlobalFunctionDependency(FunctionEntity element) { |
| 248 assert(element != null); | 256 assert(element != null); |
| 249 if (_globalFunctionDependencies == null) { | 257 if (_globalFunctionDependencies == null) { |
| 250 _globalFunctionDependencies = new Setlet<FunctionEntity>(); | 258 _globalFunctionDependencies = new Setlet<FunctionEntity>(); |
| 251 } | 259 } |
| 252 _globalFunctionDependencies.add(element); | 260 _globalFunctionDependencies.add(element); |
| 253 } | 261 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 266 globalClassDependencies: _globalClassDependencies, | 274 globalClassDependencies: _globalClassDependencies, |
| 267 helperFunctionsUsed: _helperFunctionsUsed, | 275 helperFunctionsUsed: _helperFunctionsUsed, |
| 268 helperClassesUsed: _helperClassesUsed, | 276 helperClassesUsed: _helperClassesUsed, |
| 269 needToInitializeIsolateAffinityTag: _needToInitializeIsolateAffinityTag, | 277 needToInitializeIsolateAffinityTag: _needToInitializeIsolateAffinityTag, |
| 270 needToInitializeDispatchProperty: _needToInitializeDispatchProperty, | 278 needToInitializeDispatchProperty: _needToInitializeDispatchProperty, |
| 271 requiresPreamble: requiresPreamble, | 279 requiresPreamble: requiresPreamble, |
| 272 isInvokeOnUsed: isInvokeOnUsed, | 280 isInvokeOnUsed: isInvokeOnUsed, |
| 273 isRuntimeTypeUsed: isRuntimeTypeUsed, | 281 isRuntimeTypeUsed: isRuntimeTypeUsed, |
| 274 isIsolateInUse: isIsolateInUse, | 282 isIsolateInUse: isIsolateInUse, |
| 275 isFunctionApplyUsed: isFunctionApplyUsed, | 283 isFunctionApplyUsed: isFunctionApplyUsed, |
| 284 isMirrorsUsed: isMirrorsUsed, |
| 276 isNoSuchMethodUsed: isNoSuchMethodUsed); | 285 isNoSuchMethodUsed: isNoSuchMethodUsed); |
| 277 } | 286 } |
| 278 } | 287 } |
| 279 | 288 |
| 280 class BackendUsageImpl implements BackendUsage { | 289 class BackendUsageImpl implements BackendUsage { |
| 281 // TODO(johnniwinther): Remove the need for these. | 290 // TODO(johnniwinther): Remove the need for these. |
| 282 final Set<FunctionEntity> _globalFunctionDependencies; | 291 final Set<FunctionEntity> _globalFunctionDependencies; |
| 283 final Set<ClassEntity> _globalClassDependencies; | 292 final Set<ClassEntity> _globalClassDependencies; |
| 284 | 293 |
| 285 /// Set of functions called by the backend. | 294 /// Set of functions called by the backend. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 299 | 308 |
| 300 /// `true` of `Object.runtimeType` is used. | 309 /// `true` of `Object.runtimeType` is used. |
| 301 final bool isRuntimeTypeUsed; | 310 final bool isRuntimeTypeUsed; |
| 302 | 311 |
| 303 /// `true` if the `dart:isolate` library is in use. | 312 /// `true` if the `dart:isolate` library is in use. |
| 304 final bool isIsolateInUse; | 313 final bool isIsolateInUse; |
| 305 | 314 |
| 306 /// `true` if `Function.apply` is used. | 315 /// `true` if `Function.apply` is used. |
| 307 final bool isFunctionApplyUsed; | 316 final bool isFunctionApplyUsed; |
| 308 | 317 |
| 318 /// `true` if 'dart:mirrors' features are used. |
| 319 final bool isMirrorsUsed; |
| 320 |
| 309 /// `true` if `noSuchMethod` is used. | 321 /// `true` if `noSuchMethod` is used. |
| 310 final bool isNoSuchMethodUsed; | 322 final bool isNoSuchMethodUsed; |
| 311 | 323 |
| 312 BackendUsageImpl( | 324 BackendUsageImpl( |
| 313 {Set<FunctionEntity> globalFunctionDependencies, | 325 {Set<FunctionEntity> globalFunctionDependencies, |
| 314 Set<ClassEntity> globalClassDependencies, | 326 Set<ClassEntity> globalClassDependencies, |
| 315 Set<FunctionEntity> helperFunctionsUsed, | 327 Set<FunctionEntity> helperFunctionsUsed, |
| 316 Set<ClassEntity> helperClassesUsed, | 328 Set<ClassEntity> helperClassesUsed, |
| 317 this.needToInitializeIsolateAffinityTag, | 329 this.needToInitializeIsolateAffinityTag, |
| 318 this.needToInitializeDispatchProperty, | 330 this.needToInitializeDispatchProperty, |
| 319 this.requiresPreamble, | 331 this.requiresPreamble, |
| 320 this.isInvokeOnUsed, | 332 this.isInvokeOnUsed, |
| 321 this.isRuntimeTypeUsed, | 333 this.isRuntimeTypeUsed, |
| 322 this.isIsolateInUse, | 334 this.isIsolateInUse, |
| 323 this.isFunctionApplyUsed, | 335 this.isFunctionApplyUsed, |
| 336 this.isMirrorsUsed, |
| 324 this.isNoSuchMethodUsed}) | 337 this.isNoSuchMethodUsed}) |
| 325 : this._globalFunctionDependencies = globalFunctionDependencies, | 338 : this._globalFunctionDependencies = globalFunctionDependencies, |
| 326 this._globalClassDependencies = globalClassDependencies, | 339 this._globalClassDependencies = globalClassDependencies, |
| 327 this._helperFunctionsUsed = helperFunctionsUsed, | 340 this._helperFunctionsUsed = helperFunctionsUsed, |
| 328 this._helperClassesUsed = helperClassesUsed; | 341 this._helperClassesUsed = helperClassesUsed; |
| 329 | 342 |
| 330 @override | 343 @override |
| 331 bool isFunctionUsedByBackend(FunctionEntity element) { | 344 bool isFunctionUsedByBackend(FunctionEntity element) { |
| 332 return _helperFunctionsUsed.contains(element); | 345 return _helperFunctionsUsed.contains(element); |
| 333 } | 346 } |
| 334 | 347 |
| 335 @override | 348 @override |
| 336 bool isFieldUsedByBackend(FieldEntity element) { | 349 bool isFieldUsedByBackend(FieldEntity element) { |
| 337 return _helperClassesUsed.contains(element.enclosingClass); | 350 return _helperClassesUsed.contains(element.enclosingClass); |
| 338 } | 351 } |
| 339 | 352 |
| 340 @override | 353 @override |
| 341 Iterable<FunctionEntity> get globalFunctionDependencies => | 354 Iterable<FunctionEntity> get globalFunctionDependencies => |
| 342 _globalFunctionDependencies ?? const <FunctionEntity>[]; | 355 _globalFunctionDependencies ?? const <FunctionEntity>[]; |
| 343 | 356 |
| 344 @override | 357 @override |
| 345 Iterable<ClassEntity> get globalClassDependencies => | 358 Iterable<ClassEntity> get globalClassDependencies => |
| 346 _globalClassDependencies ?? const <ClassEntity>[]; | 359 _globalClassDependencies ?? const <ClassEntity>[]; |
| 347 | 360 |
| 348 Iterable<FunctionEntity> get helperFunctionsUsed => _helperFunctionsUsed; | 361 Iterable<FunctionEntity> get helperFunctionsUsed => _helperFunctionsUsed; |
| 349 | 362 |
| 350 Iterable<ClassEntity> get helperClassesUsed => _helperClassesUsed; | 363 Iterable<ClassEntity> get helperClassesUsed => _helperClassesUsed; |
| 351 } | 364 } |
| OLD | NEW |