Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: src/types.cc

Issue 564413004: Re-revert "Use unsigned type bitsets to limit undefined behaviour" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/types.h ('k') | src/types-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types.cc
diff --git a/src/types.cc b/src/types.cc
index 16696ea282b67518a4e4877cb42c3c29bb50b8a3..af45fa41cb012d02610aa89d8c3218fc5db184cf 100644
--- a/src/types.cc
+++ b/src/types.cc
@@ -30,8 +30,7 @@ static bool deq(double x, double y) {
// The largest bitset subsumed by this type.
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) {
+int TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) {
DisallowHeapAllocation no_allocation;
if (type->IsBitset()) {
return type->AsBitset();
@@ -47,18 +46,17 @@ TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) {
// The smallest bitset subsuming this type.
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
+int TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
DisallowHeapAllocation no_allocation;
if (type->IsBitset()) {
return type->AsBitset();
} else if (type->IsUnion()) {
UnionHandle unioned = handle(type->AsUnion());
- bitset result = kNone;
+ int bitset = kNone;
for (int i = 0; i < unioned->Length(); ++i) {
- result |= unioned->Get(i)->BitsetLub();
+ bitset |= unioned->Get(i)->BitsetLub();
}
- return result;
+ return bitset;
} else if (type->IsClass()) {
// Little hack to avoid the need for a region for handlification here...
return Config::is_class(type) ? Lub(*Config::as_class(type)) :
@@ -82,18 +80,17 @@ TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
// The smallest bitset subsuming this type, ignoring explicit bounds.
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::InherentLub(TypeImpl* type) {
+int TypeImpl<Config>::BitsetType::InherentLub(TypeImpl* type) {
DisallowHeapAllocation no_allocation;
if (type->IsBitset()) {
return type->AsBitset();
} else if (type->IsUnion()) {
UnionHandle unioned = handle(type->AsUnion());
- bitset result = kNone;
+ int bitset = kNone;
for (int i = 0; i < unioned->Length(); ++i) {
- result |= unioned->Get(i)->InherentBitsetLub();
+ bitset |= unioned->Get(i)->InherentBitsetLub();
}
- return result;
+ return bitset;
} else if (type->IsClass()) {
return Lub(*type->AsClass()->Map());
} else if (type->IsConstant()) {
@@ -114,8 +111,7 @@ TypeImpl<Config>::BitsetType::InherentLub(TypeImpl* type) {
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(i::Object* value) {
+int TypeImpl<Config>::BitsetType::Lub(i::Object* value) {
DisallowHeapAllocation no_allocation;
if (value->IsNumber()) {
return Lub(value->Number()) & (value->IsSmi() ? kTaggedInt : kTaggedPtr);
@@ -125,8 +121,7 @@ TypeImpl<Config>::BitsetType::Lub(i::Object* value) {
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(double value) {
+int TypeImpl<Config>::BitsetType::Lub(double value) {
DisallowHeapAllocation no_allocation;
if (i::IsMinusZero(value)) return kMinusZero;
if (std::isnan(value)) return kNaN;
@@ -137,21 +132,19 @@ TypeImpl<Config>::BitsetType::Lub(double value) {
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(double min, double max) {
+int TypeImpl<Config>::BitsetType::Lub(double min, double max) {
DisallowHeapAllocation no_allocation;
DCHECK(dle(min, max));
if (deq(min, max)) return BitsetType::Lub(min); // Singleton range.
- bitset result = BitsetType::kNumber ^ SEMANTIC(BitsetType::kNaN);
- if (dle(0, min) || max < 0) result ^= SEMANTIC(BitsetType::kMinusZero);
- return result;
+ int bitset = BitsetType::kNumber ^ SEMANTIC(BitsetType::kNaN);
+ if (dle(0, min) || max < 0) bitset ^= SEMANTIC(BitsetType::kMinusZero);
+ return bitset;
// TODO(neis): Could refine this further by doing more checks on min/max.
}
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(int32_t value) {
+int TypeImpl<Config>::BitsetType::Lub(int32_t value) {
if (value >= 0x40000000) {
return i::SmiValuesAre31Bits() ? kOtherUnsigned31 : kUnsignedSmall;
}
@@ -162,8 +155,7 @@ TypeImpl<Config>::BitsetType::Lub(int32_t value) {
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(uint32_t value) {
+int TypeImpl<Config>::BitsetType::Lub(uint32_t value) {
DisallowHeapAllocation no_allocation;
if (value >= 0x80000000u) return kOtherUnsigned32;
if (value >= 0x40000000u) {
@@ -174,8 +166,7 @@ TypeImpl<Config>::BitsetType::Lub(uint32_t value) {
template<class Config>
-typename TypeImpl<Config>::bitset
-TypeImpl<Config>::BitsetType::Lub(i::Map* map) {
+int TypeImpl<Config>::BitsetType::Lub(i::Map* map) {
DisallowHeapAllocation no_allocation;
switch (map->instance_type()) {
case STRING_TYPE:
@@ -466,8 +457,8 @@ bool TypeImpl<Config>::UnionType::Wellformed() {
template<class Config>
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Rebound(
- bitset bitset_bound, Region* region) {
- TypeHandle bound = BitsetType::New(bitset_bound, region);
+ int bitset, Region* region) {
+ TypeHandle bound = BitsetType::New(bitset, region);
if (this->IsClass()) {
return ClassType::New(this->AsClass()->Map(), bound, region);
} else if (this->IsConstant()) {
@@ -495,16 +486,16 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Rebound(
template<class Config>
-typename TypeImpl<Config>::bitset TypeImpl<Config>::BoundBy(TypeImpl* that) {
+int TypeImpl<Config>::BoundBy(TypeImpl* that) {
DCHECK(!this->IsUnion());
if (that->IsUnion()) {
UnionType* unioned = that->AsUnion();
int length = unioned->Length();
- bitset result = BitsetType::kNone;
+ int bitset = BitsetType::kNone;
for (int i = 0; i < length; ++i) {
- result |= BoundBy(unioned->Get(i)->unhandle());
+ bitset |= BoundBy(unioned->Get(i)->unhandle());
}
- return result;
+ return bitset;
} else if (that->IsClass() && this->IsClass() &&
*this->AsClass()->Map() == *that->AsClass()->Map()) {
return that->BitsetLub();
@@ -524,7 +515,7 @@ typename TypeImpl<Config>::bitset TypeImpl<Config>::BoundBy(TypeImpl* that) {
template<class Config>
int TypeImpl<Config>::IndexInUnion(
- bitset bound, UnionHandle unioned, int current_size) {
+ int bound, UnionHandle unioned, int current_size) {
DCHECK(!this->IsUnion());
for (int i = 0; i < current_size; ++i) {
TypeHandle that = unioned->Get(i);
@@ -554,7 +545,7 @@ int TypeImpl<Config>::ExtendUnion(
UnionHandle result, int size, TypeHandle type,
TypeHandle other, bool is_intersect, Region* region) {
if (type->IsUnion()) {
- UnionHandle unioned = Config::template cast<UnionType>(type);
+ UnionHandle unioned = handle(type->AsUnion());
for (int i = 0; i < unioned->Length(); ++i) {
TypeHandle type_i = unioned->Get(i);
DCHECK(i == 0 || !(type_i->IsBitset() || type_i->Is(unioned->Get(0))));
@@ -565,10 +556,10 @@ int TypeImpl<Config>::ExtendUnion(
} else if (!type->IsBitset()) {
DCHECK(type->IsClass() || type->IsConstant() || type->IsRange() ||
type->IsContext() || type->IsArray() || type->IsFunction());
- bitset inherent_bound = type->InherentBitsetLub();
- bitset old_bound = type->BitsetLub();
- bitset other_bound = type->BoundBy(other->unhandle()) & inherent_bound;
- bitset new_bound =
+ int inherent_bound = type->InherentBitsetLub();
+ int old_bound = type->BitsetLub();
+ int other_bound = type->BoundBy(other->unhandle()) & inherent_bound;
+ int new_bound =
is_intersect ? (old_bound & other_bound) : (old_bound | other_bound);
if (new_bound != BitsetType::kNone) {
int i = type->IndexInUnion(new_bound, result, size);
@@ -577,7 +568,7 @@ int TypeImpl<Config>::ExtendUnion(
} else if (result->Get(i)->IsBitset()) {
return size; // Already fully subsumed.
} else {
- bitset type_i_bound = result->Get(i)->BitsetLub();
+ int type_i_bound = result->Get(i)->BitsetLub();
new_bound |= type_i_bound;
if (new_bound == type_i_bound) return size;
}
@@ -616,14 +607,14 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union(
if (!type2->IsBitset()) {
size += (type2->IsUnion() ? type2->AsUnion()->Length() : 1);
}
- bitset bits = type1->BitsetGlb() | type2->BitsetGlb();
- if (bits != BitsetType::kNone) ++size;
+ int bitset = type1->BitsetGlb() | type2->BitsetGlb();
+ if (bitset != BitsetType::kNone) ++size;
DCHECK(size >= 1);
UnionHandle unioned = UnionType::New(size, region);
size = 0;
- if (bits != BitsetType::kNone) {
- unioned->Set(size++, BitsetType::New(bits, region));
+ if (bitset != BitsetType::kNone) {
+ unioned->Set(size++, BitsetType::New(bitset, region));
}
size = ExtendUnion(unioned, size, type1, type2, false, region);
size = ExtendUnion(unioned, size, type2, type1, false, region);
@@ -665,14 +656,14 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect(
if (!type2->IsBitset()) {
size += (type2->IsUnion() ? type2->AsUnion()->Length() : 1);
}
- bitset bits = type1->BitsetGlb() & type2->BitsetGlb();
- if (bits != BitsetType::kNone) ++size;
+ int bitset = type1->BitsetGlb() & type2->BitsetGlb();
+ if (bitset != BitsetType::kNone) ++size;
DCHECK(size >= 1);
UnionHandle unioned = UnionType::New(size, region);
size = 0;
- if (bits != BitsetType::kNone) {
- unioned->Set(size++, BitsetType::New(bits, region));
+ if (bitset != BitsetType::kNone) {
+ unioned->Set(size++, BitsetType::New(bitset, region));
}
size = ExtendUnion(unioned, size, type1, type2, true, region);
size = ExtendUnion(unioned, size, type2, type1, true, region);
@@ -781,7 +772,7 @@ void TypeImpl<Config>::Iterator<T>::Advance() {
DisallowHeapAllocation no_allocation;
++index_;
if (type_->IsUnion()) {
- UnionHandle unioned = Config::template cast<UnionType>(type_);
+ UnionHandle unioned = handle(type_->AsUnion());
for (; index_ < unioned->Length(); ++index_) {
if (matches(unioned->Get(index_))) return;
}
@@ -850,8 +841,8 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert(
// Printing.
template<class Config>
-const char* TypeImpl<Config>::BitsetType::Name(bitset bits) {
- switch (bits) {
+const char* TypeImpl<Config>::BitsetType::Name(int bitset) {
+ switch (bitset) {
case REPRESENTATION(kAny): return "Any";
#define RETURN_NAMED_REPRESENTATION_TYPE(type, value) \
case REPRESENTATION(k##type): return #type;
@@ -871,15 +862,15 @@ const char* TypeImpl<Config>::BitsetType::Name(bitset bits) {
template <class Config>
void TypeImpl<Config>::BitsetType::Print(OStream& os, // NOLINT
- bitset bits) {
+ int bitset) {
DisallowHeapAllocation no_allocation;
- const char* name = Name(bits);
+ const char* name = Name(bitset);
if (name != NULL) {
os << name;
return;
}
- static const bitset named_bitsets[] = {
+ static const int named_bitsets[] = {
#define BITSET_CONSTANT(type, value) REPRESENTATION(k##type),
REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT)
#undef BITSET_CONSTANT
@@ -891,16 +882,16 @@ void TypeImpl<Config>::BitsetType::Print(OStream& os, // NOLINT
bool is_first = true;
os << "(";
- for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) {
- bitset subset = named_bitsets[i];
- if ((bits & subset) == subset) {
+ for (int i(arraysize(named_bitsets) - 1); bitset != 0 && i >= 0; --i) {
+ int subset = named_bitsets[i];
+ if ((bitset & subset) == subset) {
if (!is_first) os << " | ";
is_first = false;
os << Name(subset);
- bits -= subset;
+ bitset -= subset;
}
}
- DCHECK(bits == 0);
+ DCHECK(bitset == 0);
os << ")";
}
« no previous file with comments | « src/types.h ('k') | src/types-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698