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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return Type::template Convert<Type2>(t, region_); | 254 return Type::template Convert<Type2>(t, region_); |
255 } | 255 } |
256 | 256 |
257 TypeHandle Random() { | 257 TypeHandle Random() { |
258 return types[rng_->NextInt(static_cast<int>(types.size()))]; | 258 return types[rng_->NextInt(static_cast<int>(types.size()))]; |
259 } | 259 } |
260 | 260 |
261 TypeHandle Fuzz(int depth = 4) { | 261 TypeHandle Fuzz(int depth = 4) { |
262 switch (rng_->NextInt(depth == 0 ? 3 : 20)) { | 262 switch (rng_->NextInt(depth == 0 ? 3 : 20)) { |
263 case 0: { // bitset | 263 case 0: { // bitset |
264 int n = 0 | |
265 #define COUNT_BITSET_TYPES(type, value) + 1 | 264 #define COUNT_BITSET_TYPES(type, value) + 1 |
266 PROPER_BITSET_TYPE_LIST(COUNT_BITSET_TYPES) | 265 int n = 0 PROPER_BITSET_TYPE_LIST(COUNT_BITSET_TYPES); |
267 #undef COUNT_BITSET_TYPES | 266 #undef COUNT_BITSET_TYPES |
268 ; | 267 // Pick a bunch of named bitsets and return their intersection. |
269 int i = rng_->NextInt(n); | 268 TypeHandle result = Type::Any(region_); |
270 #define PICK_BITSET_TYPE(type, value) \ | 269 for (int i = 0, m = 1 + rng_->NextInt(3); i < m; ++i) { |
271 if (i-- == 0) return Type::type(region_); | 270 int j = rng_->NextInt(n); |
272 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE) | 271 #define PICK_BITSET_TYPE(type, value) \ |
273 #undef PICK_BITSET_TYPE | 272 if (j-- == 0) { \ |
274 UNREACHABLE(); | 273 TypeHandle tmp = Type::Intersect( \ |
| 274 result, Type::type(region_), region_); \ |
| 275 if (tmp->Is(Type::None()) && i != 0) { \ |
| 276 break; \ |
| 277 } { \ |
| 278 result = tmp; \ |
| 279 continue; \ |
| 280 } \ |
| 281 } |
| 282 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE) |
| 283 #undef PICK_BITSET_TYPE |
| 284 } |
| 285 return result; |
275 } | 286 } |
276 case 1: { // class | 287 case 1: { // class |
277 int i = rng_->NextInt(static_cast<int>(maps.size())); | 288 int i = rng_->NextInt(static_cast<int>(maps.size())); |
278 return Type::Class(maps[i], region_); | 289 return Type::Class(maps[i], region_); |
279 } | 290 } |
280 case 2: { // constant | 291 case 2: { // constant |
281 int i = rng_->NextInt(static_cast<int>(values.size())); | 292 int i = rng_->NextInt(static_cast<int>(values.size())); |
282 return Type::Constant(values[i], region_); | 293 return Type::Constant(values[i], region_); |
283 } | 294 } |
284 case 3: { // range | 295 case 3: { // range |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 TypeHandle type = T.Range(min, max); | 602 TypeHandle type = T.Range(min, max); |
592 CHECK(*min == *type->AsRange()->Min()); | 603 CHECK(*min == *type->AsRange()->Min()); |
593 CHECK(*max == *type->AsRange()->Max()); | 604 CHECK(*max == *type->AsRange()->Max()); |
594 } | 605 } |
595 } | 606 } |
596 | 607 |
597 // Functionality & Injectivity: | 608 // Functionality & Injectivity: |
598 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 | 609 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 |
599 for (ValueIterator i1 = T.integers.begin(); | 610 for (ValueIterator i1 = T.integers.begin(); |
600 i1 != T.integers.end(); ++i1) { | 611 i1 != T.integers.end(); ++i1) { |
601 for (ValueIterator j1 = T.integers.begin(); | 612 for (ValueIterator j1 = i1; |
602 j1 != T.integers.end(); ++j1) { | 613 j1 != T.integers.end(); ++j1) { |
603 for (ValueIterator i2 = T.integers.begin(); | 614 for (ValueIterator i2 = T.integers.begin(); |
604 i2 != T.integers.end(); ++i2) { | 615 i2 != T.integers.end(); ++i2) { |
605 for (ValueIterator j2 = T.integers.begin(); | 616 for (ValueIterator j2 = i2; |
606 j2 != T.integers.end(); ++j2) { | 617 j2 != T.integers.end(); ++j2) { |
607 i::Handle<i::Object> min1 = *i1; | 618 i::Handle<i::Object> min1 = *i1; |
608 i::Handle<i::Object> max1 = *j1; | 619 i::Handle<i::Object> max1 = *j1; |
609 i::Handle<i::Object> min2 = *i2; | 620 i::Handle<i::Object> min2 = *i2; |
610 i::Handle<i::Object> max2 = *j2; | 621 i::Handle<i::Object> max2 = *j2; |
611 if (min1->Number() > max1->Number()) std::swap(min1, max1); | 622 if (min1->Number() > max1->Number()) std::swap(min1, max1); |
612 if (min2->Number() > max2->Number()) std::swap(min2, max2); | 623 if (min2->Number() > max2->Number()) std::swap(min2, max2); |
613 TypeHandle type1 = T.Range(min1, max1); | 624 TypeHandle type1 = T.Range(min1, max1); |
614 TypeHandle type2 = T.Range(min2, max2); | 625 TypeHandle type2 = T.Range(min2, max2); |
615 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); | 626 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 TypeHandle const_type1 = T.Constant(value1); | 953 TypeHandle const_type1 = T.Constant(value1); |
943 TypeHandle const_type2 = T.Constant(value2); | 954 TypeHandle const_type2 = T.Constant(value2); |
944 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); | 955 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); |
945 } | 956 } |
946 } | 957 } |
947 | 958 |
948 // Range(min1, max1)->Is(Range(min2, max2)) iff | 959 // Range(min1, max1)->Is(Range(min2, max2)) iff |
949 // min1 >= min2 /\ max1 <= max2 | 960 // min1 >= min2 /\ max1 <= max2 |
950 for (ValueIterator i1 = T.integers.begin(); | 961 for (ValueIterator i1 = T.integers.begin(); |
951 i1 != T.integers.end(); ++i1) { | 962 i1 != T.integers.end(); ++i1) { |
952 for (ValueIterator j1 = T.integers.begin(); | 963 for (ValueIterator j1 = i1; |
953 j1 != T.integers.end(); ++j1) { | 964 j1 != T.integers.end(); ++j1) { |
954 for (ValueIterator i2 = T.integers.begin(); | 965 for (ValueIterator i2 = T.integers.begin(); |
955 i2 != T.integers.end(); ++i2) { | 966 i2 != T.integers.end(); ++i2) { |
956 for (ValueIterator j2 = T.integers.begin(); | 967 for (ValueIterator j2 = i2; |
957 j2 != T.integers.end(); ++j2) { | 968 j2 != T.integers.end(); ++j2) { |
958 i::Handle<i::Object> min1 = *i1; | 969 i::Handle<i::Object> min1 = *i1; |
959 i::Handle<i::Object> max1 = *j1; | 970 i::Handle<i::Object> max1 = *j1; |
960 i::Handle<i::Object> min2 = *i2; | 971 i::Handle<i::Object> min2 = *i2; |
961 i::Handle<i::Object> max2 = *j2; | 972 i::Handle<i::Object> max2 = *j2; |
962 if (min1->Number() > max1->Number()) std::swap(min1, max1); | 973 if (min1->Number() > max1->Number()) std::swap(min1, max1); |
963 if (min2->Number() > max2->Number()) std::swap(min2, max2); | 974 if (min2->Number() > max2->Number()) std::swap(min2, max2); |
964 TypeHandle type1 = T.Range(min1, max1); | 975 TypeHandle type1 = T.Range(min1, max1); |
965 TypeHandle type2 = T.Range(min2, max2); | 976 TypeHandle type2 = T.Range(min2, max2); |
966 CHECK(type1->Is(type2) == | 977 CHECK(type1->Is(type2) == |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 } | 1527 } |
1517 } | 1528 } |
1518 } | 1529 } |
1519 */ | 1530 */ |
1520 } | 1531 } |
1521 | 1532 |
1522 void Union3() { | 1533 void Union3() { |
1523 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) | 1534 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) |
1524 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1535 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1525 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1536 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1526 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1537 for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) { |
1527 TypeHandle type1 = *it1; | 1538 TypeHandle type1 = *it1; |
1528 TypeHandle type2 = *it2; | 1539 TypeHandle type2 = *it2; |
1529 TypeHandle type3 = *it3; | 1540 TypeHandle type3 = *it3; |
1530 TypeHandle union23 = T.Union(type2, type3); | 1541 TypeHandle union23 = T.Union(type2, type3); |
1531 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); | 1542 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); |
1532 } | 1543 } |
1533 } | 1544 } |
1534 } | 1545 } |
1535 } | 1546 } |
1536 | 1547 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 2123 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
2113 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 2124 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
2114 } | 2125 } |
2115 | 2126 |
2116 | 2127 |
2117 TEST(HTypeFromType) { | 2128 TEST(HTypeFromType) { |
2118 CcTest::InitializeVM(); | 2129 CcTest::InitializeVM(); |
2119 ZoneTests().HTypeFromType(); | 2130 ZoneTests().HTypeFromType(); |
2120 HeapTests().HTypeFromType(); | 2131 HeapTests().HTypeFromType(); |
2121 } | 2132 } |
OLD | NEW |