Chromium Code Reviews| 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(4); 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 result = Type::Intersect(result, Type::type(region_), region_); \ |
| 274 continue; \ | |
| 275 } | |
| 276 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE) | |
| 277 #undef PICK_BITSET_TYPE | |
| 278 } | |
| 279 return result; | |
|
rossberg
2014/09/24 12:39:06
Hm, I wonder how many results are semantic None...
| |
| 275 } | 280 } |
| 276 case 1: { // class | 281 case 1: { // class |
| 277 int i = rng_->NextInt(static_cast<int>(maps.size())); | 282 int i = rng_->NextInt(static_cast<int>(maps.size())); |
| 278 return Type::Class(maps[i], region_); | 283 return Type::Class(maps[i], region_); |
| 279 } | 284 } |
| 280 case 2: { // constant | 285 case 2: { // constant |
| 281 int i = rng_->NextInt(static_cast<int>(values.size())); | 286 int i = rng_->NextInt(static_cast<int>(values.size())); |
| 282 return Type::Constant(values[i], region_); | 287 return Type::Constant(values[i], region_); |
| 283 } | 288 } |
| 284 case 3: { // range | 289 case 3: { // range |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 TypeHandle type = T.Range(min, max); | 596 TypeHandle type = T.Range(min, max); |
| 592 CHECK(*min == *type->AsRange()->Min()); | 597 CHECK(*min == *type->AsRange()->Min()); |
| 593 CHECK(*max == *type->AsRange()->Max()); | 598 CHECK(*max == *type->AsRange()->Max()); |
| 594 } | 599 } |
| 595 } | 600 } |
| 596 | 601 |
| 597 // Functionality & Injectivity: | 602 // Functionality & Injectivity: |
| 598 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 | 603 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 |
| 599 for (ValueIterator i1 = T.integers.begin(); | 604 for (ValueIterator i1 = T.integers.begin(); |
| 600 i1 != T.integers.end(); ++i1) { | 605 i1 != T.integers.end(); ++i1) { |
| 601 for (ValueIterator j1 = T.integers.begin(); | 606 for (ValueIterator j1 = i1; |
| 602 j1 != T.integers.end(); ++j1) { | 607 j1 != T.integers.end(); ++j1) { |
| 603 for (ValueIterator i2 = T.integers.begin(); | 608 for (ValueIterator i2 = T.integers.begin(); |
| 604 i2 != T.integers.end(); ++i2) { | 609 i2 != T.integers.end(); ++i2) { |
| 605 for (ValueIterator j2 = T.integers.begin(); | 610 for (ValueIterator j2 = i2; |
| 606 j2 != T.integers.end(); ++j2) { | 611 j2 != T.integers.end(); ++j2) { |
| 607 i::Handle<i::Object> min1 = *i1; | 612 i::Handle<i::Object> min1 = *i1; |
| 608 i::Handle<i::Object> max1 = *j1; | 613 i::Handle<i::Object> max1 = *j1; |
| 609 i::Handle<i::Object> min2 = *i2; | 614 i::Handle<i::Object> min2 = *i2; |
| 610 i::Handle<i::Object> max2 = *j2; | 615 i::Handle<i::Object> max2 = *j2; |
| 611 if (min1->Number() > max1->Number()) std::swap(min1, max1); | 616 if (min1->Number() > max1->Number()) std::swap(min1, max1); |
| 612 if (min2->Number() > max2->Number()) std::swap(min2, max2); | 617 if (min2->Number() > max2->Number()) std::swap(min2, max2); |
| 613 TypeHandle type1 = T.Range(min1, max1); | 618 TypeHandle type1 = T.Range(min1, max1); |
| 614 TypeHandle type2 = T.Range(min2, max2); | 619 TypeHandle type2 = T.Range(min2, max2); |
| 615 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); | 620 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); | 947 TypeHandle const_type1 = T.Constant(value1); |
| 943 TypeHandle const_type2 = T.Constant(value2); | 948 TypeHandle const_type2 = T.Constant(value2); |
| 944 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); | 949 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); |
| 945 } | 950 } |
| 946 } | 951 } |
| 947 | 952 |
| 948 // Range(min1, max1)->Is(Range(min2, max2)) iff | 953 // Range(min1, max1)->Is(Range(min2, max2)) iff |
| 949 // min1 >= min2 /\ max1 <= max2 | 954 // min1 >= min2 /\ max1 <= max2 |
| 950 for (ValueIterator i1 = T.integers.begin(); | 955 for (ValueIterator i1 = T.integers.begin(); |
| 951 i1 != T.integers.end(); ++i1) { | 956 i1 != T.integers.end(); ++i1) { |
| 952 for (ValueIterator j1 = T.integers.begin(); | 957 for (ValueIterator j1 = i1; |
| 953 j1 != T.integers.end(); ++j1) { | 958 j1 != T.integers.end(); ++j1) { |
| 954 for (ValueIterator i2 = T.integers.begin(); | 959 for (ValueIterator i2 = T.integers.begin(); |
| 955 i2 != T.integers.end(); ++i2) { | 960 i2 != T.integers.end(); ++i2) { |
| 956 for (ValueIterator j2 = T.integers.begin(); | 961 for (ValueIterator j2 = i2; |
| 957 j2 != T.integers.end(); ++j2) { | 962 j2 != T.integers.end(); ++j2) { |
| 958 i::Handle<i::Object> min1 = *i1; | 963 i::Handle<i::Object> min1 = *i1; |
| 959 i::Handle<i::Object> max1 = *j1; | 964 i::Handle<i::Object> max1 = *j1; |
| 960 i::Handle<i::Object> min2 = *i2; | 965 i::Handle<i::Object> min2 = *i2; |
| 961 i::Handle<i::Object> max2 = *j2; | 966 i::Handle<i::Object> max2 = *j2; |
| 962 if (min1->Number() > max1->Number()) std::swap(min1, max1); | 967 if (min1->Number() > max1->Number()) std::swap(min1, max1); |
| 963 if (min2->Number() > max2->Number()) std::swap(min2, max2); | 968 if (min2->Number() > max2->Number()) std::swap(min2, max2); |
| 964 TypeHandle type1 = T.Range(min1, max1); | 969 TypeHandle type1 = T.Range(min1, max1); |
| 965 TypeHandle type2 = T.Range(min2, max2); | 970 TypeHandle type2 = T.Range(min2, max2); |
| 966 CHECK(type1->Is(type2) == | 971 CHECK(type1->Is(type2) == |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1516 } | 1521 } |
| 1517 } | 1522 } |
| 1518 } | 1523 } |
| 1519 */ | 1524 */ |
| 1520 } | 1525 } |
| 1521 | 1526 |
| 1522 void Union3() { | 1527 void Union3() { |
| 1523 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) | 1528 // 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) { | 1529 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
| 1525 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1530 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
| 1526 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1531 for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) { |
| 1527 TypeHandle type1 = *it1; | 1532 TypeHandle type1 = *it1; |
| 1528 TypeHandle type2 = *it2; | 1533 TypeHandle type2 = *it2; |
| 1529 TypeHandle type3 = *it3; | 1534 TypeHandle type3 = *it3; |
| 1530 TypeHandle union23 = T.Union(type2, type3); | 1535 TypeHandle union23 = T.Union(type2, type3); |
| 1531 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); | 1536 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); |
| 1532 } | 1537 } |
| 1533 } | 1538 } |
| 1534 } | 1539 } |
| 1535 } | 1540 } |
| 1536 | 1541 |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2112 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 2117 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
| 2113 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 2118 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
| 2114 } | 2119 } |
| 2115 | 2120 |
| 2116 | 2121 |
| 2117 TEST(HTypeFromType) { | 2122 TEST(HTypeFromType) { |
| 2118 CcTest::InitializeVM(); | 2123 CcTest::InitializeVM(); |
| 2119 ZoneTests().HTypeFromType(); | 2124 ZoneTests().HTypeFromType(); |
| 2120 HeapTests().HTypeFromType(); | 2125 HeapTests().HTypeFromType(); |
| 2121 } | 2126 } |
| OLD | NEW |