diff options
Diffstat (limited to 'deps/v8/test/cctest/test-types.cc')
-rw-r--r-- | deps/v8/test/cctest/test-types.cc | 269 |
1 files changed, 171 insertions, 98 deletions
diff --git a/deps/v8/test/cctest/test-types.cc b/deps/v8/test/cctest/test-types.cc index ebef527dd0..f9b6bf862f 100644 --- a/deps/v8/test/cctest/test-types.cc +++ b/deps/v8/test/cctest/test-types.cc @@ -36,7 +36,8 @@ struct ZoneRep { return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; } static bool IsBitset(Type* t) { return reinterpret_cast<uintptr_t>(t) & 1; } - static bool IsUnion(Type* t) { return IsStruct(t, 6); } + // HACK: the number 5 below is the value of StructuralType::kUnionTag. + static bool IsUnion(Type* t) { return t->IsUnionForTesting(); } static Struct* AsStruct(Type* t) { return reinterpret_cast<Struct*>(t); @@ -69,7 +70,8 @@ struct HeapRep { return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; } static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } - static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 6); } + // HACK: the number 5 below is the value of StructuralType::kUnionTag. + static bool IsUnion(Handle<HeapType> t) { return t->IsUnionForTesting(); } static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } static bitset AsBitset(Handle<HeapType> t) { @@ -103,12 +105,12 @@ struct Tests : Rep { Zone zone; TypesInstance T; - Tests() : - isolate(CcTest::i_isolate()), - scope(isolate), - zone(isolate), - T(Rep::ToRegion(&zone, isolate), isolate) { - } + Tests() + : isolate(CcTest::i_isolate()), + scope(isolate), + zone(), + T(Rep::ToRegion(&zone, isolate), isolate, + isolate->random_number_generator()) {} bool Equal(TypeHandle type1, TypeHandle type2) { return @@ -136,6 +138,14 @@ struct Tests : Rep { } } + void CheckSubOrEqual(TypeHandle type1, TypeHandle type2) { + CHECK(type1->Is(type2)); + if (this->IsBitset(type1) && this->IsBitset(type2)) { + CHECK((this->AsBitset(type1) | this->AsBitset(type2)) + == this->AsBitset(type2)); + } + } + void CheckUnordered(TypeHandle type1, TypeHandle type2) { CHECK(!type1->Is(type2)); CHECK(!type2->Is(type1)); @@ -225,17 +235,85 @@ struct Tests : Rep { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { TypeHandle type1 = *it1; TypeHandle type2 = *it2; - TypeHandle intersect12 = T.Intersect(type1, type2); if (this->IsBitset(type1) && this->IsBitset(type2)) { + TypeHandle intersect12 = T.Intersect(type1, type2); bitset bits = this->AsBitset(type1) & this->AsBitset(type2); - CHECK( - (Rep::BitsetType::IsInhabited(bits) ? bits : 0) == - this->AsBitset(intersect12)); + CHECK(bits == this->AsBitset(intersect12)); } } } } + void PointwiseRepresentation() { + // Check we can decompose type into semantics and representation and + // then compose it back to get an equivalent type. + int counter = 0; + for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { + counter++; + printf("Counter: %i\n", counter); + fflush(stdout); + TypeHandle type1 = *it1; + TypeHandle representation = T.Representation(type1); + TypeHandle semantic = T.Semantic(type1); + TypeHandle composed = T.Union(representation, semantic); + CHECK(type1->Equals(composed)); + } + + // Pointwiseness of Union. + for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { + for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { + TypeHandle type1 = *it1; + TypeHandle type2 = *it2; + TypeHandle representation1 = T.Representation(type1); + TypeHandle semantic1 = T.Semantic(type1); + TypeHandle representation2 = T.Representation(type2); + TypeHandle semantic2 = T.Semantic(type2); + TypeHandle direct_union = T.Union(type1, type2); + TypeHandle representation_union = + T.Union(representation1, representation2); + TypeHandle semantic_union = T.Union(semantic1, semantic2); + TypeHandle composed_union = + T.Union(representation_union, semantic_union); + CHECK(direct_union->Equals(composed_union)); + } + } + + // Pointwiseness of Intersect. + for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { + for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { + TypeHandle type1 = *it1; + TypeHandle type2 = *it2; + TypeHandle representation1 = T.Representation(type1); + TypeHandle semantic1 = T.Semantic(type1); + TypeHandle representation2 = T.Representation(type2); + TypeHandle semantic2 = T.Semantic(type2); + TypeHandle direct_intersection = T.Intersect(type1, type2); + TypeHandle representation_intersection = + T.Intersect(representation1, representation2); + TypeHandle semantic_intersection = T.Intersect(semantic1, semantic2); + TypeHandle composed_intersection = + T.Union(representation_intersection, semantic_intersection); + CHECK(direct_intersection->Equals(composed_intersection)); + } + } + + // Pointwiseness of Is. + for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { + for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { + TypeHandle type1 = *it1; + TypeHandle type2 = *it2; + TypeHandle representation1 = T.Representation(type1); + TypeHandle semantic1 = T.Semantic(type1); + TypeHandle representation2 = T.Representation(type2); + TypeHandle semantic2 = T.Semantic(type2); + bool representation_is = representation1->Is(representation2); + bool semantic_is = semantic1->Is(semantic2); + bool direct_is = type1->Is(type2); + CHECK(direct_is == (semantic_is && representation_is)); + } + } + } + void Class() { // Constructor for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { @@ -294,39 +372,33 @@ struct Tests : Rep { CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); - CHECK(T.Constant(fac->NewNumber(-1))->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.NegativeSignedSmall)); + CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31)); + CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31)); + CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.Negative31)); + CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned31)); + CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned30)); + CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31)); + CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30)); + CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative32)); + CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative31)); + CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32)); + CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31)); if (SmiValuesAre31Bits()) { - CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32)); CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); - CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32)); CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32)); - CHECK( - !T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32)); - CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1)) - ->Is(T.NegativeSignedSmall)); + CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); + CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); } else { CHECK(SmiValuesAre32Bits()); CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); - CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32)); - CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32)); - CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1)) - ->Is(T.NegativeSignedSmall)); - CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32)); - CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32)); - CHECK( - T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.NegativeSigned32)); + CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); + CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); } CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); - CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.NonNegativeSigned32)); + CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31)); CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); - CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.NonNegativeSigned32)); + CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31)); CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); @@ -338,7 +410,8 @@ struct Tests : Rep { CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber)); CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32)); CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); - CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); + CHECK(T.Constant(fac->NewNumber(std::numeric_limits<double>::quiet_NaN())) + ->Is(T.NaN)); CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.PlainNumber)); CHECK(!T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.Integral32)); CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.PlainNumber)); @@ -349,9 +422,9 @@ struct Tests : Rep { // Constructor for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { - i::Handle<i::Object> min = *i; - i::Handle<i::Object> max = *j; - if (min->Number() > max->Number()) std::swap(min, max); + double min = (*i)->Number(); + double max = (*j)->Number(); + if (min > max) std::swap(min, max); TypeHandle type = T.Range(min, max); CHECK(type->IsRange()); } @@ -360,12 +433,12 @@ struct Tests : Rep { // Range attributes for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { - i::Handle<i::Object> min = *i; - i::Handle<i::Object> max = *j; - if (min->Number() > max->Number()) std::swap(min, max); + double min = (*i)->Number(); + double max = (*j)->Number(); + if (min > max) std::swap(min, max); TypeHandle type = T.Range(min, max); - CHECK(*min == *type->AsRange()->Min()); - CHECK(*max == *type->AsRange()->Max()); + CHECK(min == type->AsRange()->Min()); + CHECK(max == type->AsRange()->Max()); } } @@ -379,15 +452,15 @@ struct Tests : Rep { i2 != T.integers.end(); ++i2) { for (ValueIterator j2 = i2; j2 != T.integers.end(); ++j2) { - i::Handle<i::Object> min1 = *i1; - i::Handle<i::Object> max1 = *j1; - i::Handle<i::Object> min2 = *i2; - i::Handle<i::Object> max2 = *j2; - if (min1->Number() > max1->Number()) std::swap(min1, max1); - if (min2->Number() > max2->Number()) std::swap(min2, max2); + double min1 = (*i1)->Number(); + double max1 = (*j1)->Number(); + double min2 = (*i2)->Number(); + double max2 = (*j2)->Number(); + if (min1 > max1) std::swap(min1, max1); + if (min2 > max2) std::swap(min2, max2); TypeHandle type1 = T.Range(min1, max1); TypeHandle type2 = T.Range(min2, max2); - CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2)); + CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); } } } @@ -606,8 +679,6 @@ struct Tests : Rep { } void MinMax() { - Factory* fac = isolate->factory(); - // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). // TODO(neis): Need to ignore representation for this to be true. /* @@ -655,13 +726,12 @@ struct Tests : Rep { } } - // Rangification: If T->Is(Range(-inf,+inf)) and !T->Is(None), then + // Rangification: If T->Is(Range(-inf,+inf)) and T is inhabited, then // T->Is(Range(T->Min(), T->Max())). for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { TypeHandle type = *it; - CHECK(!(type->Is(T.Integer) && !type->Is(T.None)) || - type->Is(T.Range(fac->NewNumber(type->Min()), - fac->NewNumber(type->Max())))); + CHECK(!type->Is(T.Integer) || !type->IsInhabited() || + type->Is(T.Range(type->Min(), type->Max()))); } } @@ -795,11 +865,12 @@ struct Tests : Rep { (type1->IsClass() && type2->IsClass()) || (type1->IsConstant() && type2->IsConstant()) || (type1->IsConstant() && type2->IsRange()) || + (this->IsBitset(type1) && type2->IsRange()) || (type1->IsRange() && type2->IsRange()) || (type1->IsContext() && type2->IsContext()) || (type1->IsArray() && type2->IsArray()) || (type1->IsFunction() && type2->IsFunction()) || - type1->Equals(T.None)); + !type1->IsInhabited()); } } } @@ -825,17 +896,15 @@ struct Tests : Rep { i2 != T.integers.end(); ++i2) { for (ValueIterator j2 = i2; j2 != T.integers.end(); ++j2) { - i::Handle<i::Object> min1 = *i1; - i::Handle<i::Object> max1 = *j1; - i::Handle<i::Object> min2 = *i2; - i::Handle<i::Object> max2 = *j2; - if (min1->Number() > max1->Number()) std::swap(min1, max1); - if (min2->Number() > max2->Number()) std::swap(min2, max2); + double min1 = (*i1)->Number(); + double max1 = (*j1)->Number(); + double min2 = (*i2)->Number(); + double max2 = (*j2)->Number(); + if (min1 > max1) std::swap(min1, max1); + if (min2 > max2) std::swap(min2, max2); TypeHandle type1 = T.Range(min1, max1); TypeHandle type2 = T.Range(min2, max2); - CHECK(type1->Is(type2) == - (min1->Number() >= min2->Number() && - max1->Number() <= max2->Number())); + CHECK(type1->Is(type2) == (min1 >= min2 && max1 <= max2)); } } } @@ -895,8 +964,8 @@ struct Tests : Rep { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { TypeHandle type = *it; if (type->IsConstant() && IsInteger(*type->AsConstant()->Value())) { - CHECK(type->Is( - T.Range(type->AsConstant()->Value(), type->AsConstant()->Value()))); + CHECK(type->Is(T.Range(type->AsConstant()->Value()->Number(), + type->AsConstant()->Value()->Number()))); } } @@ -907,8 +976,8 @@ struct Tests : Rep { TypeHandle type2 = *it2; if (type1->IsConstant() && type2->IsRange() && type1->Is(type2)) { double x = type1->AsConstant()->Value()->Number(); - double min = type2->AsRange()->Min()->Number(); - double max = type2->AsRange()->Max()->Number(); + double min = type2->AsRange()->Min(); + double max = type2->AsRange()->Max(); CHECK(IsInteger(x) && min <= x && x <= max); } } @@ -933,7 +1002,7 @@ struct Tests : Rep { CheckSub(T.SignedSmall, T.Number); CheckSub(T.Signed32, T.Number); - CheckSub(T.SignedSmall, T.Signed32); + CheckSubOrEqual(T.SignedSmall, T.Signed32); CheckUnordered(T.SignedSmall, T.MinusZero); CheckUnordered(T.Signed32, T.Unsigned32); @@ -1305,7 +1374,7 @@ struct Tests : Rep { CheckDisjoint(T.SignedFunction1, T.MethodFunction); CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!! CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!! - CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Untagged)); // !!! + CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Tagged)); // !!! } void Union1() { @@ -1477,8 +1546,8 @@ struct Tests : Rep { CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number); // Bitset-class - CheckSub( - T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); + CheckSub(T.Union(T.ObjectClass, T.SignedSmall), + T.Union(T.Object, T.Number)); CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); @@ -1548,11 +1617,9 @@ struct Tests : Rep { T.Union(T.ObjectConstant2, T.ObjectConstant1), T.Union(T.ObjectConstant1, T.ObjectConstant2)), T.Union(T.ObjectConstant2, T.ObjectConstant1)); - CheckEqual( - T.Union( - T.Union(T.Number, T.ArrayClass), - T.Union(T.SignedSmall, T.Array)), - T.Union(T.Number, T.Array)); + CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass), + T.Union(T.SignedSmall, T.Array)), + T.Union(T.Number, T.Array)); } void Intersect() { @@ -1696,24 +1763,24 @@ struct Tests : Rep { // Bitset-class CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); - CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); - CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); + CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Array)), T.None); + CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Number)), T.None); // Bitset-array CheckEqual(T.Intersect(T.NumberArray, T.Object), T.NumberArray); - CheckEqual(T.Intersect(T.AnyArray, T.Proxy), T.None); + CheckEqual(T.Semantic(T.Intersect(T.AnyArray, T.Proxy)), T.None); // Bitset-function CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); - CheckEqual(T.Intersect(T.NumberFunction1, T.Proxy), T.None); + CheckEqual(T.Semantic(T.Intersect(T.NumberFunction1, T.Proxy)), T.None); // Bitset-union CheckEqual( T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), T.Union(T.ObjectConstant1, T.ObjectClass)); - CHECK( - !T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number) - ->IsInhabited()); + CheckEqual(T.Semantic(T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), + T.Number)), + T.None); // Class-constant CHECK(T.Intersect(T.ObjectConstant1, T.ObjectClass)->IsInhabited()); // !!! @@ -1766,11 +1833,9 @@ struct Tests : Rep { ->IsInhabited()); // !!! // Union-union - CheckEqual( - T.Intersect( - T.Union(T.Number, T.ArrayClass), - T.Union(T.SignedSmall, T.Array)), - T.Union(T.SignedSmall, T.ArrayClass)); + CheckEqual(T.Intersect(T.Union(T.Number, T.ArrayClass), + T.Union(T.SignedSmall, T.Array)), + T.Union(T.SignedSmall, T.ArrayClass)); CheckEqual( T.Intersect( T.Union(T.Number, T.ObjectClass), @@ -1849,8 +1914,8 @@ struct Tests : Rep { TypeHandle type1 = *it1; if (type1->IsRange()) { typename Type::RangeType* range = type1->GetRange(); - CHECK(type1->Min() == range->Min()->Number()); - CHECK(type1->Max() == range->Max()->Number()); + CHECK(type1->Min() == range->Min()); + CHECK(type1->Max() == range->Max()); } } @@ -1862,8 +1927,8 @@ struct Tests : Rep { if (type1->IsConstant() && type2->IsRange()) { TypeHandle u = T.Union(type1, type2); - CHECK(type2->Min() == u->GetRange()->Min()->Number()); - CHECK(type2->Max() == u->GetRange()->Max()->Number()); + CHECK(type2->Min() == u->GetRange()->Min()); + CHECK(type2->Max() == u->GetRange()->Max()); } } } @@ -1871,8 +1936,9 @@ struct Tests : Rep { template<class Type2, class TypeHandle2, class Region2, class Rep2> void Convert() { - Types<Type2, TypeHandle2, Region2> T2( - Rep2::ToRegion(&zone, isolate), isolate); + Types<Type2, TypeHandle2, Region2> T2(Rep2::ToRegion(&zone, isolate), + isolate, + isolate->random_number_generator()); for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { TypeHandle type1 = *it; TypeHandle2 type2 = T2.template Convert<Type>(type1); @@ -1905,6 +1971,13 @@ TEST(IsSomeType) { } +TEST(PointwiseRepresentation) { + CcTest::InitializeVM(); + // ZoneTests().PointwiseRepresentation(); + HeapTests().PointwiseRepresentation(); +} + + TEST(BitsetType) { CcTest::InitializeVM(); ZoneTests().Bitset(); |