Minor clarifications and simplifications as well as additional checks.

R=rossberg@chromium.org
BUG=

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22573 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
neis@chromium.org 2014-07-23 17:17:48 +00:00
parent ea1be613dc
commit 61e1994f83
2 changed files with 29 additions and 28 deletions

View File

@ -262,7 +262,7 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
if (this->IsBitset() && SEMANTIC(this->AsBitset()) == BitsetType::kNone) {
// Bitsets only have non-bitset supertypes along the representation axis.
int that_bitset = that->BitsetGlb();
return (this->AsBitset() | that_bitset) == that_bitset;
return (BitsetType::Is(this->AsBitset(), that_bitset));
}
if (that->IsClass()) {
@ -313,16 +313,12 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
// T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn)
// (iff T is not a union)
ASSERT(!this->IsUnion());
if (that->IsUnion()) {
UnionHandle unioned = handle(that->AsUnion());
for (int i = 0; i < unioned->Length(); ++i) {
if (this->Is(unioned->Get(i))) return true;
if (this->IsBitset()) break; // Fast fail, only first field is a bitset.
}
return false;
ASSERT(!this->IsUnion() && that->IsUnion());
UnionHandle unioned = handle(that->AsUnion());
for (int i = 0; i < unioned->Length(); ++i) {
if (this->Is(unioned->Get(i))) return true;
if (this->IsBitset()) break; // Fast fail, only first field is a bitset.
}
return false;
}
@ -382,11 +378,8 @@ bool TypeImpl<Config>::Maybe(TypeImpl* that) {
}
ASSERT(!this->IsUnion() && !that->IsUnion());
if (this->IsBitset()) {
return BitsetType::IsInhabited(this->AsBitset() & that->BitsetLub());
}
if (that->IsBitset()) {
return BitsetType::IsInhabited(this->BitsetLub() & that->AsBitset());
if (this->IsBitset() || that->IsBitset()) {
return BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub());
}
if (this->IsClass()) {
return that->IsClass()
@ -441,7 +434,7 @@ bool TypeImpl<Config>::UnionType::Wellformed() {
// Union and intersection
template<class Config>
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Narrow(
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Rebound(
int bitset, Region* region) {
TypeHandle bound = BitsetType::New(bitset, region);
if (this->IsClass()) {
@ -555,7 +548,7 @@ int TypeImpl<Config>::ExtendUnion(
new_bound |= type_i_bound;
if (new_bound == type_i_bound) return size;
}
if (new_bound != old_bound) type = type->Narrow(new_bound, region);
if (new_bound != old_bound) type = type->Rebound(new_bound, region);
result->Set(i, type);
}
}
@ -570,7 +563,7 @@ int TypeImpl<Config>::NormalizeUnion(UnionHandle result, int size, int bitset) {
if (bitset != BitsetType::kNone && SEMANTIC(bitset) == BitsetType::kNone) {
for (int i = 1; i < size; ++i) {
int glb = result->Get(i)->BitsetGlb();
if ((bitset | glb) == glb) {
if (BitsetType::Is(bitset, glb)) {
for (int j = 1; j < size; ++j) {
result->Set(j - 1, result->Get(j));
}

View File

@ -68,11 +68,12 @@ namespace internal {
// None <= R
// R <= Any
//
// UntaggedInt <= UntaggedInt8 \/ UntaggedInt16 \/ UntaggedInt32)
// UntaggedFloat <= UntaggedFloat32 \/ UntaggedFloat64
// UntaggedNumber <= UntaggedInt \/ UntaggedFloat
// Untagged <= UntaggedNumber \/ UntaggedPtr
// Tagged <= TaggedInt \/ TaggedPtr
// UntaggedInt = UntaggedInt1 \/ UntaggedInt8 \/
// UntaggedInt16 \/ UntaggedInt32
// UntaggedFloat = UntaggedFloat32 \/ UntaggedFloat64
// UntaggedNumber = UntaggedInt \/ UntaggedFloat
// Untagged = UntaggedNumber \/ UntaggedPtr
// Tagged = TaggedInt \/ TaggedPtr
//
// Subtyping relates the two dimensions, for example:
//
@ -464,7 +465,7 @@ class TypeImpl : public Config::Base {
bool SlowIs(TypeImpl* that);
TypeHandle Narrow(int bitset, Region* region);
TypeHandle Rebound(int bitset, Region* region);
int BoundBy(TypeImpl* that);
int IndexInUnion(int bound, UnionHandle unioned, int current_size);
static int ExtendUnion(
@ -502,6 +503,10 @@ class TypeImpl<Config>::BitsetType : public TypeImpl<Config> {
return (bitset & kRepresentation) && (bitset & kSemantic);
}
static bool Is(int bitset1, int bitset2) {
return (bitset1 | bitset2) == bitset2;
}
static int Glb(TypeImpl* type); // greatest lower bound that's a bitset
static int Lub(TypeImpl* type); // least upper bound that's a bitset
static int Lub(i::Object* value);
@ -612,6 +617,7 @@ class TypeImpl<Config>::ClassType : public StructuralType {
static ClassHandle New(
i::Handle<i::Map> map, TypeHandle bound, Region* region) {
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::Lub(*map)));
ClassHandle type = Config::template cast<ClassType>(
StructuralType::New(StructuralType::kClassTag, 2, region));
type->Set(0, bound);
@ -648,6 +654,7 @@ class TypeImpl<Config>::ConstantType : public StructuralType {
static ConstantHandle New(
i::Handle<i::Object> value, TypeHandle bound, Region* region) {
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::Lub(*value)));
ConstantHandle type = Config::template cast<ConstantType>(
StructuralType::New(StructuralType::kConstantTag, 2, region));
type->Set(0, bound);
@ -679,8 +686,7 @@ class TypeImpl<Config>::RangeType : public StructuralType {
static RangeHandle New(
double min, double max, TypeHandle bound, Region* region) {
ASSERT(SEMANTIC(bound->AsBitset() | BitsetType::kNumber)
== SEMANTIC(BitsetType::kNumber));
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kNumber));
ASSERT(!std::isnan(min) && !std::isnan(max) && min <= max);
RangeHandle type = Config::template cast<RangeType>(
StructuralType::New(StructuralType::kRangeTag, 3, region));
@ -715,6 +721,8 @@ class TypeImpl<Config>::ContextType : public StructuralType {
TypeHandle Outer() { return this->Get(1); }
static ContextHandle New(TypeHandle outer, TypeHandle bound, Region* region) {
ASSERT(BitsetType::Is(
bound->AsBitset(), BitsetType::kInternal & BitsetType::kTaggedPtr));
ContextHandle type = Config::template cast<ContextType>(
StructuralType::New(StructuralType::kContextTag, 2, region));
type->Set(0, bound);
@ -745,7 +753,7 @@ class TypeImpl<Config>::ArrayType : public StructuralType {
TypeHandle Element() { return this->Get(1); }
static ArrayHandle New(TypeHandle element, TypeHandle bound, Region* region) {
ASSERT(SEMANTIC(bound->AsBitset()) == SEMANTIC(BitsetType::kArray));
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kArray));
ArrayHandle type = Config::template cast<ArrayType>(
StructuralType::New(StructuralType::kArrayTag, 2, region));
type->Set(0, bound);
@ -782,7 +790,7 @@ class TypeImpl<Config>::FunctionType : public StructuralType {
static FunctionHandle New(
TypeHandle result, TypeHandle receiver, TypeHandle bound,
int arity, Region* region) {
ASSERT(SEMANTIC(bound->AsBitset()) == SEMANTIC(BitsetType::kFunction));
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kFunction));
FunctionHandle type = Config::template cast<FunctionType>(
StructuralType::New(StructuralType::kFunctionTag, 3 + arity, region));
type->Set(0, bound);