| 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 library js_backend.backend.impact_transformer; | 5 library js_backend.backend.impact_transformer; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common_elements.dart'; | 8 import '../common_elements.dart'; |
| 9 import '../common/backend_api.dart' show ImpactTransformer; | 9 import '../common/backend_api.dart' show ImpactTransformer; |
| 10 import '../common/codegen.dart' show CodegenImpact; | 10 import '../common/codegen.dart' show CodegenImpact; |
| 11 import '../common/resolution.dart' show ResolutionImpact; | 11 import '../common/resolution.dart' show ResolutionImpact; |
| 12 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
| 13 import '../common_elements.dart' show ElementEnvironment; | 13 import '../common_elements.dart' show ElementEnvironment; |
| 14 import '../elements/elements.dart' show AsyncMarker; | 14 import '../elements/elements.dart' show AsyncMarker; |
| 15 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
| 16 import '../elements/resolution_types.dart' show Types; | 16 import '../elements/resolution_types.dart' show Types; |
| 17 import '../elements/types.dart'; | 17 import '../elements/types.dart'; |
| 18 import '../native/enqueue.dart'; | 18 import '../native/enqueue.dart'; |
| 19 import '../native/native.dart' as native; | 19 import '../native/native.dart' as native; |
| 20 import '../options.dart'; | 20 import '../options.dart'; |
| 21 import '../universe/feature.dart'; | 21 import '../universe/feature.dart'; |
| 22 import '../universe/use.dart' | 22 import '../universe/use.dart' |
| 23 show StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 23 show StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
| 24 import '../universe/world_impact.dart' show TransformedWorldImpact, WorldImpact; | 24 import '../universe/world_impact.dart' show TransformedWorldImpact, WorldImpact; |
| 25 import '../util/util.dart'; | 25 import '../util/util.dart'; |
| 26 import 'backend.dart'; | 26 import 'backend.dart'; |
| 27 import 'backend_helpers.dart'; | |
| 28 import 'backend_impact.dart'; | 27 import 'backend_impact.dart'; |
| 29 import 'backend_usage.dart'; | 28 import 'backend_usage.dart'; |
| 30 import 'checked_mode_helpers.dart'; | 29 import 'checked_mode_helpers.dart'; |
| 31 import 'custom_elements_analysis.dart'; | 30 import 'custom_elements_analysis.dart'; |
| 32 import 'interceptor_data.dart'; | 31 import 'interceptor_data.dart'; |
| 33 import 'lookup_map_analysis.dart'; | 32 import 'lookup_map_analysis.dart'; |
| 34 import 'mirrors_data.dart'; | 33 import 'mirrors_data.dart'; |
| 35 import 'namer.dart'; | 34 import 'namer.dart'; |
| 36 import 'native_data.dart'; | 35 import 'native_data.dart'; |
| 37 | 36 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 327 } |
| 329 if (type is InterfaceType && _nativeBasicData.isNativeClass(type.element)) { | 328 if (type is InterfaceType && _nativeBasicData.isNativeClass(type.element)) { |
| 330 registerImpact(_impacts.nativeTypeCheck); | 329 registerImpact(_impacts.nativeTypeCheck); |
| 331 } | 330 } |
| 332 } | 331 } |
| 333 } | 332 } |
| 334 | 333 |
| 335 class CodegenImpactTransformer { | 334 class CodegenImpactTransformer { |
| 336 final CompilerOptions _options; | 335 final CompilerOptions _options; |
| 337 final ElementEnvironment _elementEnvironment; | 336 final ElementEnvironment _elementEnvironment; |
| 338 final BackendHelpers _helpers; | 337 final CommonElements _commonElements; |
| 339 final BackendImpacts _impacts; | 338 final BackendImpacts _impacts; |
| 340 final CheckedModeHelpers _checkedModeHelpers; | 339 final CheckedModeHelpers _checkedModeHelpers; |
| 341 final NativeData _nativeData; | 340 final NativeData _nativeData; |
| 342 final BackendUsage _backendUsage; | 341 final BackendUsage _backendUsage; |
| 343 final RuntimeTypesNeed _rtiNeed; | 342 final RuntimeTypesNeed _rtiNeed; |
| 344 final NativeCodegenEnqueuer _nativeCodegenEnqueuer; | 343 final NativeCodegenEnqueuer _nativeCodegenEnqueuer; |
| 345 final Namer _namer; | 344 final Namer _namer; |
| 346 final OneShotInterceptorData _oneShotInterceptorData; | 345 final OneShotInterceptorData _oneShotInterceptorData; |
| 347 final LookupMapAnalysis _lookupMapAnalysis; | 346 final LookupMapAnalysis _lookupMapAnalysis; |
| 348 final RuntimeTypesChecksBuilder _rtiChecksBuilder; | 347 final RuntimeTypesChecksBuilder _rtiChecksBuilder; |
| 349 | 348 |
| 350 CodegenImpactTransformer( | 349 CodegenImpactTransformer( |
| 351 this._options, | 350 this._options, |
| 352 this._elementEnvironment, | 351 this._elementEnvironment, |
| 353 this._helpers, | 352 this._commonElements, |
| 354 this._impacts, | 353 this._impacts, |
| 355 this._checkedModeHelpers, | 354 this._checkedModeHelpers, |
| 356 this._nativeData, | 355 this._nativeData, |
| 357 this._backendUsage, | 356 this._backendUsage, |
| 358 this._rtiNeed, | 357 this._rtiNeed, |
| 359 this._nativeCodegenEnqueuer, | 358 this._nativeCodegenEnqueuer, |
| 360 this._namer, | 359 this._namer, |
| 361 this._oneShotInterceptorData, | 360 this._oneShotInterceptorData, |
| 362 this._lookupMapAnalysis, | 361 this._lookupMapAnalysis, |
| 363 this._rtiChecksBuilder); | 362 this._rtiChecksBuilder); |
| 364 | 363 |
| 365 void onIsCheckForCodegen(DartType type, TransformedWorldImpact transformed) { | 364 void onIsCheckForCodegen(DartType type, TransformedWorldImpact transformed) { |
| 366 if (type.isDynamic) return; | 365 if (type.isDynamic) return; |
| 367 type = type.unaliased; | 366 type = type.unaliased; |
| 368 _impacts.typeCheck.registerImpact(transformed, _elementEnvironment); | 367 _impacts.typeCheck.registerImpact(transformed, _elementEnvironment); |
| 369 | 368 |
| 370 bool inCheckedMode = _options.enableTypeAssertions; | 369 bool inCheckedMode = _options.enableTypeAssertions; |
| 371 // [registerIsCheck] is also called for checked mode checks, so we | 370 // [registerIsCheck] is also called for checked mode checks, so we |
| 372 // need to register checked mode helpers. | 371 // need to register checked mode helpers. |
| 373 if (inCheckedMode) { | 372 if (inCheckedMode) { |
| 374 // All helpers are added to resolution queue in enqueueHelpers. These | 373 // All helpers are added to resolution queue in enqueueHelpers. These |
| 375 // calls to [enqueue] with the resolution enqueuer serve as assertions | 374 // calls to [enqueue] with the resolution enqueuer serve as assertions |
| 376 // that the helper was in fact added. | 375 // that the helper was in fact added. |
| 377 // TODO(13155): Find a way to enqueue helpers lazily. | 376 // TODO(13155): Find a way to enqueue helpers lazily. |
| 378 CheckedModeHelper helper = | 377 CheckedModeHelper helper = |
| 379 _checkedModeHelpers.getCheckedModeHelper(type, typeCast: false); | 378 _checkedModeHelpers.getCheckedModeHelper(type, typeCast: false); |
| 380 if (helper != null) { | 379 if (helper != null) { |
| 381 StaticUse staticUse = helper.getStaticUse(_helpers); | 380 StaticUse staticUse = helper.getStaticUse(_commonElements); |
| 382 transformed.registerStaticUse(staticUse); | 381 transformed.registerStaticUse(staticUse); |
| 383 } | 382 } |
| 384 // We also need the native variant of the check (for DOM types). | 383 // We also need the native variant of the check (for DOM types). |
| 385 helper = | 384 helper = |
| 386 _checkedModeHelpers.getNativeCheckedModeHelper(type, typeCast: false); | 385 _checkedModeHelpers.getNativeCheckedModeHelper(type, typeCast: false); |
| 387 if (helper != null) { | 386 if (helper != null) { |
| 388 StaticUse staticUse = helper.getStaticUse(_helpers); | 387 StaticUse staticUse = helper.getStaticUse(_commonElements); |
| 389 transformed.registerStaticUse(staticUse); | 388 transformed.registerStaticUse(staticUse); |
| 390 } | 389 } |
| 391 } | 390 } |
| 392 if (!type.treatAsRaw || type.containsTypeVariables) { | 391 if (!type.treatAsRaw || type.containsTypeVariables) { |
| 393 _impacts.genericIsCheck.registerImpact(transformed, _elementEnvironment); | 392 _impacts.genericIsCheck.registerImpact(transformed, _elementEnvironment); |
| 394 } | 393 } |
| 395 if (type is InterfaceType && _nativeData.isNativeClass(type.element)) { | 394 if (type is InterfaceType && _nativeData.isNativeClass(type.element)) { |
| 396 // We will neeed to add the "$is" and "$as" properties on the | 395 // We will neeed to add the "$is" and "$as" properties on the |
| 397 // JavaScript object prototype, so we make sure | 396 // JavaScript object prototype, so we make sure |
| 398 // [:defineProperty:] is compiled. | 397 // [:defineProperty:] is compiled. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 _impacts.asyncStarBody | 466 _impacts.asyncStarBody |
| 468 .registerImpact(transformed, _elementEnvironment); | 467 .registerImpact(transformed, _elementEnvironment); |
| 469 break; | 468 break; |
| 470 } | 469 } |
| 471 } | 470 } |
| 472 | 471 |
| 473 // TODO(johnniwinther): Remove eager registration. | 472 // TODO(johnniwinther): Remove eager registration. |
| 474 return transformed; | 473 return transformed; |
| 475 } | 474 } |
| 476 } | 475 } |
| OLD | NEW |