Commit 4620ae5c authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Fix symmetry of Maybe() predicate. Fix bug in NowContains() predicate.

Add tests for TypeImpl::Of(), TypeImpl::NowOf() and
TypeImpl::NowContains(). Improves the implementation of
TypeImpl::NowIs() to match that of TypeImpl::NowContains().

Mark test-types with NO_VARIANTS to speedup testing, since
the variants do not affect the type system at all.

Also improve test coverage for types.

TEST=cctest/test-types
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/230673002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20639 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0387b235
...@@ -306,28 +306,23 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) { ...@@ -306,28 +306,23 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
template<class Config> template<class Config>
bool TypeImpl<Config>::NowIs(TypeImpl* that) { bool TypeImpl<Config>::NowIs(TypeImpl* that) {
if (this->Is(that)) return true; if (this->IsConstant()) {
if (this->IsConstant() && this->AsConstant()->IsHeapObject()) { DisallowHeapAllocation no_allocation;
i::Handle<i::Map> map(i::HeapObject::cast(*this->AsConstant())->map()); i::Object* object = *this->AsConstant();
for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) { if (object->IsHeapObject()) {
if (*it.Current() == *map) return true; i::Map* map = i::HeapObject::cast(object)->map();
for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) {
if (*it.Current() == map) return true;
}
} }
} }
return false; return this->Is(that);
} }
// Check this overlaps that. // Check this overlaps that.
template<class Config> template<class Config>
bool TypeImpl<Config>::Maybe(TypeImpl* that) { bool TypeImpl<Config>::Maybe(TypeImpl* that) {
// Fast path for bitsets.
if (this->IsBitset()) {
return IsInhabited(this->AsBitset() & that->LubBitset());
}
if (that->IsBitset()) {
return IsInhabited(this->LubBitset() & that->AsBitset());
}
// (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T)
if (this->IsUnion()) { if (this->IsUnion()) {
StructHandle unioned = this->AsUnion(); StructHandle unioned = this->AsUnion();
...@@ -349,6 +344,13 @@ bool TypeImpl<Config>::Maybe(TypeImpl* that) { ...@@ -349,6 +344,13 @@ bool TypeImpl<Config>::Maybe(TypeImpl* that) {
} }
ASSERT(!this->IsUnion() && !that->IsUnion()); ASSERT(!this->IsUnion() && !that->IsUnion());
if (this->IsBitset()) {
return IsInhabited(this->AsBitset() & that->LubBitset());
}
if (that->IsBitset()) {
return IsInhabited(this->LubBitset() & that->AsBitset());
}
if (this->IsClass()) { if (this->IsClass()) {
return that->IsClass() && *this->AsClass() == *that->AsClass(); return that->IsClass() && *this->AsClass() == *that->AsClass();
} }
...@@ -371,9 +373,14 @@ bool TypeImpl<Config>::Contains(i::Object* value) { ...@@ -371,9 +373,14 @@ bool TypeImpl<Config>::Contains(i::Object* value) {
template<class Config> template<class Config>
bool TypeImpl<Config>::NowContains(i::Object* value) { bool TypeImpl<Config>::NowContains(i::Object* value) {
return this->Contains(value) || if (value->IsHeapObject()) {
(this->IsClass() && value->IsHeapObject() && DisallowHeapAllocation no_allocation;
*this->AsClass() == i::HeapObject::cast(value)->map()); i::Map* map = i::HeapObject::cast(value)->map();
for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) {
if (*it.Current() == map) return true;
}
}
return this->Contains(value);
} }
......
...@@ -65,6 +65,10 @@ ...@@ -65,6 +65,10 @@
# are actually 13 * 38 * 5 * 128 = 316160 individual tests hidden here. # are actually 13 * 38 * 5 * 128 = 316160 individual tests hidden here.
'test-parsing/ParserSync': [PASS, NO_VARIANTS], 'test-parsing/ParserSync': [PASS, NO_VARIANTS],
# This tests only the type system, so there is no point in running several
# variants.
'test-types/*': [PASS, NO_VARIANTS],
# BUG(2999). # BUG(2999).
'test-cpu-profiler/CollectCpuProfile': [PASS, FLAKY], 'test-cpu-profiler/CollectCpuProfile': [PASS, FLAKY],
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <list> #include <vector>
#include "cctest.h" #include "cctest.h"
#include "types.h" #include "types.h"
...@@ -36,106 +36,54 @@ using namespace v8::internal; ...@@ -36,106 +36,54 @@ using namespace v8::internal;
template<class Type, class TypeHandle, class Region> template<class Type, class TypeHandle, class Region>
class Types { class Types {
public: public:
Types(Region* region, Isolate* isolate) : Types(Region* region, Isolate* isolate) : region_(region) {
Representation(Type::Representation(region)), static const size_t kMaxTypes = 300;
Semantic(Type::Semantic(region)), types.reserve(kMaxTypes);
None(Type::None(region)),
Any(Type::Any(region)), #define DECLARE_TYPE(name, value) \
Boolean(Type::Boolean(region)), name = Type::name(region); \
Null(Type::Null(region)), types.push_back(name);
Undefined(Type::Undefined(region)), BITSET_TYPE_LIST(DECLARE_TYPE)
Number(Type::Number(region)), #undef DECLARE_TYPE
SignedSmall(Type::SignedSmall(region)),
Signed32(Type::Signed32(region)), object_map = isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize);
Float(Type::Float(region)), array_map = isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize);
Name(Type::Name(region)), ObjectClass = Type::Class(object_map, region);
UniqueName(Type::UniqueName(region)), ArrayClass = Type::Class(array_map, region);
String(Type::String(region)), types.push_back(ObjectClass);
InternalizedString(Type::InternalizedString(region)), types.push_back(ArrayClass);
Symbol(Type::Symbol(region)),
Receiver(Type::Receiver(region)),
Object(Type::Object(region)),
Array(Type::Array(region)),
Function(Type::Function(region)),
Proxy(Type::Proxy(region)),
object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)),
array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)),
region_(region) {
smi = handle(Smi::FromInt(666), isolate); smi = handle(Smi::FromInt(666), isolate);
signed32 = isolate->factory()->NewHeapNumber(0x40000000); signed32 = isolate->factory()->NewHeapNumber(0x40000000);
object1 = isolate->factory()->NewJSObjectFromMap(object_map); object1 = isolate->factory()->NewJSObjectFromMap(object_map);
object2 = isolate->factory()->NewJSObjectFromMap(object_map); object2 = isolate->factory()->NewJSObjectFromMap(object_map);
array = isolate->factory()->NewJSArray(20); array = isolate->factory()->NewJSArray(20);
ObjectClass = Type::Class(object_map, region); values.push_back(smi);
ArrayClass = Type::Class(array_map, region); values.push_back(signed32);
values.push_back(object1);
values.push_back(object2);
values.push_back(array);
SmiConstant = Type::Constant(smi, region); SmiConstant = Type::Constant(smi, region);
Signed32Constant = Type::Constant(signed32, region); Signed32Constant = Type::Constant(signed32, region);
ObjectConstant1 = Type::Constant(object1, region); ObjectConstant1 = Type::Constant(object1, region);
ObjectConstant2 = Type::Constant(object2, region); ObjectConstant2 = Type::Constant(object2, region);
ArrayConstant1 = Type::Constant(array, region); ArrayConstant = Type::Constant(array, region);
ArrayConstant2 = Type::Constant(array, region); for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) {
types.push_back(Type::Constant(*it, region));
types.push_back(None);
types.push_back(Any);
types.push_back(Boolean);
types.push_back(Null);
types.push_back(Undefined);
types.push_back(Number);
types.push_back(SignedSmall);
types.push_back(Signed32);
types.push_back(Float);
types.push_back(Name);
types.push_back(UniqueName);
types.push_back(String);
types.push_back(InternalizedString);
types.push_back(Symbol);
types.push_back(Receiver);
types.push_back(Object);
types.push_back(Array);
types.push_back(Function);
types.push_back(Proxy);
types.push_back(ObjectClass);
types.push_back(ArrayClass);
types.push_back(SmiConstant);
types.push_back(Signed32Constant);
types.push_back(ObjectConstant1);
types.push_back(ObjectConstant2);
types.push_back(ArrayConstant1);
types.push_back(ArrayConstant2);
for (int i = 0; i < 300; ++i) {
types.push_back(Fuzz());
} }
objects.push_back(smi); while (types.size() < kMaxTypes) {
objects.push_back(signed32); size_t i = rng.NextInt(types.size());
objects.push_back(object1); size_t j = rng.NextInt(types.size());
objects.push_back(object2); if (i != j) types.push_back(Type::Union(types[i], types[j], region));
objects.push_back(array); }
} }
RandomNumberGenerator rng; RandomNumberGenerator rng;
TypeHandle Representation; #define DECLARE_TYPE(name, value) TypeHandle name;
TypeHandle Semantic; BITSET_TYPE_LIST(DECLARE_TYPE)
TypeHandle None; #undef DECLARE_TYPE
TypeHandle Any;
TypeHandle Boolean;
TypeHandle Null;
TypeHandle Undefined;
TypeHandle Number;
TypeHandle SignedSmall;
TypeHandle Signed32;
TypeHandle Float;
TypeHandle Name;
TypeHandle UniqueName;
TypeHandle String;
TypeHandle InternalizedString;
TypeHandle Symbol;
TypeHandle Receiver;
TypeHandle Object;
TypeHandle Array;
TypeHandle Function;
TypeHandle Proxy;
TypeHandle ObjectClass; TypeHandle ObjectClass;
TypeHandle ArrayClass; TypeHandle ArrayClass;
...@@ -144,8 +92,7 @@ class Types { ...@@ -144,8 +92,7 @@ class Types {
TypeHandle Signed32Constant; TypeHandle Signed32Constant;
TypeHandle ObjectConstant1; TypeHandle ObjectConstant1;
TypeHandle ObjectConstant2; TypeHandle ObjectConstant2;
TypeHandle ArrayConstant1; TypeHandle ArrayConstant;
TypeHandle ArrayConstant2;
Handle<i::Map> object_map; Handle<i::Map> object_map;
Handle<i::Map> array_map; Handle<i::Map> array_map;
...@@ -156,16 +103,20 @@ class Types { ...@@ -156,16 +103,20 @@ class Types {
Handle<i::JSObject> object2; Handle<i::JSObject> object2;
Handle<i::JSArray> array; Handle<i::JSArray> array;
typedef std::list<TypeHandle> TypeList; typedef std::vector<TypeHandle> TypeVector;
TypeList types; TypeVector types;
typedef std::list<Handle<i::Object> > ObjectList; typedef std::vector<Handle<i::Object> > ValueVector;
ObjectList objects; ValueVector values;
TypeHandle Of(Handle<i::Object> obj) { TypeHandle Of(Handle<i::Object> obj) {
return Type::Of(obj, region_); return Type::Of(obj, region_);
} }
TypeHandle NowOf(Handle<i::Object> obj) {
return Type::NowOf(obj, region_);
}
TypeHandle Constant(Handle<i::Object> obj) { TypeHandle Constant(Handle<i::Object> obj) {
return Type::Constant(obj, region_); return Type::Constant(obj, region_);
} }
...@@ -182,49 +133,6 @@ class Types { ...@@ -182,49 +133,6 @@ class Types {
return Type::template Convert<Type2>(t, region_); return Type::template Convert<Type2>(t, region_);
} }
TypeHandle Fuzz(int depth = 5) {
switch (rng.NextInt(depth == 0 ? 3 : 20)) {
case 0: { // bitset
int n = 0
#define COUNT_BITSET_TYPES(type, value) + 1
BITSET_TYPE_LIST(COUNT_BITSET_TYPES)
#undef COUNT_BITSET_TYPES
;
int i = rng.NextInt(n);
#define PICK_BITSET_TYPE(type, value) \
if (i-- == 0) return Type::type(region_);
BITSET_TYPE_LIST(PICK_BITSET_TYPE)
#undef PICK_BITSET_TYPE
UNREACHABLE();
}
case 1: // class
switch (rng.NextInt(2)) {
case 0: return ObjectClass;
case 1: return ArrayClass;
}
UNREACHABLE();
case 2: // constant
switch (rng.NextInt(6)) {
case 0: return SmiConstant;
case 1: return Signed32Constant;
case 2: return ObjectConstant1;
case 3: return ObjectConstant2;
case 4: return ArrayConstant1;
case 5: return ArrayConstant2;
}
UNREACHABLE();
default: { // union
int n = rng.NextInt(10);
TypeHandle type = None;
for (int i = 0; i < n; ++i) {
type = Type::Union(type, Fuzz(depth - 1), region_);
}
return type;
}
}
UNREACHABLE();
}
private: private:
Region* region_; Region* region_;
}; };
...@@ -291,14 +199,14 @@ struct HeapRep { ...@@ -291,14 +199,14 @@ struct HeapRep {
template<class Type, class TypeHandle, class Region, class Rep> template<class Type, class TypeHandle, class Region, class Rep>
struct Tests : Rep { struct Tests : Rep {
typedef Types<Type, TypeHandle, Region> TypesInstance;
typedef typename TypesInstance::TypeVector::iterator TypeIterator;
typedef typename TypesInstance::ValueVector::iterator ValueIterator;
Isolate* isolate; Isolate* isolate;
HandleScope scope; HandleScope scope;
Zone zone; Zone zone;
Types<Type, TypeHandle, Region> T; TypesInstance T;
typedef typename Types<Type, TypeHandle, Region>::TypeList::iterator
TypeIterator;
typedef typename Types<Type, TypeHandle, Region>::ObjectList::iterator
ObjectIterator;
Tests() : Tests() :
isolate(CcTest::i_isolate()), isolate(CcTest::i_isolate()),
...@@ -394,15 +302,35 @@ struct Tests : Rep { ...@@ -394,15 +302,35 @@ struct Tests : Rep {
CHECK(this->IsConstant(T.SmiConstant)); CHECK(this->IsConstant(T.SmiConstant));
CHECK(this->IsConstant(T.ObjectConstant1)); CHECK(this->IsConstant(T.ObjectConstant1));
CHECK(this->IsConstant(T.ObjectConstant2)); CHECK(this->IsConstant(T.ObjectConstant2));
CHECK(this->IsConstant(T.ArrayConstant1)); CHECK(this->IsConstant(T.ArrayConstant));
CHECK(this->IsConstant(T.ArrayConstant2));
CHECK(*T.smi == this->AsConstant(T.SmiConstant)); CHECK(*T.smi == this->AsConstant(T.SmiConstant));
CHECK(*T.object1 == this->AsConstant(T.ObjectConstant1)); CHECK(*T.object1 == this->AsConstant(T.ObjectConstant1));
CHECK(*T.object2 == this->AsConstant(T.ObjectConstant2)); CHECK(*T.object2 == this->AsConstant(T.ObjectConstant2));
CHECK(*T.object1 != this->AsConstant(T.ObjectConstant2)); CHECK(*T.object1 != this->AsConstant(T.ObjectConstant2));
CHECK(*T.array == this->AsConstant(T.ArrayConstant1)); CHECK(*T.array == this->AsConstant(T.ArrayConstant));
CHECK(*T.array == this->AsConstant(T.ArrayConstant2)); }
void Of() {
CHECK(T.Of(T.smi)->Is(T.SignedSmall));
CHECK(T.Of(T.signed32)->Is(T.Signed32));
CHECK(T.Of(T.object1)->Is(T.Object));
CHECK(T.Of(T.object2)->Is(T.Object));
CHECK(T.Of(T.array)->Is(T.Array));
}
void NowOf() {
// NowOf(V)->Is(Of(V)) for all V
for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
Handle<i::Object> val = *vt;
CHECK(T.NowOf(val)->Is(T.Of(val)));
}
CHECK(T.NowOf(T.smi)->NowIs(T.SignedSmall));
CHECK(T.NowOf(T.signed32)->NowIs(T.Signed32));
CHECK(T.NowOf(T.object1)->NowIs(T.ObjectClass));
CHECK(T.NowOf(T.object2)->NowIs(T.ObjectClass));
CHECK(T.NowOf(T.array)->NowIs(T.Array));
} }
void Is() { void Is() {
...@@ -503,16 +431,16 @@ struct Tests : Rep { ...@@ -503,16 +431,16 @@ struct Tests : Rep {
CheckSub(T.SmiConstant, T.Number); CheckSub(T.SmiConstant, T.Number);
CheckSub(T.ObjectConstant1, T.Object); CheckSub(T.ObjectConstant1, T.Object);
CheckSub(T.ObjectConstant2, T.Object); CheckSub(T.ObjectConstant2, T.Object);
CheckSub(T.ArrayConstant1, T.Object); CheckSub(T.ArrayConstant, T.Object);
CheckSub(T.ArrayConstant1, T.Array); CheckSub(T.ArrayConstant, T.Array);
CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); CheckUnordered(T.ObjectConstant1, T.ObjectConstant2);
CheckUnordered(T.ObjectConstant1, T.ArrayConstant1); CheckUnordered(T.ObjectConstant1, T.ArrayConstant);
CheckUnordered(T.ObjectConstant1, T.ObjectClass); CheckUnordered(T.ObjectConstant1, T.ObjectClass);
CheckUnordered(T.ObjectConstant2, T.ObjectClass); CheckUnordered(T.ObjectConstant2, T.ObjectClass);
CheckUnordered(T.ObjectConstant1, T.ArrayClass); CheckUnordered(T.ObjectConstant1, T.ArrayClass);
CheckUnordered(T.ObjectConstant2, T.ArrayClass); CheckUnordered(T.ObjectConstant2, T.ArrayClass);
CheckUnordered(T.ArrayConstant1, T.ObjectClass); CheckUnordered(T.ArrayConstant, T.ObjectClass);
} }
void NowIs() { void NowIs() {
...@@ -574,21 +502,59 @@ struct Tests : Rep { ...@@ -574,21 +502,59 @@ struct Tests : Rep {
} }
void Contains() { void Contains() {
// T->Contains(O) iff Constant(O)->Is(T) for all T,O // T->Contains(V) iff Constant(V)->Is(T) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it;
Handle<i::Object> val = *vt;
CHECK(type->Contains(val) == T.Constant(val)->Is(type));
}
}
// Of(V)->Is(T) implies T->Contains(V) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it;
Handle<i::Object> val = *vt;
CHECK(!T.Of(val)->Is(type) || type->Contains(val));
}
}
}
void NowContains() {
// T->NowContains(V) iff Constant(V)->NowIs(T) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it;
Handle<i::Object> val = *vt;
CHECK(type->NowContains(val) == T.Constant(val)->NowIs(type));
}
}
// NowOf(V)->Is(T) implies T->NowContains(V) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it;
Handle<i::Object> value = *vt;
CHECK(!T.NowOf(value)->NowIs(type) || type->NowContains(value));
}
}
// NowOf(V)->NowIs(T) implies T->NowContains(V) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ObjectIterator ot = T.objects.begin(); ot != T.objects.end(); ++ot) { for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it; TypeHandle type = *it;
Handle<i::Object> obj = *ot; Handle<i::Object> val = *vt;
CHECK(type->Contains(obj) == T.Constant(obj)->Is(type)); CHECK(!T.NowOf(val)->NowIs(type) || type->NowContains(val));
} }
} }
// Of(O)->Is(T) implies T->Contains(O) for all T,O // T->Contains(V) implies T->NowContains(V) for all T,V
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
for (ObjectIterator ot = T.objects.begin(); ot != T.objects.end(); ++ot) { for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
TypeHandle type = *it; TypeHandle type = *it;
Handle<i::Object> obj = *ot; Handle<i::Object> val = *vt;
CHECK(!T.Of(obj)->Is(type) || type->Contains(obj)); CHECK(!type->Contains(val) || type->NowContains(val));
} }
} }
} }
...@@ -600,7 +566,7 @@ struct Tests : Rep { ...@@ -600,7 +566,7 @@ struct Tests : Rep {
CHECK(type->Maybe(type) || !type->IsInhabited()); CHECK(type->Maybe(type) || !type->IsInhabited());
} }
// Commutativity // Symmetry
for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
TypeHandle type1 = *it1; TypeHandle type1 = *it1;
...@@ -669,18 +635,17 @@ struct Tests : Rep { ...@@ -669,18 +635,17 @@ struct Tests : Rep {
CheckDisjoint(T.SmiConstant, T.Float, T.Semantic); CheckDisjoint(T.SmiConstant, T.Float, T.Semantic);
CheckOverlap(T.ObjectConstant1, T.Object, T.Semantic); CheckOverlap(T.ObjectConstant1, T.Object, T.Semantic);
CheckOverlap(T.ObjectConstant2, T.Object, T.Semantic); CheckOverlap(T.ObjectConstant2, T.Object, T.Semantic);
CheckOverlap(T.ArrayConstant1, T.Object, T.Semantic); CheckOverlap(T.ArrayConstant, T.Object, T.Semantic);
CheckOverlap(T.ArrayConstant1, T.Array, T.Semantic); CheckOverlap(T.ArrayConstant, T.Array, T.Semantic);
CheckOverlap(T.ArrayConstant1, T.ArrayConstant2, T.Semantic);
CheckOverlap(T.ObjectConstant1, T.ObjectConstant1, T.Semantic); CheckOverlap(T.ObjectConstant1, T.ObjectConstant1, T.Semantic);
CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2, T.Semantic); CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2, T.Semantic);
CheckDisjoint(T.ObjectConstant1, T.ArrayConstant1, T.Semantic); CheckDisjoint(T.ObjectConstant1, T.ArrayConstant, T.Semantic);
CheckDisjoint(T.ObjectConstant1, T.ObjectClass, T.Semantic); CheckDisjoint(T.ObjectConstant1, T.ObjectClass, T.Semantic);
CheckDisjoint(T.ObjectConstant2, T.ObjectClass, T.Semantic); CheckDisjoint(T.ObjectConstant2, T.ObjectClass, T.Semantic);
CheckDisjoint(T.ObjectConstant1, T.ArrayClass, T.Semantic); CheckDisjoint(T.ObjectConstant1, T.ArrayClass, T.Semantic);
CheckDisjoint(T.ObjectConstant2, T.ArrayClass, T.Semantic); CheckDisjoint(T.ObjectConstant2, T.ArrayClass, T.Semantic);
CheckDisjoint(T.ArrayConstant1, T.ObjectClass, T.Semantic); CheckDisjoint(T.ArrayConstant, T.ObjectClass, T.Semantic);
} }
void Union() { void Union() {
...@@ -710,32 +675,27 @@ struct Tests : Rep { ...@@ -710,32 +675,27 @@ struct Tests : Rep {
// Constant-constant // Constant-constant
CHECK(this->IsConstant(T.Union(T.ObjectConstant1, T.ObjectConstant1))); CHECK(this->IsConstant(T.Union(T.ObjectConstant1, T.ObjectConstant1)));
CHECK(this->IsConstant(T.Union(T.ArrayConstant1, T.ArrayConstant1))); CHECK(this->IsConstant(T.Union(T.ArrayConstant, T.ArrayConstant)));
CHECK(this->IsUnion(T.Union(T.ObjectConstant1, T.ObjectConstant2))); CHECK(this->IsUnion(T.Union(T.ObjectConstant1, T.ObjectConstant2)));
CheckEqual( CheckEqual(
T.Union(T.ObjectConstant1, T.ObjectConstant1), T.Union(T.ObjectConstant1, T.ObjectConstant1),
T.ObjectConstant1); T.ObjectConstant1);
CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1); CheckEqual(T.Union(T.ArrayConstant, T.ArrayConstant), T.ArrayConstant);
CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2);
CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2)); CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2));
CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any); CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any);
CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2));
CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2));
CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2));
CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object);
CheckUnordered( CheckUnordered(
T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass);
CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array);
CheckOverlap(
T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array, T.Semantic);
CheckOverlap( CheckOverlap(
T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2, T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array, T.Semantic);
T.Semantic);
CheckDisjoint( CheckDisjoint(
T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number, T.Semantic); T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number, T.Semantic);
CheckDisjoint( CheckDisjoint(
T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass,
T.Semantic); T.Semantic);
// Bitset-class // Bitset-class
...@@ -781,7 +741,7 @@ struct Tests : Rep { ...@@ -781,7 +741,7 @@ struct Tests : Rep {
CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass));
CheckSub( CheckSub(
T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object));
CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1); CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant);
CheckDisjoint( CheckDisjoint(
T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2,
T.Semantic); T.Semantic);
...@@ -842,9 +802,9 @@ struct Tests : Rep { ...@@ -842,9 +802,9 @@ struct Tests : Rep {
CHECK(this->IsUnion(T.Union( CHECK(this->IsUnion(T.Union(
T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2))));
CHECK(this->IsUnion(T.Union( CHECK(this->IsUnion(T.Union(
T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1)));
CHECK(this->IsUnion(T.Union( CHECK(this->IsUnion(T.Union(
T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1))); T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1)));
CheckEqual( CheckEqual(
T.Union( T.Union(
...@@ -852,9 +812,9 @@ struct Tests : Rep { ...@@ -852,9 +812,9 @@ struct Tests : Rep {
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
CheckEqual( CheckEqual(
T.Union( T.Union(
T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1), T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1),
T.Union( T.Union(
T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1))); T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1)));
// Union-union // Union-union
CHECK(this->IsBitset(T.Union( CHECK(this->IsBitset(T.Union(
...@@ -869,13 +829,6 @@ struct Tests : Rep { ...@@ -869,13 +829,6 @@ struct Tests : Rep {
T.Union(T.ObjectConstant2, T.ObjectConstant1), T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Union(T.ObjectConstant1, T.ObjectConstant2)), T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
CheckEqual(
T.Union(
T.Union(T.ObjectConstant2, T.ArrayConstant1),
T.Union(T.ObjectConstant1, T.ArrayConstant2)),
T.Union(
T.Union(T.ObjectConstant1, T.ObjectConstant2),
T.ArrayConstant1));
CheckEqual( CheckEqual(
T.Union( T.Union(
T.Union(T.Number, T.ArrayClass), T.Union(T.Number, T.ArrayClass),
...@@ -903,13 +856,10 @@ struct Tests : Rep { ...@@ -903,13 +856,10 @@ struct Tests : Rep {
// Constant-constant // Constant-constant
CHECK(this->IsConstant(T.Intersect(T.ObjectConstant1, T.ObjectConstant1))); CHECK(this->IsConstant(T.Intersect(T.ObjectConstant1, T.ObjectConstant1)));
CHECK(this->IsConstant(T.Intersect(T.ArrayConstant1, T.ArrayConstant2)));
CHECK(this->IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectConstant2))); CHECK(this->IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectConstant2)));
CheckEqual( CheckEqual(
T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1);
CheckEqual(
T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1);
CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None); CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None);
// Bitset-class // Bitset-class
...@@ -955,7 +905,7 @@ struct Tests : Rep { ...@@ -955,7 +905,7 @@ struct Tests : Rep {
CHECK(this->IsClass( CHECK(this->IsClass(
T.Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass))); T.Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass)));
CHECK(this->IsBitset( CHECK(this->IsBitset(
T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass))); T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass)));
CheckEqual( CheckEqual(
T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)),
...@@ -964,7 +914,7 @@ struct Tests : Rep { ...@@ -964,7 +914,7 @@ struct Tests : Rep {
T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)),
T.ArrayClass); T.ArrayClass);
CheckEqual( CheckEqual(
T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass), T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass),
T.None); T.None);
// Constant-union // Constant-union
...@@ -973,7 +923,7 @@ struct Tests : Rep { ...@@ -973,7 +923,7 @@ struct Tests : Rep {
CHECK(this->IsConstant(T.Intersect( CHECK(this->IsConstant(T.Intersect(
T.Union(T.Number, T.ObjectClass), T.SmiConstant))); T.Union(T.Number, T.ObjectClass), T.SmiConstant)));
CHECK(this->IsBitset(T.Intersect( CHECK(this->IsBitset(T.Intersect(
T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1)));
CheckEqual( CheckEqual(
T.Intersect( T.Intersect(
...@@ -984,7 +934,7 @@ struct Tests : Rep { ...@@ -984,7 +934,7 @@ struct Tests : Rep {
T.SmiConstant); T.SmiConstant);
CheckEqual( CheckEqual(
T.Intersect( T.Intersect(
T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1), T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1),
T.None); T.None);
// Union-union // Union-union
...@@ -1014,21 +964,16 @@ struct Tests : Rep { ...@@ -1014,21 +964,16 @@ struct Tests : Rep {
T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass),
T.Union( T.Union(
T.ObjectConstant1, T.ObjectConstant1,
T.Union(T.ArrayConstant1, T.ObjectConstant2))), T.Union(T.ArrayConstant, T.ObjectConstant2))),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
CheckEqual(
T.Intersect(
T.Union(T.ObjectConstant2, T.ArrayConstant1),
T.Union(T.ObjectConstant1, T.ArrayConstant2)),
T.ArrayConstant1);
} }
template<class Type2, class TypeHandle2, class Region2, class Rep2> template<class Type2, class TypeHandle2, class Region2, class Rep2>
void Convert() { void Convert() {
Types<Type2, TypeHandle2, Region2> T2( Types<Type2, TypeHandle2, Region2> T2(
Rep2::ToRegion(&zone, isolate), isolate); Rep2::ToRegion(&zone, isolate), isolate);
for (int i = 0; i < 100; ++i) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
TypeHandle type = T.Fuzz(); TypeHandle type = *it;
CheckEqual(type, CheckEqual(type,
T.template Convert<Type2>(T2.template Convert<Type>(type))); T.template Convert<Type2>(T2.template Convert<Type>(type)));
} }
...@@ -1060,6 +1005,20 @@ TEST(Constant) { ...@@ -1060,6 +1005,20 @@ TEST(Constant) {
} }
TEST(Of) {
CcTest::InitializeVM();
ZoneTests().Of();
HeapTests().Of();
}
TEST(NowOf) {
CcTest::InitializeVM();
ZoneTests().NowOf();
HeapTests().NowOf();
}
TEST(Is) { TEST(Is) {
CcTest::InitializeVM(); CcTest::InitializeVM();
ZoneTests().Is(); ZoneTests().Is();
...@@ -1081,6 +1040,13 @@ TEST(Contains) { ...@@ -1081,6 +1040,13 @@ TEST(Contains) {
} }
TEST(NowContains) {
CcTest::InitializeVM();
ZoneTests().NowContains();
HeapTests().NowContains();
}
TEST(Maybe) { TEST(Maybe) {
CcTest::InitializeVM(); CcTest::InitializeVM();
ZoneTests().Maybe(); ZoneTests().Maybe();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment