| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 dart2js.kernel.impact_test; | 5 library dart2js.kernel.impact_test; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/commandline_options.dart'; | 8 import 'package:compiler/src/commandline_options.dart'; |
| 9 import 'package:compiler/src/common.dart'; | 9 import 'package:compiler/src/common.dart'; |
| 10 import 'package:compiler/src/common/names.dart'; | 10 import 'package:compiler/src/common/names.dart'; |
| 11 import 'package:compiler/src/common/resolution.dart'; | 11 import 'package:compiler/src/common/resolution.dart'; |
| 12 import 'package:compiler/src/compiler.dart'; | 12 import 'package:compiler/src/compiler.dart'; |
| 13 import 'package:compiler/src/constants/expressions.dart'; | 13 import 'package:compiler/src/constants/expressions.dart'; |
| 14 import 'package:compiler/src/elements/resolution_types.dart'; | 14 import 'package:compiler/src/elements/resolution_types.dart'; |
| 15 import 'package:compiler/src/elements/elements.dart'; | 15 import 'package:compiler/src/elements/elements.dart'; |
| 16 import 'package:compiler/src/js_backend/backend.dart'; |
| 17 import 'package:compiler/src/kernel/world_builder.dart'; |
| 18 import 'package:compiler/src/kernel/element_adapter.dart'; |
| 16 import 'package:compiler/src/resolution/registry.dart'; | 19 import 'package:compiler/src/resolution/registry.dart'; |
| 17 import 'package:compiler/src/resolution/tree_elements.dart'; | 20 import 'package:compiler/src/resolution/tree_elements.dart'; |
| 18 import 'package:compiler/src/ssa/kernel_impact.dart'; | 21 import 'package:compiler/src/ssa/kernel_impact.dart'; |
| 19 import 'package:compiler/src/serialization/equivalence.dart'; | 22 import 'package:compiler/src/serialization/equivalence.dart'; |
| 20 import 'package:compiler/src/universe/call_structure.dart'; | 23 import 'package:compiler/src/universe/call_structure.dart'; |
| 21 import 'package:compiler/src/universe/feature.dart'; | 24 import 'package:compiler/src/universe/feature.dart'; |
| 22 import 'package:compiler/src/universe/use.dart'; | 25 import 'package:compiler/src/universe/use.dart'; |
| 23 import 'package:expect/expect.dart'; | 26 import 'package:expect/expect.dart'; |
| 27 import 'package:kernel/ast.dart' as ir; |
| 24 import '../memory_compiler.dart'; | 28 import '../memory_compiler.dart'; |
| 25 import '../serialization/test_helper.dart'; | 29 import '../serialization/test_helper.dart'; |
| 26 | 30 |
| 27 const Map<String, String> SOURCE = const <String, String>{ | 31 const Map<String, String> SOURCE = const <String, String>{ |
| 28 'main.dart': r''' | 32 'main.dart': r''' |
| 29 import 'helper.dart'; | 33 import 'helper.dart'; |
| 30 import 'dart:html'; | 34 import 'dart:html'; |
| 31 | 35 |
| 32 main() { | 36 main() { |
| 33 testEmpty(); | 37 testEmpty(); |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 Compiler compiler = compilerFor( | 625 Compiler compiler = compilerFor( |
| 622 entryPoint: entryPoint, | 626 entryPoint: entryPoint, |
| 623 memorySourceFiles: SOURCE, | 627 memorySourceFiles: SOURCE, |
| 624 options: [ | 628 options: [ |
| 625 fullTest ? Flags.analyzeAll : Flags.analyzeOnly, | 629 fullTest ? Flags.analyzeAll : Flags.analyzeOnly, |
| 626 Flags.useKernel, | 630 Flags.useKernel, |
| 627 Flags.enableAssertMessage | 631 Flags.enableAssertMessage |
| 628 ]); | 632 ]); |
| 629 compiler.resolution.retainCachesForTesting = true; | 633 compiler.resolution.retainCachesForTesting = true; |
| 630 await compiler.run(entryPoint); | 634 await compiler.run(entryPoint); |
| 631 checkLibrary(compiler, compiler.mainApp, fullTest: fullTest); | 635 JavaScriptBackend backend = compiler.backend; |
| 636 KernelElementAdapter kernelElementAdapter = |
| 637 new KernelWorldBuilder(compiler.reporter, backend.kernelTask.program); |
| 638 |
| 639 checkLibrary(compiler, kernelElementAdapter, compiler.mainApp, |
| 640 fullTest: fullTest); |
| 632 if (fullTest) { | 641 if (fullTest) { |
| 633 // TODO(johnniwinther): Handle all libraries for `!fullTest`. | 642 // TODO(johnniwinther): Handle all libraries for `!fullTest`. |
| 634 compiler.libraryLoader.libraries.forEach((LibraryElement library) { | 643 compiler.libraryLoader.libraries.forEach((LibraryElement library) { |
| 635 if (library == compiler.mainApp) return; | 644 if (library == compiler.mainApp) return; |
| 636 checkLibrary(compiler, library, fullTest: fullTest); | 645 checkLibrary(compiler, kernelElementAdapter, library, |
| 646 fullTest: fullTest); |
| 637 }); | 647 }); |
| 638 } | 648 } |
| 639 }); | 649 }); |
| 640 } | 650 } |
| 641 | 651 |
| 642 void checkLibrary(Compiler compiler, LibraryElement library, | 652 void checkLibrary(Compiler compiler, KernelElementAdapter kernelElementAdapter, |
| 653 LibraryElement library, |
| 643 {bool fullTest: false}) { | 654 {bool fullTest: false}) { |
| 644 library.forEachLocalMember((AstElement element) { | 655 library.forEachLocalMember((AstElement element) { |
| 645 if (element.isClass) { | 656 if (element.isClass) { |
| 646 ClassElement cls = element; | 657 ClassElement cls = element; |
| 647 cls.forEachLocalMember((AstElement member) { | 658 cls.forEachLocalMember((AstElement member) { |
| 648 checkElement(compiler, member, fullTest: fullTest); | 659 checkElement(compiler, kernelElementAdapter, member, |
| 660 fullTest: fullTest); |
| 649 }); | 661 }); |
| 650 } else if (element.isTypedef) { | 662 } else if (element.isTypedef) { |
| 651 // Skip typedefs. | 663 // Skip typedefs. |
| 652 } else { | 664 } else { |
| 653 checkElement(compiler, element, fullTest: fullTest); | 665 checkElement(compiler, kernelElementAdapter, element, fullTest: fullTest); |
| 654 } | 666 } |
| 655 }); | 667 }); |
| 656 } | 668 } |
| 657 | 669 |
| 658 void checkElement(Compiler compiler, AstElement element, | 670 void checkElement(Compiler compiler, KernelElementAdapter kernelElementAdapter, |
| 671 AstElement element, |
| 659 {bool fullTest: false}) { | 672 {bool fullTest: false}) { |
| 660 if (!fullTest) { | 673 if (!fullTest) { |
| 661 if (element.library.isPlatformLibrary) { | 674 if (element.library.isPlatformLibrary) { |
| 662 // TODO(johnniwinther): Enqueue these elements for `!fullTest`. | 675 // TODO(johnniwinther): Enqueue these elements for `!fullTest`. |
| 663 // Test only selected elements in web-related platform libraries since | 676 // Test only selected elements in web-related platform libraries since |
| 664 // this unittest otherwise takes too long to run. | 677 // this unittest otherwise takes too long to run. |
| 665 switch (element.library.canonicalUri.path) { | 678 switch (element.library.canonicalUri.path) { |
| 666 case 'html': | 679 case 'html': |
| 667 if ('$element' == | 680 if ('$element' == |
| 668 'function(_ValidatingTreeSanitizer#_sanitizeUntrustedElement)') { | 681 'function(_ValidatingTreeSanitizer#_sanitizeUntrustedElement)') { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 688 if (element.isConstructor) { | 701 if (element.isConstructor) { |
| 689 ConstructorElement constructor = element; | 702 ConstructorElement constructor = element; |
| 690 if (constructor.isRedirectingFactory) { | 703 if (constructor.isRedirectingFactory) { |
| 691 // Skip redirecting constructors for now; they might not be supported. | 704 // Skip redirecting constructors for now; they might not be supported. |
| 692 return; | 705 return; |
| 693 } | 706 } |
| 694 } | 707 } |
| 695 if (!fullTest && !compiler.resolution.hasResolutionImpact(element)) { | 708 if (!fullTest && !compiler.resolution.hasResolutionImpact(element)) { |
| 696 return; | 709 return; |
| 697 } | 710 } |
| 698 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); | 711 compiler.reporter.withCurrentElement(element.implementation, () { |
| 699 astImpact = laxImpact(compiler, element, astImpact); | 712 ResolutionImpact astImpact = |
| 700 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); | 713 compiler.resolution.getResolutionImpact(element); |
| 701 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); | 714 astImpact = laxImpact(compiler, element, astImpact); |
| 702 testResolutionImpactEquivalence( | 715 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); |
| 703 astImpact, kernelImpact, const CheckStrategy()); | 716 ir.Member member = getIrMember(compiler, element.resolvedAst); |
| 717 // TODO(johnniwinther): Check equivalence for the computed impact. |
| 718 buildKernelImpact(member, kernelElementAdapter); |
| 719 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); |
| 720 testResolutionImpactEquivalence( |
| 721 astImpact, kernelImpact, const CheckStrategy()); |
| 722 }); |
| 704 } | 723 } |
| 705 | 724 |
| 706 /// Lax the precision of [impact] to meet expectancy of the corresponding impact | 725 /// Lax the precision of [impact] to meet expectancy of the corresponding impact |
| 707 /// generated from kernel. | 726 /// generated from kernel. |
| 708 ResolutionImpact laxImpact( | 727 ResolutionImpact laxImpact( |
| 709 Compiler compiler, AstElement element, ResolutionImpact impact) { | 728 Compiler compiler, AstElement element, ResolutionImpact impact) { |
| 710 ResolutionWorldImpactBuilder builder = | 729 ResolutionWorldImpactBuilder builder = |
| 711 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); | 730 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); |
| 712 for (StaticUse staticUse in impact.staticUses) { | 731 for (StaticUse staticUse in impact.staticUses) { |
| 713 switch (staticUse.kind) { | 732 switch (staticUse.kind) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 visitList(type.optionalParameterTypes), | 852 visitList(type.optionalParameterTypes), |
| 834 type.namedParameters, | 853 type.namedParameters, |
| 835 visitList(type.namedParameterTypes)); | 854 visitList(type.namedParameterTypes)); |
| 836 } | 855 } |
| 837 } | 856 } |
| 838 | 857 |
| 839 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType]. | 858 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType]. |
| 840 ResolutionDartType unalias(ResolutionDartType type) { | 859 ResolutionDartType unalias(ResolutionDartType type) { |
| 841 return const Unaliaser().visit(type); | 860 return const Unaliaser().visit(type); |
| 842 } | 861 } |
| OLD | NEW |