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

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

Issue 2577423002: Further reduce use of Compiler.closedWorld. (Closed)
Patch Set: Created 4 years 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 commonMasks = compiler.closedWorld.commonMasks;
731 var typesInferrer = compiler.globalInference.typesInferrerInternal; 730 var typesInferrer = compiler.globalInference.typesInferrerInternal;
732 var world = compiler.closedWorld; 731 var closedWorld = typesInferrer.closedWorld;
732 var commonMasks = closedWorld.commonMasks;
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(
739 typesInferrer.getReturnTypeOfElement(element), closedWorld),
739 name); 740 name);
740 } 741 }
741 742
742 var interceptorType = 743 var interceptorType = commonMasks.interceptorType;
743 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
744 744
745 checkReturn('returnNum1', commonMasks.numType); 745 checkReturn('returnNum1', commonMasks.numType);
746 checkReturn('returnNum2', commonMasks.numType); 746 checkReturn('returnNum2', commonMasks.numType);
747 checkReturn('returnInt1', commonMasks.uint31Type); 747 checkReturn('returnInt1', commonMasks.uint31Type);
748 checkReturn('returnInt2', commonMasks.uint31Type); 748 checkReturn('returnInt2', commonMasks.uint31Type);
749 checkReturn('returnDouble', commonMasks.doubleType); 749 checkReturn('returnDouble', commonMasks.doubleType);
750 checkReturn('returnGiveUp', interceptorType); 750 checkReturn('returnGiveUp', interceptorType);
751 checkReturn( 751 checkReturn(
752 'returnInt5', commonMasks.uint32Type); // uint31+uint31->uint32 752 'returnInt5', commonMasks.uint32Type); // uint31+uint31->uint32
753 checkReturn( 753 checkReturn(
754 'returnInt6', commonMasks.uint32Type); // uint31+uint31->uint32 754 'returnInt6', commonMasks.uint32Type); // uint31+uint31->uint32
755 checkReturn('returnIntOrNull', commonMasks.uint31Type.nullable()); 755 checkReturn('returnIntOrNull', commonMasks.uint31Type.nullable());
756 checkReturn('returnInt3', commonMasks.uint31Type); 756 checkReturn('returnInt3', commonMasks.uint31Type);
757 checkReturn('returnDynamic', commonMasks.dynamicType); 757 checkReturn('returnDynamic', commonMasks.dynamicType);
758 checkReturn('returnInt4', commonMasks.uint31Type); 758 checkReturn('returnInt4', commonMasks.uint31Type);
759 checkReturn('returnInt7', commonMasks.positiveIntType); 759 checkReturn('returnInt7', commonMasks.positiveIntType);
760 checkReturn('returnInt8', commonMasks.positiveIntType); 760 checkReturn('returnInt8', commonMasks.positiveIntType);
761 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); 761 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty());
762 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); 762 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty());
763 TypeMask intType = new TypeMask.nonNullSubtype( 763 TypeMask intType = new TypeMask.nonNullSubtype(
764 compiler.coreClasses.intClass, compiler.closedWorld); 764 compiler.coreClasses.intClass, closedWorld);
765 checkReturn('testIsCheck1', intType); 765 checkReturn('testIsCheck1', intType);
766 checkReturn('testIsCheck2', intType); 766 checkReturn('testIsCheck2', intType);
767 checkReturn('testIsCheck3', intType.nullable()); 767 checkReturn('testIsCheck3', intType.nullable());
768 checkReturn('testIsCheck4', intType); 768 checkReturn('testIsCheck4', intType);
769 checkReturn('testIsCheck5', intType); 769 checkReturn('testIsCheck5', intType);
770 checkReturn('testIsCheck6', commonMasks.dynamicType); 770 checkReturn('testIsCheck6', commonMasks.dynamicType);
771 checkReturn('testIsCheck7', intType); 771 checkReturn('testIsCheck7', intType);
772 checkReturn('testIsCheck8', commonMasks.dynamicType); 772 checkReturn('testIsCheck8', commonMasks.dynamicType);
773 checkReturn('testIsCheck9', intType); 773 checkReturn('testIsCheck9', intType);
774 checkReturn('testIsCheck10', commonMasks.dynamicType); 774 checkReturn('testIsCheck10', commonMasks.dynamicType);
(...skipping 14 matching lines...) Expand all
789 checkReturn('testIsCheck25', commonMasks.dynamicType); 789 checkReturn('testIsCheck25', commonMasks.dynamicType);
790 checkReturn('testIsCheck26', intType); 790 checkReturn('testIsCheck26', intType);
791 checkReturn('testIsCheck27', intType); 791 checkReturn('testIsCheck27', intType);
792 checkReturn('testIsCheck28', commonMasks.dynamicType); 792 checkReturn('testIsCheck28', commonMasks.dynamicType);
793 checkReturn('testIsCheck29', commonMasks.dynamicType); 793 checkReturn('testIsCheck29', commonMasks.dynamicType);
794 checkReturn('testIf1', commonMasks.uint31Type.nullable()); 794 checkReturn('testIf1', commonMasks.uint31Type.nullable());
795 checkReturn('testIf2', commonMasks.uint31Type.nullable()); 795 checkReturn('testIf2', commonMasks.uint31Type.nullable());
796 checkReturn( 796 checkReturn(
797 'returnAsString', 797 'returnAsString',
798 new TypeMask.subtype( 798 new TypeMask.subtype(
799 compiler.coreClasses.stringClass, compiler.closedWorld)); 799 compiler.coreClasses.stringClass, closedWorld));
800 checkReturn('returnIntAsNum', commonMasks.uint31Type); 800 checkReturn('returnIntAsNum', commonMasks.uint31Type);
801 checkReturn('returnAsTypedef', commonMasks.functionType.nullable()); 801 checkReturn('returnAsTypedef', commonMasks.functionType.nullable());
802 checkReturn('returnTopLevelGetter', commonMasks.uint31Type); 802 checkReturn('returnTopLevelGetter', commonMasks.uint31Type);
803 checkReturn('testDeadCode', commonMasks.uint31Type); 803 checkReturn('testDeadCode', commonMasks.uint31Type);
804 checkReturn('testLabeledIf', commonMasks.uint31Type.nullable()); 804 checkReturn('testLabeledIf', commonMasks.uint31Type.nullable());
805 checkReturn( 805 checkReturn(
806 'testSwitch1', 806 'testSwitch1',
807 simplify( 807 simplify(
808 commonMasks.intType 808 commonMasks.intType
809 .union(commonMasks.doubleType, compiler.closedWorld) 809 .union(commonMasks.doubleType, closedWorld)
810 .nullable(), 810 .nullable(),
811 compiler)); 811 closedWorld));
812 checkReturn('testSwitch2', commonMasks.uint31Type); 812 checkReturn('testSwitch2', commonMasks.uint31Type);
813 checkReturn('testSwitch3', interceptorType.nullable()); 813 checkReturn('testSwitch3', interceptorType.nullable());
814 checkReturn('testSwitch4', commonMasks.uint31Type); 814 checkReturn('testSwitch4', commonMasks.uint31Type);
815 checkReturn('testSwitch5', commonMasks.uint31Type); 815 checkReturn('testSwitch5', commonMasks.uint31Type);
816 checkReturn('testContinue1', interceptorType.nullable()); 816 checkReturn('testContinue1', interceptorType.nullable());
817 checkReturn('testBreak1', interceptorType.nullable()); 817 checkReturn('testBreak1', interceptorType.nullable());
818 checkReturn('testContinue2', interceptorType.nullable()); 818 checkReturn('testContinue2', interceptorType.nullable());
819 checkReturn('testBreak2', commonMasks.uint32Type.nullable()); 819 checkReturn('testBreak2', commonMasks.uint32Type.nullable());
820 checkReturn('testReturnElementOfConstList1', commonMasks.uint31Type); 820 checkReturn('testReturnElementOfConstList1', commonMasks.uint31Type);
821 checkReturn('testReturnElementOfConstList2', commonMasks.uint31Type); 821 checkReturn('testReturnElementOfConstList2', commonMasks.uint31Type);
822 checkReturn('testReturnItselfOrInt', commonMasks.uint31Type); 822 checkReturn('testReturnItselfOrInt', commonMasks.uint31Type);
823 checkReturn('testReturnInvokeDynamicGetter', commonMasks.dynamicType); 823 checkReturn('testReturnInvokeDynamicGetter', commonMasks.dynamicType);
824 824
825 checkReturn('testDoWhile1', commonMasks.stringType); 825 checkReturn('testDoWhile1', commonMasks.stringType);
826 checkReturn('testDoWhile2', commonMasks.nullType); 826 checkReturn('testDoWhile2', commonMasks.nullType);
827 checkReturn('testDoWhile3', commonMasks.uint31Type); 827 checkReturn('testDoWhile3', commonMasks.uint31Type);
828 checkReturn('testDoWhile4', commonMasks.numType); 828 checkReturn('testDoWhile4', commonMasks.numType);
829 829
830 checkReturnInClass(String className, String methodName, type) { 830 checkReturnInClass(String className, String methodName, type) {
831 var cls = findElement(compiler, className); 831 var cls = findElement(compiler, className);
832 var element = cls.lookupLocalMember(methodName); 832 var element = cls.lookupLocalMember(methodName);
833 Expect.equals( 833 Expect.equals(
834 type, 834 type,
835 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), 835 simplify(
836 typesInferrer.getReturnTypeOfElement(element), closedWorld),
836 '$className:$methodName'); 837 '$className:$methodName');
837 } 838 }
838 839
839 checkReturnInClass('A', 'returnInt1', commonMasks.uint32Type); 840 checkReturnInClass('A', 'returnInt1', commonMasks.uint32Type);
840 checkReturnInClass('A', 'returnInt2', commonMasks.uint32Type); 841 checkReturnInClass('A', 'returnInt2', commonMasks.uint32Type);
841 checkReturnInClass('A', 'returnInt3', commonMasks.uint32Type); 842 checkReturnInClass('A', 'returnInt3', commonMasks.uint32Type);
842 checkReturnInClass('A', 'returnInt4', commonMasks.uint32Type); 843 checkReturnInClass('A', 'returnInt4', commonMasks.uint32Type);
843 checkReturnInClass('A', 'returnInt5', commonMasks.uint32Type); 844 checkReturnInClass('A', 'returnInt5', commonMasks.uint32Type);
844 checkReturnInClass('A', 'returnInt6', commonMasks.uint32Type); 845 checkReturnInClass('A', 'returnInt6', commonMasks.uint32Type);
845 checkReturnInClass('A', '==', interceptorType); 846 checkReturnInClass('A', '==', interceptorType);
(...skipping 11 matching lines...) Expand all
857 checkReturnInClass('C', 'returnInt1', commonMasks.positiveIntType); 858 checkReturnInClass('C', 'returnInt1', commonMasks.positiveIntType);
858 checkReturnInClass('C', 'returnInt2', commonMasks.positiveIntType); 859 checkReturnInClass('C', 'returnInt2', commonMasks.positiveIntType);
859 checkReturnInClass('C', 'returnInt3', commonMasks.positiveIntType); 860 checkReturnInClass('C', 'returnInt3', commonMasks.positiveIntType);
860 checkReturnInClass('C', 'returnInt4', commonMasks.positiveIntType); 861 checkReturnInClass('C', 'returnInt4', commonMasks.positiveIntType);
861 checkReturnInClass('C', 'returnInt5', commonMasks.positiveIntType); 862 checkReturnInClass('C', 'returnInt5', commonMasks.positiveIntType);
862 checkReturnInClass('C', 'returnInt6', commonMasks.positiveIntType); 863 checkReturnInClass('C', 'returnInt6', commonMasks.positiveIntType);
863 864
864 checkFactoryConstructor(String className, String factoryName) { 865 checkFactoryConstructor(String className, String factoryName) {
865 var cls = findElement(compiler, className); 866 var cls = findElement(compiler, className);
866 var element = cls.localLookup(factoryName); 867 var element = cls.localLookup(factoryName);
867 Expect.equals(new TypeMask.nonNullExact(cls, world), 868 Expect.equals(new TypeMask.nonNullExact(cls, closedWorld),
868 typesInferrer.getReturnTypeOfElement(element)); 869 typesInferrer.getReturnTypeOfElement(element));
869 } 870 }
870 871
871 checkFactoryConstructor('A', ''); 872 checkFactoryConstructor('A', '');
872 873
873 checkReturn('testCascade1', commonMasks.growableListType); 874 checkReturn('testCascade1', commonMasks.growableListType);
874 checkReturn( 875 checkReturn(
875 'testCascade2', 876 'testCascade2',
876 new TypeMask.nonNullExact( 877 new TypeMask.nonNullExact(
877 findElement(compiler, 'CascadeHelper'), world)); 878 findElement(compiler, 'CascadeHelper'), closedWorld));
878 checkReturn('testSpecialization1', commonMasks.numType); 879 checkReturn('testSpecialization1', commonMasks.numType);
879 checkReturn('testSpecialization2', commonMasks.dynamicType); 880 checkReturn('testSpecialization2', commonMasks.dynamicType);
880 checkReturn('testSpecialization3', commonMasks.uint31Type.nullable()); 881 checkReturn('testSpecialization3', commonMasks.uint31Type.nullable());
881 checkReturn('testReturnNull1', commonMasks.nullType); 882 checkReturn('testReturnNull1', commonMasks.nullType);
882 checkReturn('testReturnNull2', commonMasks.nullType); 883 checkReturn('testReturnNull2', commonMasks.nullType);
883 checkReturn('testReturnNull3', commonMasks.dynamicType); 884 checkReturn('testReturnNull3', commonMasks.dynamicType);
884 checkReturn('testReturnNull4', commonMasks.nullType); 885 checkReturn('testReturnNull4', commonMasks.nullType);
885 checkReturn('testReturnNull5', commonMasks.nullType); 886 checkReturn('testReturnNull5', commonMasks.nullType);
886 checkReturn('testReturnNull6', commonMasks.dynamicType); 887 checkReturn('testReturnNull6', commonMasks.dynamicType);
887 checkReturn('testReturnNotEquals', commonMasks.boolType); 888 checkReturn('testReturnNotEquals', commonMasks.boolType);
888 })); 889 }));
889 } 890 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698