Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: tests/compiler/dart2js/simple_inferrer_test.dart

Issue 2278213003: Rename the global inference task and reduce it's API surface by introducing the (Closed)
Patch Set: cl comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import "package:async_helper/async_helper.dart"; 6 import "package:async_helper/async_helper.dart";
7 import 'package:compiler/src/types/types.dart' show TypeMask; 7 import 'package:compiler/src/types/types.dart' show TypeMask;
8 import 'type_mask_test_helper.dart'; 8 import 'type_mask_test_helper.dart';
9 9
10 import 'compiler_helper.dart'; 10 import 'compiler_helper.dart';
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 testReturnNull6(); 720 testReturnNull6();
721 testReturnNotEquals(); 721 testReturnNotEquals();
722 } 722 }
723 """; 723 """;
724 724
725 void main() { 725 void main() {
726 Uri uri = new Uri(scheme: 'source'); 726 Uri uri = new Uri(scheme: 'source');
727 var compiler = compilerFor(TEST, uri); 727 var compiler = compilerFor(TEST, uri);
728 compiler.diagnosticHandler = createHandler(compiler, TEST); 728 compiler.diagnosticHandler = createHandler(compiler, TEST);
729 asyncTest(() => compiler.run(uri).then((_) { 729 asyncTest(() => compiler.run(uri).then((_) {
730 var typesTask = compiler.typesTask; 730 var commonMasks = compiler.commonMasks;
731 var typesInferrer = typesTask.typesInferrer; 731 var typesInferrer = compiler.globalInference.typesInferrer;
732 var world = compiler.world; 732 var world = compiler.world;
733 733
734 checkReturn(String name, type) { 734 checkReturn(String name, type) {
735 var element = findElement(compiler, name); 735 var element = findElement(compiler, name);
736 Expect.equals( 736 Expect.equals(
737 type, 737 type,
738 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), 738 simplify(typesInferrer.getReturnTypeOfElement(element), compiler),
739 name); 739 name);
740 } 740 }
741 var interceptorType = 741 var interceptorType =
742 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); 742 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
743 743
744 checkReturn('returnNum1', typesTask.numType); 744 checkReturn('returnNum1', commonMasks.numType);
745 checkReturn('returnNum2', typesTask.numType); 745 checkReturn('returnNum2', commonMasks.numType);
746 checkReturn('returnInt1', typesTask.uint31Type); 746 checkReturn('returnInt1', commonMasks.uint31Type);
747 checkReturn('returnInt2', typesTask.uint31Type); 747 checkReturn('returnInt2', commonMasks.uint31Type);
748 checkReturn('returnDouble', typesTask.doubleType); 748 checkReturn('returnDouble', commonMasks.doubleType);
749 checkReturn('returnGiveUp', interceptorType); 749 checkReturn('returnGiveUp', interceptorType);
750 checkReturn('returnInt5', typesTask.uint32Type); // uint31+uint31->uint32 750 checkReturn('returnInt5', commonMasks.uint32Type); // uint31+uint31->uint32
751 checkReturn('returnInt6', typesTask.uint32Type); // uint31+uint31->uint32 751 checkReturn('returnInt6', commonMasks.uint32Type); // uint31+uint31->uint32
752 checkReturn('returnIntOrNull', typesTask.uint31Type.nullable()); 752 checkReturn('returnIntOrNull', commonMasks.uint31Type.nullable());
753 checkReturn('returnInt3', typesTask.uint31Type); 753 checkReturn('returnInt3', commonMasks.uint31Type);
754 checkReturn('returnDynamic', typesTask.dynamicType); 754 checkReturn('returnDynamic', commonMasks.dynamicType);
755 checkReturn('returnInt4', typesTask.uint31Type); 755 checkReturn('returnInt4', commonMasks.uint31Type);
756 checkReturn('returnInt7', typesTask.positiveIntType); 756 checkReturn('returnInt7', commonMasks.positiveIntType);
757 checkReturn('returnInt8', typesTask.positiveIntType); 757 checkReturn('returnInt8', commonMasks.positiveIntType);
758 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); 758 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty());
759 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); 759 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty());
760 TypeMask intType = new TypeMask.nonNullSubtype( 760 TypeMask intType = new TypeMask.nonNullSubtype(
761 compiler.coreClasses.intClass, compiler.world); 761 compiler.coreClasses.intClass, compiler.world);
762 checkReturn('testIsCheck1', intType); 762 checkReturn('testIsCheck1', intType);
763 checkReturn('testIsCheck2', intType); 763 checkReturn('testIsCheck2', intType);
764 checkReturn('testIsCheck3', intType.nullable()); 764 checkReturn('testIsCheck3', intType.nullable());
765 checkReturn('testIsCheck4', intType); 765 checkReturn('testIsCheck4', intType);
766 checkReturn('testIsCheck5', intType); 766 checkReturn('testIsCheck5', intType);
767 checkReturn('testIsCheck6', typesTask.dynamicType); 767 checkReturn('testIsCheck6', commonMasks.dynamicType);
768 checkReturn('testIsCheck7', intType); 768 checkReturn('testIsCheck7', intType);
769 checkReturn('testIsCheck8', typesTask.dynamicType); 769 checkReturn('testIsCheck8', commonMasks.dynamicType);
770 checkReturn('testIsCheck9', intType); 770 checkReturn('testIsCheck9', intType);
771 checkReturn('testIsCheck10', typesTask.dynamicType); 771 checkReturn('testIsCheck10', commonMasks.dynamicType);
772 checkReturn('testIsCheck11', intType); 772 checkReturn('testIsCheck11', intType);
773 checkReturn('testIsCheck12', typesTask.dynamicType); 773 checkReturn('testIsCheck12', commonMasks.dynamicType);
774 checkReturn('testIsCheck13', intType); 774 checkReturn('testIsCheck13', intType);
775 checkReturn('testIsCheck14', typesTask.dynamicType); 775 checkReturn('testIsCheck14', commonMasks.dynamicType);
776 checkReturn('testIsCheck15', intType); 776 checkReturn('testIsCheck15', intType);
777 checkReturn('testIsCheck16', typesTask.dynamicType); 777 checkReturn('testIsCheck16', commonMasks.dynamicType);
778 checkReturn('testIsCheck17', intType); 778 checkReturn('testIsCheck17', intType);
779 checkReturn('testIsCheck18', typesTask.dynamicType); 779 checkReturn('testIsCheck18', commonMasks.dynamicType);
780 checkReturn('testIsCheck19', typesTask.dynamicType); 780 checkReturn('testIsCheck19', commonMasks.dynamicType);
781 checkReturn('testIsCheck20', interceptorType); 781 checkReturn('testIsCheck20', interceptorType);
782 checkReturn('testIsCheck21', typesTask.dynamicType); 782 checkReturn('testIsCheck21', commonMasks.dynamicType);
783 checkReturn('testIsCheck22', typesTask.dynamicType); 783 checkReturn('testIsCheck22', commonMasks.dynamicType);
784 checkReturn('testIsCheck23', intType); 784 checkReturn('testIsCheck23', intType);
785 checkReturn('testIsCheck24', intType); 785 checkReturn('testIsCheck24', intType);
786 checkReturn('testIsCheck25', typesTask.dynamicType); 786 checkReturn('testIsCheck25', commonMasks.dynamicType);
787 checkReturn('testIsCheck26', intType); 787 checkReturn('testIsCheck26', intType);
788 checkReturn('testIsCheck27', intType); 788 checkReturn('testIsCheck27', intType);
789 checkReturn('testIsCheck28', typesTask.dynamicType); 789 checkReturn('testIsCheck28', commonMasks.dynamicType);
790 checkReturn('testIsCheck29', typesTask.dynamicType); 790 checkReturn('testIsCheck29', commonMasks.dynamicType);
791 checkReturn('testIf1', typesTask.uint31Type.nullable()); 791 checkReturn('testIf1', commonMasks.uint31Type.nullable());
792 checkReturn('testIf2', typesTask.uint31Type.nullable()); 792 checkReturn('testIf2', commonMasks.uint31Type.nullable());
793 checkReturn('returnAsString', new TypeMask.subtype( 793 checkReturn('returnAsString', new TypeMask.subtype(
794 compiler.coreClasses.stringClass, compiler.world)); 794 compiler.coreClasses.stringClass, compiler.world));
795 checkReturn('returnIntAsNum', typesTask.uint31Type); 795 checkReturn('returnIntAsNum', commonMasks.uint31Type);
796 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); 796 checkReturn('returnAsTypedef', commonMasks.functionType.nullable());
797 checkReturn('returnTopLevelGetter', typesTask.uint31Type); 797 checkReturn('returnTopLevelGetter', commonMasks.uint31Type);
798 checkReturn('testDeadCode', typesTask.uint31Type); 798 checkReturn('testDeadCode', commonMasks.uint31Type);
799 checkReturn('testLabeledIf', typesTask.uint31Type.nullable()); 799 checkReturn('testLabeledIf', commonMasks.uint31Type.nullable());
800 checkReturn('testSwitch1', simplify( 800 checkReturn('testSwitch1', simplify(
801 typesTask.intType 801 commonMasks.intType
802 .union(typesTask.doubleType, compiler.world) 802 .union(commonMasks.doubleType, compiler.world)
803 .nullable(), 803 .nullable(),
804 compiler)); 804 compiler));
805 checkReturn('testSwitch2', typesTask.uint31Type); 805 checkReturn('testSwitch2', commonMasks.uint31Type);
806 checkReturn('testSwitch3', interceptorType.nullable()); 806 checkReturn('testSwitch3', interceptorType.nullable());
807 checkReturn('testSwitch4', typesTask.uint31Type); 807 checkReturn('testSwitch4', commonMasks.uint31Type);
808 checkReturn('testSwitch5', typesTask.uint31Type); 808 checkReturn('testSwitch5', commonMasks.uint31Type);
809 checkReturn('testContinue1', interceptorType.nullable()); 809 checkReturn('testContinue1', interceptorType.nullable());
810 checkReturn('testBreak1', interceptorType.nullable()); 810 checkReturn('testBreak1', interceptorType.nullable());
811 checkReturn('testContinue2', interceptorType.nullable()); 811 checkReturn('testContinue2', interceptorType.nullable());
812 checkReturn('testBreak2', typesTask.uint32Type.nullable()); 812 checkReturn('testBreak2', commonMasks.uint32Type.nullable());
813 checkReturn('testReturnElementOfConstList1', typesTask.uint31Type); 813 checkReturn('testReturnElementOfConstList1', commonMasks.uint31Type);
814 checkReturn('testReturnElementOfConstList2', typesTask.uint31Type); 814 checkReturn('testReturnElementOfConstList2', commonMasks.uint31Type);
815 checkReturn('testReturnItselfOrInt', typesTask.uint31Type); 815 checkReturn('testReturnItselfOrInt', commonMasks.uint31Type);
816 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); 816 checkReturn('testReturnInvokeDynamicGetter', commonMasks.dynamicType);
817 817
818 checkReturn('testDoWhile1', typesTask.stringType); 818 checkReturn('testDoWhile1', commonMasks.stringType);
819 checkReturn('testDoWhile2', typesTask.nullType); 819 checkReturn('testDoWhile2', commonMasks.nullType);
820 checkReturn('testDoWhile3', typesTask.uint31Type); 820 checkReturn('testDoWhile3', commonMasks.uint31Type);
821 checkReturn('testDoWhile4', typesTask.numType); 821 checkReturn('testDoWhile4', commonMasks.numType);
822 822
823 checkReturnInClass(String className, String methodName, type) { 823 checkReturnInClass(String className, String methodName, type) {
824 var cls = findElement(compiler, className); 824 var cls = findElement(compiler, className);
825 var element = cls.lookupLocalMember(methodName); 825 var element = cls.lookupLocalMember(methodName);
826 Expect.equals(type, 826 Expect.equals(type,
827 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), 827 simplify(typesInferrer.getReturnTypeOfElement(element), compiler),
828 '$className:$methodName'); 828 '$className:$methodName');
829 } 829 }
830 830
831 checkReturnInClass('A', 'returnInt1', typesTask.uint32Type); 831 checkReturnInClass('A', 'returnInt1', commonMasks.uint32Type);
832 checkReturnInClass('A', 'returnInt2', typesTask.uint32Type); 832 checkReturnInClass('A', 'returnInt2', commonMasks.uint32Type);
833 checkReturnInClass('A', 'returnInt3', typesTask.uint32Type); 833 checkReturnInClass('A', 'returnInt3', commonMasks.uint32Type);
834 checkReturnInClass('A', 'returnInt4', typesTask.uint32Type); 834 checkReturnInClass('A', 'returnInt4', commonMasks.uint32Type);
835 checkReturnInClass('A', 'returnInt5', typesTask.uint32Type); 835 checkReturnInClass('A', 'returnInt5', commonMasks.uint32Type);
836 checkReturnInClass('A', 'returnInt6', typesTask.uint32Type); 836 checkReturnInClass('A', 'returnInt6', commonMasks.uint32Type);
837 checkReturnInClass('A', '==', interceptorType); 837 checkReturnInClass('A', '==', interceptorType);
838 838
839 checkReturnInClass('B', 'returnInt1', typesTask.uint32Type); 839 checkReturnInClass('B', 'returnInt1', commonMasks.uint32Type);
840 checkReturnInClass('B', 'returnInt2', typesTask.uint32Type); 840 checkReturnInClass('B', 'returnInt2', commonMasks.uint32Type);
841 checkReturnInClass('B', 'returnInt3', typesTask.uint32Type); 841 checkReturnInClass('B', 'returnInt3', commonMasks.uint32Type);
842 checkReturnInClass('B', 'returnInt4', typesTask.uint32Type); 842 checkReturnInClass('B', 'returnInt4', commonMasks.uint32Type);
843 checkReturnInClass('B', 'returnInt5', typesTask.uint32Type); 843 checkReturnInClass('B', 'returnInt5', commonMasks.uint32Type);
844 checkReturnInClass('B', 'returnInt6', typesTask.uint32Type); 844 checkReturnInClass('B', 'returnInt6', commonMasks.uint32Type);
845 checkReturnInClass('B', 'returnInt7', typesTask.uint32Type); 845 checkReturnInClass('B', 'returnInt7', commonMasks.uint32Type);
846 checkReturnInClass('B', 'returnInt8', typesTask.uint32Type); 846 checkReturnInClass('B', 'returnInt8', commonMasks.uint32Type);
847 checkReturnInClass('B', 'returnInt9', typesTask.uint31Type); 847 checkReturnInClass('B', 'returnInt9', commonMasks.uint31Type);
848 848
849 checkReturnInClass('C', 'returnInt1', typesTask.positiveIntType); 849 checkReturnInClass('C', 'returnInt1', commonMasks.positiveIntType);
850 checkReturnInClass('C', 'returnInt2', typesTask.positiveIntType); 850 checkReturnInClass('C', 'returnInt2', commonMasks.positiveIntType);
851 checkReturnInClass('C', 'returnInt3', typesTask.positiveIntType); 851 checkReturnInClass('C', 'returnInt3', commonMasks.positiveIntType);
852 checkReturnInClass('C', 'returnInt4', typesTask.positiveIntType); 852 checkReturnInClass('C', 'returnInt4', commonMasks.positiveIntType);
853 checkReturnInClass('C', 'returnInt5', typesTask.positiveIntType); 853 checkReturnInClass('C', 'returnInt5', commonMasks.positiveIntType);
854 checkReturnInClass('C', 'returnInt6', typesTask.positiveIntType); 854 checkReturnInClass('C', 'returnInt6', commonMasks.positiveIntType);
855 855
856 checkFactoryConstructor(String className, String factoryName) { 856 checkFactoryConstructor(String className, String factoryName) {
857 var cls = findElement(compiler, className); 857 var cls = findElement(compiler, className);
858 var element = cls.localLookup(factoryName); 858 var element = cls.localLookup(factoryName);
859 Expect.equals(new TypeMask.nonNullExact(cls, world), 859 Expect.equals(new TypeMask.nonNullExact(cls, world),
860 typesInferrer.getReturnTypeOfElement(element)); 860 typesInferrer.getReturnTypeOfElement(element));
861 } 861 }
862 checkFactoryConstructor('A', ''); 862 checkFactoryConstructor('A', '');
863 863
864 checkReturn('testCascade1', typesTask.growableListType); 864 checkReturn('testCascade1', commonMasks.growableListType);
865 checkReturn('testCascade2', new TypeMask.nonNullExact( 865 checkReturn('testCascade2', new TypeMask.nonNullExact(
866 findElement(compiler, 'CascadeHelper'), world)); 866 findElement(compiler, 'CascadeHelper'), world));
867 checkReturn('testSpecialization1', typesTask.numType); 867 checkReturn('testSpecialization1', commonMasks.numType);
868 checkReturn('testSpecialization2', typesTask.dynamicType); 868 checkReturn('testSpecialization2', commonMasks.dynamicType);
869 checkReturn('testSpecialization3', typesTask.uint31Type.nullable()); 869 checkReturn('testSpecialization3', commonMasks.uint31Type.nullable());
870 checkReturn('testReturnNull1', typesTask.nullType); 870 checkReturn('testReturnNull1', commonMasks.nullType);
871 checkReturn('testReturnNull2', typesTask.nullType); 871 checkReturn('testReturnNull2', commonMasks.nullType);
872 checkReturn('testReturnNull3', typesTask.dynamicType); 872 checkReturn('testReturnNull3', commonMasks.dynamicType);
873 checkReturn('testReturnNull4', typesTask.nullType); 873 checkReturn('testReturnNull4', commonMasks.nullType);
874 checkReturn('testReturnNull5', typesTask.nullType); 874 checkReturn('testReturnNull5', commonMasks.nullType);
875 checkReturn('testReturnNull6', typesTask.dynamicType); 875 checkReturn('testReturnNull6', commonMasks.dynamicType);
876 checkReturn('testReturnNotEquals', typesTask.boolType); 876 checkReturn('testReturnNotEquals', commonMasks.boolType);
877 })); 877 }));
878 } 878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698