| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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; | 5 library js_backend.backend; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 10 | 10 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 454 |
| 455 /// True if the html library has been loaded. | 455 /// True if the html library has been loaded. |
| 456 bool htmlLibraryIsLoaded = false; | 456 bool htmlLibraryIsLoaded = false; |
| 457 | 457 |
| 458 /// True when we enqueue the loadLibrary code. | 458 /// True when we enqueue the loadLibrary code. |
| 459 bool isLoadLibraryFunctionResolved = false; | 459 bool isLoadLibraryFunctionResolved = false; |
| 460 | 460 |
| 461 /// `true` if access to [BackendHelpers.invokeOnMethod] is supported. | 461 /// `true` if access to [BackendHelpers.invokeOnMethod] is supported. |
| 462 bool hasInvokeOnSupport = false; | 462 bool hasInvokeOnSupport = false; |
| 463 | 463 |
| 464 /// `true` if tear-offs are supported for incremental compilation. | |
| 465 bool hasIncrementalTearOffSupport = false; | |
| 466 | |
| 467 /// `true` of `Object.runtimeType` is supported. | 464 /// `true` of `Object.runtimeType` is supported. |
| 468 bool hasRuntimeTypeSupport = false; | 465 bool hasRuntimeTypeSupport = false; |
| 469 | 466 |
| 470 /// `true` of use of the `dart:isolate` library is supported. | 467 /// `true` of use of the `dart:isolate` library is supported. |
| 471 bool hasIsolateSupport = false; | 468 bool hasIsolateSupport = false; |
| 472 | 469 |
| 473 /// `true` of `Function.apply` is supported. | 470 /// `true` of `Function.apply` is supported. |
| 474 bool hasFunctionApplySupport = false; | 471 bool hasFunctionApplySupport = false; |
| 475 | 472 |
| 476 /// List of constants from metadata. If metadata must be preserved, | 473 /// List of constants from metadata. If metadata must be preserved, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 753 } |
| 757 | 754 |
| 758 /** | 755 /** |
| 759 * Record that [method] is called from a subclass via `super`. | 756 * Record that [method] is called from a subclass via `super`. |
| 760 */ | 757 */ |
| 761 bool maybeRegisterAliasedSuperMember( | 758 bool maybeRegisterAliasedSuperMember( |
| 762 MemberElement member, Selector selector) { | 759 MemberElement member, Selector selector) { |
| 763 if (!canUseAliasedSuperMember(member, selector)) { | 760 if (!canUseAliasedSuperMember(member, selector)) { |
| 764 // Invoking a super getter isn't supported, this would require changes to | 761 // Invoking a super getter isn't supported, this would require changes to |
| 765 // compact field descriptors in the emitter. | 762 // compact field descriptors in the emitter. |
| 766 // We also turn off this optimization in incremental compilation, to | |
| 767 // avoid having to regenerate a method just because someone started | |
| 768 // calling it through super. | |
| 769 return false; | 763 return false; |
| 770 } | 764 } |
| 771 aliasedSuperMembers.add(member); | 765 aliasedSuperMembers.add(member); |
| 772 return true; | 766 return true; |
| 773 } | 767 } |
| 774 | 768 |
| 775 bool canUseAliasedSuperMember(Element member, Selector selector) { | 769 bool canUseAliasedSuperMember(Element member, Selector selector) { |
| 776 return !selector.isGetter && !compiler.options.hasIncrementalSupport; | 770 return !selector.isGetter; |
| 777 } | 771 } |
| 778 | 772 |
| 779 /** | 773 /** |
| 780 * Returns `true` if [member] is called from a subclass via `super`. | 774 * Returns `true` if [member] is called from a subclass via `super`. |
| 781 */ | 775 */ |
| 782 bool isAliasedSuperMember(FunctionElement member) { | 776 bool isAliasedSuperMember(FunctionElement member) { |
| 783 return aliasedSuperMembers.contains(member); | 777 return aliasedSuperMembers.contains(member); |
| 784 } | 778 } |
| 785 | 779 |
| 786 /// Returns `true` if [element] is part of JsInterop. | 780 /// Returns `true` if [element] is part of JsInterop. |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 bool isComplexNoSuchMethod(FunctionElement element) => | 1432 bool isComplexNoSuchMethod(FunctionElement element) => |
| 1439 noSuchMethodRegistry.isComplex(element); | 1433 noSuchMethodRegistry.isComplex(element); |
| 1440 | 1434 |
| 1441 bool methodNeedsRti(FunctionElement function) { | 1435 bool methodNeedsRti(FunctionElement function) { |
| 1442 return rti.methodsNeedingRti.contains(function) || hasRuntimeTypeSupport; | 1436 return rti.methodsNeedingRti.contains(function) || hasRuntimeTypeSupport; |
| 1443 } | 1437 } |
| 1444 | 1438 |
| 1445 CodegenEnqueuer get codegenEnqueuer => compiler.enqueuer.codegen; | 1439 CodegenEnqueuer get codegenEnqueuer => compiler.enqueuer.codegen; |
| 1446 | 1440 |
| 1447 CodegenEnqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler) { | 1441 CodegenEnqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler) { |
| 1448 return new CodegenEnqueuer(task, compiler.cacheStrategy, this, | 1442 return new CodegenEnqueuer( |
| 1449 compiler.options, const TreeShakingEnqueuerStrategy()); | 1443 task, this, compiler.options, const TreeShakingEnqueuerStrategy()); |
| 1450 } | 1444 } |
| 1451 | 1445 |
| 1452 WorldImpact codegen(CodegenWorkItem work) { | 1446 WorldImpact codegen(CodegenWorkItem work) { |
| 1453 Element element = work.element; | 1447 Element element = work.element; |
| 1454 if (compiler.elementHasCompileTimeError(element)) { | 1448 if (compiler.elementHasCompileTimeError(element)) { |
| 1455 DiagnosticMessage message = | 1449 DiagnosticMessage message = |
| 1456 // If there's more than one error, the first is probably most | 1450 // If there's more than one error, the first is probably most |
| 1457 // informative, as the following errors may be side-effects of the | 1451 // informative, as the following errors may be side-effects of the |
| 1458 // first error. | 1452 // first error. |
| 1459 compiler.elementsWithCompileTimeErrors[element].first; | 1453 compiler.elementsWithCompileTimeErrors[element].first; |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2283 _noSuchMethodEnabledForCodegen = true; | 2277 _noSuchMethodEnabledForCodegen = true; |
| 2284 } | 2278 } |
| 2285 } | 2279 } |
| 2286 | 2280 |
| 2287 if (!enqueuer.queueIsEmpty) return false; | 2281 if (!enqueuer.queueIsEmpty) return false; |
| 2288 | 2282 |
| 2289 if (compiler.options.useKernel && compiler.mainApp != null) { | 2283 if (compiler.options.useKernel && compiler.mainApp != null) { |
| 2290 kernelTask.buildKernelIr(); | 2284 kernelTask.buildKernelIr(); |
| 2291 } | 2285 } |
| 2292 | 2286 |
| 2293 if (compiler.options.hasIncrementalSupport && | |
| 2294 !hasIncrementalTearOffSupport) { | |
| 2295 // Always enable tear-off closures during incremental compilation. | |
| 2296 Element element = helpers.closureFromTearOff; | |
| 2297 if (element != null) { | |
| 2298 enqueuer.applyImpact( | |
| 2299 impactTransformer.createImpactFor(impacts.closureClass)); | |
| 2300 } | |
| 2301 hasIncrementalTearOffSupport = true; | |
| 2302 } | |
| 2303 | |
| 2304 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) { | 2287 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) { |
| 2305 preMirrorsMethodCount = generatedCode.length; | 2288 preMirrorsMethodCount = generatedCode.length; |
| 2306 } | 2289 } |
| 2307 | 2290 |
| 2308 if (isTreeShakingDisabled) { | 2291 if (isTreeShakingDisabled) { |
| 2309 enqueuer.applyImpact(mirrorsAnalysis.computeImpactForReflectiveElements( | 2292 enqueuer.applyImpact(mirrorsAnalysis.computeImpactForReflectiveElements( |
| 2310 recentClasses, | 2293 recentClasses, |
| 2311 enqueuer.processedClasses, | 2294 enqueuer.processedClasses, |
| 2312 compiler.libraryLoader.libraries, | 2295 compiler.libraryLoader.libraries, |
| 2313 forResolution: enqueuer.isResolutionQueue)); | 2296 forResolution: enqueuer.isResolutionQueue)); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2513 "@NoSideEffects() should always be combined with @NoInline."); | 2496 "@NoSideEffects() should always be combined with @NoInline."); |
| 2514 } | 2497 } |
| 2515 } | 2498 } |
| 2516 | 2499 |
| 2517 FunctionElement helperForBadMain() => helpers.badMain; | 2500 FunctionElement helperForBadMain() => helpers.badMain; |
| 2518 | 2501 |
| 2519 FunctionElement helperForMissingMain() => helpers.missingMain; | 2502 FunctionElement helperForMissingMain() => helpers.missingMain; |
| 2520 | 2503 |
| 2521 FunctionElement helperForMainArity() => helpers.mainHasTooManyParameters; | 2504 FunctionElement helperForMainArity() => helpers.mainHasTooManyParameters; |
| 2522 | 2505 |
| 2523 void forgetElement(Element element) { | |
| 2524 constants.forgetElement(element); | |
| 2525 constantCompilerTask.dartConstantCompiler.forgetElement(element); | |
| 2526 aliasedSuperMembers.remove(element); | |
| 2527 generatedCode.remove(element); | |
| 2528 if (element is MemberElement) { | |
| 2529 for (Element closure in element.nestedClosures) { | |
| 2530 generatedCode.remove(closure); | |
| 2531 } | |
| 2532 } | |
| 2533 } | |
| 2534 | |
| 2535 @override | 2506 @override |
| 2536 WorldImpact computeMainImpact(MethodElement mainMethod, | 2507 WorldImpact computeMainImpact(MethodElement mainMethod, |
| 2537 {bool forResolution}) { | 2508 {bool forResolution}) { |
| 2538 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); | 2509 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); |
| 2539 if (mainMethod.parameters.isNotEmpty) { | 2510 if (mainMethod.parameters.isNotEmpty) { |
| 2540 impactTransformer.registerBackendImpact( | 2511 impactTransformer.registerBackendImpact( |
| 2541 mainImpact, impacts.mainWithArguments); | 2512 mainImpact, impacts.mainWithArguments); |
| 2542 mainImpact.registerStaticUse( | 2513 mainImpact.registerStaticUse( |
| 2543 new StaticUse.staticInvoke(mainMethod, CallStructure.TWO_ARGS)); | 2514 new StaticUse.staticInvoke(mainMethod, CallStructure.TWO_ARGS)); |
| 2544 // If the main method takes arguments, this compilation could be the | 2515 // If the main method takes arguments, this compilation could be the |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3306 @override | 3277 @override |
| 3307 bool isNativeClass(ClassElement element) { | 3278 bool isNativeClass(ClassElement element) { |
| 3308 return helpers.backend.isNative(element); | 3279 return helpers.backend.isNative(element); |
| 3309 } | 3280 } |
| 3310 | 3281 |
| 3311 @override | 3282 @override |
| 3312 bool isNativeMember(MemberElement element) { | 3283 bool isNativeMember(MemberElement element) { |
| 3313 return helpers.backend.isNative(element); | 3284 return helpers.backend.isNative(element); |
| 3314 } | 3285 } |
| 3315 } | 3286 } |
| OLD | NEW |