| 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'; |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 const factory GenericClass.redirect() = GenericClass<X, Y>.generative; | 607 const factory GenericClass.redirect() = GenericClass<X, Y>.generative; |
| 608 | 608 |
| 609 Map<X, T> genericMethod<T>(T arg) => { null: arg }; | 609 Map<X, T> genericMethod<T>(T arg) => { null: arg }; |
| 610 } | 610 } |
| 611 typedef Typedef(); | 611 typedef Typedef(); |
| 612 typedef X GenericTypedef<X, Y>(Y y); | 612 typedef X GenericTypedef<X, Y>(Y y); |
| 613 ''', | 613 ''', |
| 614 }; | 614 }; |
| 615 | 615 |
| 616 main(List<String> args) { | 616 main(List<String> args) { |
| 617 bool fullTest = args.contains('--full'); |
| 617 asyncTest(() async { | 618 asyncTest(() async { |
| 618 enableDebugMode(); | 619 enableDebugMode(); |
| 619 Uri entryPoint = Uri.parse('memory:main.dart'); | 620 Uri entryPoint = Uri.parse('memory:main.dart'); |
| 620 Compiler compiler = compilerFor( | 621 Compiler compiler = compilerFor( |
| 621 entryPoint: entryPoint, | 622 entryPoint: entryPoint, |
| 622 memorySourceFiles: SOURCE, | 623 memorySourceFiles: SOURCE, |
| 623 options: [ | 624 options: [ |
| 624 Flags.analyzeAll, | 625 fullTest ? Flags.analyzeAll : Flags.analyzeOnly, |
| 625 Flags.useKernel, | 626 Flags.useKernel, |
| 626 Flags.enableAssertMessage | 627 Flags.enableAssertMessage |
| 627 ]); | 628 ]); |
| 628 compiler.resolution.retainCachesForTesting = true; | 629 compiler.resolution.retainCachesForTesting = true; |
| 629 await compiler.run(entryPoint); | 630 await compiler.run(entryPoint); |
| 630 checkLibrary(compiler, compiler.mainApp, fullTest: args.contains('--full')); | 631 checkLibrary(compiler, compiler.mainApp, fullTest: fullTest); |
| 631 compiler.libraryLoader.libraries.forEach((LibraryElement library) { | 632 if (fullTest) { |
| 632 if (library == compiler.mainApp) return; | 633 // TODO(johnniwinther): Handle all libraries for `!fullTest`. |
| 633 checkLibrary(compiler, library, fullTest: args.contains('--full')); | 634 compiler.libraryLoader.libraries.forEach((LibraryElement library) { |
| 634 }); | 635 if (library == compiler.mainApp) return; |
| 636 checkLibrary(compiler, library, fullTest: fullTest); |
| 637 }); |
| 638 } |
| 635 }); | 639 }); |
| 636 } | 640 } |
| 637 | 641 |
| 638 void checkLibrary(Compiler compiler, LibraryElement library, | 642 void checkLibrary(Compiler compiler, LibraryElement library, |
| 639 {bool fullTest: false}) { | 643 {bool fullTest: false}) { |
| 640 library.forEachLocalMember((AstElement element) { | 644 library.forEachLocalMember((AstElement element) { |
| 641 if (element.isClass) { | 645 if (element.isClass) { |
| 642 ClassElement cls = element; | 646 ClassElement cls = element; |
| 643 cls.forEachLocalMember((AstElement member) { | 647 cls.forEachLocalMember((AstElement member) { |
| 644 checkElement(compiler, member, fullTest: fullTest); | 648 checkElement(compiler, member, fullTest: fullTest); |
| 645 }); | 649 }); |
| 646 } else if (element.isTypedef) { | 650 } else if (element.isTypedef) { |
| 647 // Skip typedefs. | 651 // Skip typedefs. |
| 648 } else { | 652 } else { |
| 649 checkElement(compiler, element, fullTest: fullTest); | 653 checkElement(compiler, element, fullTest: fullTest); |
| 650 } | 654 } |
| 651 }); | 655 }); |
| 652 } | 656 } |
| 653 | 657 |
| 654 void checkElement(Compiler compiler, AstElement element, | 658 void checkElement(Compiler compiler, AstElement element, |
| 655 {bool fullTest: false}) { | 659 {bool fullTest: false}) { |
| 656 if (!fullTest) { | 660 if (!fullTest) { |
| 657 if (element.library.isPlatformLibrary) { | 661 if (element.library.isPlatformLibrary) { |
| 662 // TODO(johnniwinther): Enqueue these elements for `!fullTest`. |
| 658 // Test only selected elements in web-related platform libraries since | 663 // Test only selected elements in web-related platform libraries since |
| 659 // this unittest otherwise takes too long to run. | 664 // this unittest otherwise takes too long to run. |
| 660 switch (element.library.canonicalUri.path) { | 665 switch (element.library.canonicalUri.path) { |
| 661 case 'html': | 666 case 'html': |
| 662 if ('$element' == | 667 if ('$element' == |
| 663 'function(_ValidatingTreeSanitizer#_sanitizeUntrustedElement)') { | 668 'function(_ValidatingTreeSanitizer#_sanitizeUntrustedElement)') { |
| 664 break; | 669 break; |
| 665 } | 670 } |
| 666 return; | 671 return; |
| 667 case 'web_gl': | 672 case 'web_gl': |
| 668 if ('$element' == | 673 if ('$element' == |
| 669 'function(RenderingContext#getFramebufferAttachmentParameter)') { | 674 'function(RenderingContext#getFramebufferAttachmentParameter)') { |
| 670 return; | 675 break; |
| 671 } | 676 } |
| 672 break; | 677 return; |
| 673 case 'indexed_db': | 678 case 'indexed_db': |
| 674 if ('$element' == 'field(ObjectStore#keyPath)') { | 679 if ('$element' == 'field(ObjectStore#keyPath)') { |
| 675 break; | 680 break; |
| 676 } | 681 } |
| 677 return; | 682 return; |
| 678 case 'web_audio': | 683 case 'web_audio': |
| 679 return; | 684 return; |
| 680 } | 685 } |
| 681 } | 686 } |
| 682 } | 687 } |
| 683 if (element.isConstructor) { | 688 if (element.isConstructor) { |
| 684 ConstructorElement constructor = element; | 689 ConstructorElement constructor = element; |
| 685 if (constructor.isRedirectingFactory) { | 690 if (constructor.isRedirectingFactory) { |
| 686 // Skip redirecting constructors for now; they might not be supported. | 691 // Skip redirecting constructors for now; they might not be supported. |
| 687 return; | 692 return; |
| 688 } | 693 } |
| 689 } | 694 } |
| 695 if (!fullTest && !compiler.resolution.hasResolutionImpact(element)) { |
| 696 return; |
| 697 } |
| 690 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); | 698 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); |
| 691 astImpact = laxImpact(compiler, element, astImpact); | 699 astImpact = laxImpact(compiler, element, astImpact); |
| 692 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); | 700 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); |
| 693 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); | 701 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); |
| 694 testResolutionImpactEquivalence( | 702 testResolutionImpactEquivalence( |
| 695 astImpact, kernelImpact, const CheckStrategy()); | 703 astImpact, kernelImpact, const CheckStrategy()); |
| 696 } | 704 } |
| 697 | 705 |
| 698 /// Lax the precision of [impact] to meet expectancy of the corresponding impact | 706 /// Lax the precision of [impact] to meet expectancy of the corresponding impact |
| 699 /// generated from kernel. | 707 /// generated from kernel. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 visitList(type.optionalParameterTypes), | 833 visitList(type.optionalParameterTypes), |
| 826 type.namedParameters, | 834 type.namedParameters, |
| 827 visitList(type.namedParameterTypes)); | 835 visitList(type.namedParameterTypes)); |
| 828 } | 836 } |
| 829 } | 837 } |
| 830 | 838 |
| 831 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType]. | 839 /// Perform unaliasing of all typedefs nested within a [ResolutionDartType]. |
| 832 ResolutionDartType unalias(ResolutionDartType type) { | 840 ResolutionDartType unalias(ResolutionDartType type) { |
| 833 return const Unaliaser().visit(type); | 841 return const Unaliaser().visit(type); |
| 834 } | 842 } |
| OLD | NEW |