OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/hydrogen-types.h" | 7 #include "src/hydrogen-types.h" |
8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
9 #include "src/types.h" | 9 #include "src/types.h" |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 integers.push_back(isolate->factory()->NewNumber(+V8_INFINITY)); | 152 integers.push_back(isolate->factory()->NewNumber(+V8_INFINITY)); |
153 integers.push_back(isolate->factory()->NewNumber(-rng_->NextInt(10))); | 153 integers.push_back(isolate->factory()->NewNumber(-rng_->NextInt(10))); |
154 integers.push_back(isolate->factory()->NewNumber(+rng_->NextInt(10))); | 154 integers.push_back(isolate->factory()->NewNumber(+rng_->NextInt(10))); |
155 for (int i = 0; i < 10; ++i) { | 155 for (int i = 0; i < 10; ++i) { |
156 double x = rng_->NextInt(); | 156 double x = rng_->NextInt(); |
157 integers.push_back(isolate->factory()->NewNumber(x)); | 157 integers.push_back(isolate->factory()->NewNumber(x)); |
158 x *= rng_->NextInt(); | 158 x *= rng_->NextInt(); |
159 if (!IsMinusZero(x)) integers.push_back(isolate->factory()->NewNumber(x)); | 159 if (!IsMinusZero(x)) integers.push_back(isolate->factory()->NewNumber(x)); |
160 } | 160 } |
161 | 161 |
| 162 Integer = Type::Range( |
| 163 isolate->factory()->NewNumber(-V8_INFINITY), |
| 164 isolate->factory()->NewNumber(-V8_INFINITY), region); |
| 165 |
162 NumberArray = Type::Array(Number, region); | 166 NumberArray = Type::Array(Number, region); |
163 StringArray = Type::Array(String, region); | 167 StringArray = Type::Array(String, region); |
164 AnyArray = Type::Array(Any, region); | 168 AnyArray = Type::Array(Any, region); |
165 | 169 |
166 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); | 170 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); |
167 NumberFunction1 = Type::Function(Number, Number, region); | 171 NumberFunction1 = Type::Function(Number, Number, region); |
168 NumberFunction2 = Type::Function(Number, Number, Number, region); | 172 NumberFunction2 = Type::Function(Number, Number, Number, region); |
169 MethodFunction = Type::Function(String, Object, 0, region); | 173 MethodFunction = Type::Function(String, Object, 0, region); |
170 | 174 |
171 for (int i = 0; i < 30; ++i) { | 175 for (int i = 0; i < 30; ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
182 Handle<i::HeapNumber> signed32; | 186 Handle<i::HeapNumber> signed32; |
183 Handle<i::JSObject> object1; | 187 Handle<i::JSObject> object1; |
184 Handle<i::JSObject> object2; | 188 Handle<i::JSObject> object2; |
185 Handle<i::JSArray> array; | 189 Handle<i::JSArray> array; |
186 Handle<i::Oddball> uninitialized; | 190 Handle<i::Oddball> uninitialized; |
187 | 191 |
188 #define DECLARE_TYPE(name, value) TypeHandle name; | 192 #define DECLARE_TYPE(name, value) TypeHandle name; |
189 BITSET_TYPE_LIST(DECLARE_TYPE) | 193 BITSET_TYPE_LIST(DECLARE_TYPE) |
190 #undef DECLARE_TYPE | 194 #undef DECLARE_TYPE |
191 | 195 |
| 196 TypeHandle Integer; |
| 197 |
192 TypeHandle ObjectClass; | 198 TypeHandle ObjectClass; |
193 TypeHandle ArrayClass; | 199 TypeHandle ArrayClass; |
194 TypeHandle NumberClass; | 200 TypeHandle NumberClass; |
195 TypeHandle UninitializedClass; | 201 TypeHandle UninitializedClass; |
196 | 202 |
197 TypeHandle SmiConstant; | 203 TypeHandle SmiConstant; |
198 TypeHandle Signed32Constant; | 204 TypeHandle Signed32Constant; |
199 TypeHandle ObjectConstant1; | 205 TypeHandle ObjectConstant1; |
200 TypeHandle ObjectConstant2; | 206 TypeHandle ObjectConstant2; |
201 TypeHandle ArrayConstant; | 207 TypeHandle ArrayConstant; |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 i::Handle<i::Object> max2 = *j2; | 652 i::Handle<i::Object> max2 = *j2; |
647 if (min1->Number() > max1->Number()) std::swap(min1, max1); | 653 if (min1->Number() > max1->Number()) std::swap(min1, max1); |
648 if (min2->Number() > max2->Number()) std::swap(min2, max2); | 654 if (min2->Number() > max2->Number()) std::swap(min2, max2); |
649 TypeHandle type1 = T.Range(min1, max1); | 655 TypeHandle type1 = T.Range(min1, max1); |
650 TypeHandle type2 = T.Range(min2, max2); | 656 TypeHandle type2 = T.Range(min2, max2); |
651 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); | 657 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); |
652 } | 658 } |
653 } | 659 } |
654 } | 660 } |
655 } | 661 } |
| 662 |
| 663 // Weakening: |
| 664 // 1.) Range(x,y)->Is(Range(x,y)->Weaken()) |
| 665 // 2.) Range(x,y)->Weaken()->IsRange() iff Range(x,y)->Maybe(OtherNumber) |
| 666 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { |
| 667 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { |
| 668 i::Handle<i::Object> min = *i; |
| 669 i::Handle<i::Object> max = *j; |
| 670 if (min->Number() > max->Number()) std::swap(min, max); |
| 671 typename Type::RangeType* range = T.Range(min, max)->AsRange(); |
| 672 CHECK(range->Is(range->Weaken(T.region()))); |
| 673 CHECK(range->Weaken(T.region())->IsRange() == |
| 674 range->Maybe(T.OtherNumber)); |
| 675 } |
| 676 } |
656 } | 677 } |
657 | 678 |
658 void Context() { | 679 void Context() { |
659 // Constructor | 680 // Constructor |
660 for (int i = 0; i < 20; ++i) { | 681 for (int i = 0; i < 20; ++i) { |
661 TypeHandle type = T.Random(); | 682 TypeHandle type = T.Random(); |
662 TypeHandle context = T.Context(type); | 683 TypeHandle context = T.Context(type); |
663 CHECK(context->Iscontext()); | 684 CHECK(context->Iscontext()); |
664 } | 685 } |
665 | 686 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 TypeHandle type = *it; | 881 TypeHandle type = *it; |
861 TypeHandle const_type = T.Constant(value); | 882 TypeHandle const_type = T.Constant(value); |
862 TypeHandle nowof_type = T.NowOf(value); | 883 TypeHandle nowof_type = T.NowOf(value); |
863 CHECK(!const_type->Is(type) || | 884 CHECK(!const_type->Is(type) || |
864 nowof_type->Is(type) || type->Maybe(const_type)); | 885 nowof_type->Is(type) || type->Maybe(const_type)); |
865 } | 886 } |
866 } | 887 } |
867 } | 888 } |
868 | 889 |
869 void MinMax() { | 890 void MinMax() { |
| 891 Factory* fac = isolate->factory(); |
| 892 |
870 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). | 893 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). |
871 // TODO(neis): Need to ignore representation for this to be true. | 894 // TODO(neis): Need to ignore representation for this to be true. |
872 /* | 895 /* |
873 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 896 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
874 TypeHandle type = *it; | 897 TypeHandle type = *it; |
875 if (this->IsBitset(type) && type->Is(T.Number) && | 898 if (this->IsBitset(type) && type->Is(T.Number) && |
876 !type->Is(T.None) && !type->Is(T.NaN)) { | 899 !type->Is(T.None) && !type->Is(T.NaN)) { |
877 TypeHandle range = T.Range( | 900 TypeHandle range = T.Range( |
878 isolate->factory()->NewNumber(type->Min()), | 901 isolate->factory()->NewNumber(type->Min()), |
879 isolate->factory()->NewNumber(type->Max())); | 902 isolate->factory()->NewNumber(type->Max())); |
880 CHECK(range->Is(type)); | 903 CHECK(range->Is(type)); |
881 } | 904 } |
882 } | 905 } |
883 */ | 906 */ |
884 | 907 |
885 // If b is regular numeric bitset, then b->Min() and b->Max() are integers. | 908 // If b is regular numeric bitset, then b->Min() and b->Max() are integers. |
886 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 909 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
887 TypeHandle type = *it; | 910 TypeHandle type = *it; |
888 if (this->IsBitset(type) && type->Is(T.Number) && | 911 if (this->IsBitset(type) && type->Is(T.Number) && !type->Is(T.NaN)) { |
889 !type->Is(T.None) && !type->Is(T.NaN)) { | |
890 CHECK(IsInteger(type->Min()) && IsInteger(type->Max())); | 912 CHECK(IsInteger(type->Min()) && IsInteger(type->Max())); |
891 } | 913 } |
892 } | 914 } |
893 | 915 |
894 // If b1 and b2 are regular numeric bitsets with b1->Is(b2), then | 916 // If b1 and b2 are regular numeric bitsets with b1->Is(b2), then |
895 // b1->Min() >= b2->Min() and b1->Max() <= b2->Max(). | 917 // b1->Min() >= b2->Min() and b1->Max() <= b2->Max(). |
896 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 918 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
897 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 919 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
898 TypeHandle type1 = *it1; | 920 TypeHandle type1 = *it1; |
899 TypeHandle type2 = *it2; | 921 TypeHandle type2 = *it2; |
900 if (this->IsBitset(type1) && type1->Is(type2) && type2->Is(T.Number) && | 922 if (this->IsBitset(type1) && type1->Is(type2) && type2->Is(T.Number) && |
901 !type1->Is(T.NaN) && !type2->Is(T.NaN)) { | 923 !type1->Is(T.NaN) && !type2->Is(T.NaN)) { |
902 CHECK(type1->Min() >= type2->Min()); | 924 CHECK(type1->Min() >= type2->Min()); |
903 CHECK(type1->Max() <= type2->Max()); | 925 CHECK(type1->Max() <= type2->Max()); |
904 } | 926 } |
905 } | 927 } |
906 } | 928 } |
907 | 929 |
908 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max() | 930 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max() |
909 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 931 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
910 TypeHandle type = *it; | 932 TypeHandle type = *it; |
911 if (type->IsRange()) { | 933 if (type->IsRange()) { |
912 TypeHandle lub = Rep::BitsetType::New( | 934 TypeHandle lub = Rep::BitsetType::New( |
913 Rep::BitsetType::Lub(type), T.region()); | 935 Rep::BitsetType::Lub(type), T.region()); |
914 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); | 936 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); |
915 } | 937 } |
916 } | 938 } |
| 939 |
| 940 // Rangification: If T->Is(Range(-inf,+inf)) and !T->Is(None), then |
| 941 // T->Is(Range(T->Min(), T->Max())). |
| 942 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 943 TypeHandle type = *it; |
| 944 CHECK( |
| 945 !(type->Is(T.Integer) && !type->Is(T.None)) || |
| 946 type->Is(T.Range( |
| 947 fac->NewNumber(type->Min()), fac->NewNumber(type->Max())))); |
| 948 } |
917 } | 949 } |
918 | 950 |
919 void BitsetGlb() { | 951 void BitsetGlb() { |
920 // Lower: (T->BitsetGlb())->Is(T) | 952 // Lower: (T->BitsetGlb())->Is(T) |
921 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 953 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
922 TypeHandle type = *it; | 954 TypeHandle type = *it; |
923 TypeHandle glb = | 955 TypeHandle glb = |
924 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); | 956 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); |
925 CHECK(glb->Is(type)); | 957 CHECK(glb->Is(type)); |
926 } | 958 } |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2302 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 2334 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
2303 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 2335 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
2304 } | 2336 } |
2305 | 2337 |
2306 | 2338 |
2307 TEST(HTypeFromType) { | 2339 TEST(HTypeFromType) { |
2308 CcTest::InitializeVM(); | 2340 CcTest::InitializeVM(); |
2309 ZoneTests().HTypeFromType(); | 2341 ZoneTests().HTypeFromType(); |
2310 HeapTests().HTypeFromType(); | 2342 HeapTests().HTypeFromType(); |
2311 } | 2343 } |
OLD | NEW |