2014-04-01 11:07:09 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-12-19 07:17:45 +00:00
|
|
|
#include <iomanip>
|
2014-12-20 13:17:20 +00:00
|
|
|
|
|
|
|
#include "src/types.h"
|
2014-12-19 07:17:45 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/ostreams.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/types-inl.h"
|
2013-06-05 15:43:53 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-08-07 15:30:16 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// NOTE: If code is marked as being a "shortcut", this means that removing
|
|
|
|
// the code won't affect the semantics of the surrounding function definition.
|
2014-08-07 15:30:16 +00:00
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Range-related helper functions.
|
2014-08-07 15:30:16 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// The result may be invalid (max < min).
|
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::Limits TypeImpl<Config>::Intersect(
|
|
|
|
Limits lhs, Limits rhs) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
Limits result(lhs);
|
2015-01-28 13:55:35 +00:00
|
|
|
if (lhs.min < rhs.min) result.min = rhs.min;
|
|
|
|
if (lhs.max > rhs.max) result.max = rhs.max;
|
2014-09-24 07:33:51 +00:00
|
|
|
return result;
|
2014-08-07 15:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
template <class Config>
|
|
|
|
bool TypeImpl<Config>::IsEmpty(Limits lim) {
|
2015-01-28 13:55:35 +00:00
|
|
|
return lim.min > lim.max;
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::Limits TypeImpl<Config>::Union(Limits lhs,
|
|
|
|
Limits rhs) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-02-12 15:21:17 +00:00
|
|
|
if (IsEmpty(lhs)) return rhs;
|
|
|
|
if (IsEmpty(rhs)) return lhs;
|
2014-09-24 07:33:51 +00:00
|
|
|
Limits result(lhs);
|
2015-01-28 13:55:35 +00:00
|
|
|
if (lhs.min > rhs.min) result.min = rhs.min;
|
|
|
|
if (lhs.max < rhs.max) result.max = rhs.max;
|
2014-09-24 07:33:51 +00:00
|
|
|
return result;
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
bool TypeImpl<Config>::Overlap(
|
|
|
|
typename TypeImpl<Config>::RangeType* lhs,
|
|
|
|
typename TypeImpl<Config>::RangeType* rhs) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-09-24 07:33:51 +00:00
|
|
|
typename TypeImpl<Config>::Limits lim = Intersect(Limits(lhs), Limits(rhs));
|
2015-01-28 13:55:35 +00:00
|
|
|
return lim.min <= lim.max;
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
bool TypeImpl<Config>::Contains(
|
|
|
|
typename TypeImpl<Config>::RangeType* lhs,
|
|
|
|
typename TypeImpl<Config>::RangeType* rhs) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-02-12 15:21:17 +00:00
|
|
|
return lhs->Min() <= rhs->Min() && rhs->Max() <= lhs->Max();
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
bool TypeImpl<Config>::Contains(typename TypeImpl<Config>::RangeType* lhs,
|
|
|
|
typename TypeImpl<Config>::ConstantType* rhs) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-01-28 13:55:35 +00:00
|
|
|
return IsInteger(*rhs->Value()) &&
|
|
|
|
lhs->Min() <= rhs->Value()->Number() &&
|
|
|
|
rhs->Value()->Number() <= lhs->Max();
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
bool TypeImpl<Config>::Contains(
|
|
|
|
typename TypeImpl<Config>::RangeType* range, i::Object* val) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-01-28 08:42:15 +00:00
|
|
|
return IsInteger(val) &&
|
2015-01-28 13:55:35 +00:00
|
|
|
range->Min() <= val->Number() && val->Number() <= range->Max();
|
2014-05-26 13:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Min and Max computation.
|
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
double TypeImpl<Config>::Min() {
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(this->SemanticIs(Number()));
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
|
|
|
|
if (this->IsUnion()) {
|
2014-12-20 13:17:20 +00:00
|
|
|
double min = +V8_INFINITY;
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
min = std::min(min, this->AsUnion()->Get(i)->Min());
|
|
|
|
}
|
|
|
|
return min;
|
|
|
|
}
|
2015-01-28 13:55:35 +00:00
|
|
|
if (this->IsRange()) return this->AsRange()->Min();
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsConstant()) return this->AsConstant()->Value()->Number();
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
2014-08-05 13:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 15:30:16 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
double TypeImpl<Config>::Max() {
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(this->SemanticIs(Number()));
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
|
|
|
|
if (this->IsUnion()) {
|
2014-12-20 13:17:20 +00:00
|
|
|
double max = -V8_INFINITY;
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
max = std::max(max, this->AsUnion()->Get(i)->Max());
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
2015-01-28 13:55:35 +00:00
|
|
|
if (this->IsRange()) return this->AsRange()->Max();
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsConstant()) return this->AsConstant()->Value()->Number();
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
2014-08-07 15:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Glb and lub computation.
|
|
|
|
|
|
|
|
|
|
|
|
// The largest bitset subsumed by this type.
|
2014-08-05 13:19:32 +00:00
|
|
|
template<class Config>
|
2014-09-16 12:58:43 +00:00
|
|
|
typename TypeImpl<Config>::bitset
|
2014-09-24 07:33:51 +00:00
|
|
|
TypeImpl<Config>::BitsetType::Glb(TypeImpl* type) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-02-12 15:21:17 +00:00
|
|
|
// Fast case.
|
2014-09-24 07:33:51 +00:00
|
|
|
if (type->IsBitset()) {
|
|
|
|
return type->AsBitset();
|
|
|
|
} else if (type->IsUnion()) {
|
|
|
|
SLOW_DCHECK(type->AsUnion()->Wellformed());
|
2015-01-28 08:42:15 +00:00
|
|
|
return type->AsUnion()->Get(0)->BitsetGlb() |
|
2015-02-12 15:21:17 +00:00
|
|
|
SEMANTIC(type->AsUnion()->Get(1)->BitsetGlb()); // Shortcut.
|
2015-01-28 08:42:15 +00:00
|
|
|
} else if (type->IsRange()) {
|
2015-01-28 13:55:35 +00:00
|
|
|
bitset glb = SEMANTIC(
|
|
|
|
BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max()));
|
2015-02-12 15:21:17 +00:00
|
|
|
return glb | REPRESENTATION(type->BitsetLub());
|
2015-01-22 05:33:23 +00:00
|
|
|
} else {
|
2015-02-12 15:21:17 +00:00
|
|
|
return type->Representation();
|
2014-05-26 13:10:52 +00:00
|
|
|
}
|
2014-08-05 13:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// The smallest bitset subsuming this type.
|
2014-08-05 13:19:32 +00:00
|
|
|
template<class Config>
|
2014-09-16 12:58:43 +00:00
|
|
|
typename TypeImpl<Config>::bitset
|
2014-09-24 07:33:51 +00:00
|
|
|
TypeImpl<Config>::BitsetType::Lub(TypeImpl* type) {
|
2014-08-05 13:19:32 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-09-24 07:33:51 +00:00
|
|
|
if (type->IsBitset()) return type->AsBitset();
|
|
|
|
if (type->IsUnion()) {
|
2015-02-12 15:21:17 +00:00
|
|
|
// Take the representation from the first element, which is always
|
|
|
|
// a bitset.
|
|
|
|
int bitset = type->AsUnion()->Get(0)->BitsetLub();
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
// Other elements only contribute their semantic part.
|
|
|
|
bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub());
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
return bitset;
|
2014-05-26 13:10:52 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
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)) :
|
|
|
|
type->AsClass()->Bound(NULL)->AsBitset();
|
|
|
|
}
|
|
|
|
if (type->IsConstant()) return type->AsConstant()->Bound()->AsBitset();
|
2015-01-28 13:55:35 +00:00
|
|
|
if (type->IsRange()) return type->AsRange()->Bound();
|
2014-12-11 13:47:40 +00:00
|
|
|
if (type->IsContext()) return kInternal & kTaggedPointer;
|
2014-09-24 07:33:51 +00:00
|
|
|
if (type->IsArray()) return kArray;
|
2014-12-11 13:47:40 +00:00
|
|
|
if (type->IsFunction()) return kOtherObject; // TODO(rossberg): kFunction
|
2014-09-24 07:33:51 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return kNone;
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-16 12:58:43 +00:00
|
|
|
typename TypeImpl<Config>::bitset
|
|
|
|
TypeImpl<Config>::BitsetType::Lub(i::Map* map) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2013-11-15 15:14:09 +00:00
|
|
|
switch (map->instance_type()) {
|
|
|
|
case STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case ONE_BYTE_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case CONS_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case CONS_ONE_BYTE_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case SLICED_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case SLICED_ONE_BYTE_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case EXTERNAL_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case EXTERNAL_ONE_BYTE_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
case SHORT_EXTERNAL_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
2014-09-24 07:33:51 +00:00
|
|
|
return kOtherString;
|
2013-11-15 15:14:09 +00:00
|
|
|
case INTERNALIZED_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case ONE_BYTE_INTERNALIZED_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case EXTERNAL_INTERNALIZED_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
case SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE:
|
2014-09-10 12:38:12 +00:00
|
|
|
case SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
2014-09-24 07:33:51 +00:00
|
|
|
return kInternalizedString;
|
2013-11-15 15:14:09 +00:00
|
|
|
case SYMBOL_TYPE:
|
|
|
|
return kSymbol;
|
2014-04-07 09:41:13 +00:00
|
|
|
case ODDBALL_TYPE: {
|
|
|
|
Heap* heap = map->GetHeap();
|
|
|
|
if (map == heap->undefined_map()) return kUndefined;
|
|
|
|
if (map == heap->null_map()) return kNull;
|
|
|
|
if (map == heap->boolean_map()) return kBoolean;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map == heap->the_hole_map() ||
|
2014-07-10 12:37:08 +00:00
|
|
|
map == heap->uninitialized_map() ||
|
2014-04-10 11:51:03 +00:00
|
|
|
map == heap->no_interceptor_result_sentinel_map() ||
|
2014-04-07 09:41:13 +00:00
|
|
|
map == heap->termination_exception_map() ||
|
|
|
|
map == heap->arguments_marker_map());
|
2014-12-11 13:47:40 +00:00
|
|
|
return kInternal & kTaggedPointer;
|
2014-04-07 09:41:13 +00:00
|
|
|
}
|
2013-11-15 15:14:09 +00:00
|
|
|
case HEAP_NUMBER_TYPE:
|
2014-12-11 13:47:40 +00:00
|
|
|
return kNumber & kTaggedPointer;
|
2013-11-15 15:14:09 +00:00
|
|
|
case JS_VALUE_TYPE:
|
|
|
|
case JS_DATE_TYPE:
|
|
|
|
case JS_OBJECT_TYPE:
|
|
|
|
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
|
|
|
|
case JS_GENERATOR_OBJECT_TYPE:
|
|
|
|
case JS_MODULE_TYPE:
|
|
|
|
case JS_GLOBAL_OBJECT_TYPE:
|
|
|
|
case JS_BUILTINS_OBJECT_TYPE:
|
|
|
|
case JS_GLOBAL_PROXY_TYPE:
|
|
|
|
case JS_ARRAY_BUFFER_TYPE:
|
|
|
|
case JS_TYPED_ARRAY_TYPE:
|
|
|
|
case JS_DATA_VIEW_TYPE:
|
|
|
|
case JS_SET_TYPE:
|
|
|
|
case JS_MAP_TYPE:
|
2014-04-22 18:14:46 +00:00
|
|
|
case JS_SET_ITERATOR_TYPE:
|
|
|
|
case JS_MAP_ITERATOR_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case JS_WEAK_MAP_TYPE:
|
|
|
|
case JS_WEAK_SET_TYPE:
|
|
|
|
if (map->is_undetectable()) return kUndetectable;
|
|
|
|
return kOtherObject;
|
|
|
|
case JS_ARRAY_TYPE:
|
|
|
|
return kArray;
|
|
|
|
case JS_FUNCTION_TYPE:
|
2014-12-11 13:47:40 +00:00
|
|
|
return kOtherObject; // TODO(rossberg): there should be a Function type.
|
2013-11-15 15:14:09 +00:00
|
|
|
case JS_REGEXP_TYPE:
|
2014-12-11 13:47:40 +00:00
|
|
|
return kOtherObject; // TODO(rossberg): there should be a RegExp type.
|
2013-11-15 15:14:09 +00:00
|
|
|
case JS_PROXY_TYPE:
|
|
|
|
case JS_FUNCTION_PROXY_TYPE:
|
|
|
|
return kProxy;
|
|
|
|
case MAP_TYPE:
|
|
|
|
// When compiling stub templates, the meta map is used as a place holder
|
|
|
|
// for the actual map with which the template is later instantiated.
|
|
|
|
// We treat it as a kind of type variable whose upper bound is Any.
|
|
|
|
// TODO(rossberg): for caching of CompareNilIC stubs to work correctly,
|
|
|
|
// we must exclude Undetectable here. This makes no sense, really,
|
|
|
|
// because it means that the template isn't actually parametric.
|
|
|
|
// Also, it doesn't apply elsewhere. 8-(
|
|
|
|
// We ought to find a cleaner solution for compiling stubs parameterised
|
|
|
|
// over type or class variables, esp ones with bounds...
|
|
|
|
return kDetectable;
|
|
|
|
case DECLARED_ACCESSOR_INFO_TYPE:
|
|
|
|
case EXECUTABLE_ACCESSOR_INFO_TYPE:
|
2014-05-26 13:10:52 +00:00
|
|
|
case SHARED_FUNCTION_INFO_TYPE:
|
2013-11-15 15:14:09 +00:00
|
|
|
case ACCESSOR_PAIR_TYPE:
|
|
|
|
case FIXED_ARRAY_TYPE:
|
2014-10-15 11:38:04 +00:00
|
|
|
case BYTE_ARRAY_TYPE:
|
2014-04-24 07:16:10 +00:00
|
|
|
case FOREIGN_TYPE:
|
2015-01-16 12:38:13 +00:00
|
|
|
case SCRIPT_TYPE:
|
2014-07-30 13:54:45 +00:00
|
|
|
case CODE_TYPE:
|
2014-12-11 13:47:40 +00:00
|
|
|
return kInternal & kTaggedPointer;
|
2013-11-15 15:14:09 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return kNone;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::bitset
|
|
|
|
TypeImpl<Config>::BitsetType::Lub(i::Object* value) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
if (value->IsNumber()) {
|
2014-12-11 13:47:40 +00:00
|
|
|
return Lub(value->Number()) &
|
|
|
|
(value->IsSmi() ? kTaggedSigned : kTaggedPointer);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
return Lub(i::HeapObject::cast(value)->map());
|
|
|
|
}
|
|
|
|
|
2013-11-15 15:14:09 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
typename TypeImpl<Config>::bitset
|
|
|
|
TypeImpl<Config>::BitsetType::Lub(double value) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-09-24 07:33:51 +00:00
|
|
|
if (i::IsMinusZero(value)) return kMinusZero;
|
|
|
|
if (std::isnan(value)) return kNaN;
|
2014-09-30 10:34:54 +00:00
|
|
|
if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value);
|
2014-12-11 17:50:02 +00:00
|
|
|
return kPlainNumber;
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
// Minimum values of regular numeric bitsets.
|
2014-12-11 17:50:02 +00:00
|
|
|
template <class Config>
|
2015-01-28 08:42:15 +00:00
|
|
|
const typename TypeImpl<Config>::BitsetType::Boundary
|
|
|
|
TypeImpl<Config>::BitsetType::BoundariesArray[] = {
|
|
|
|
{kPlainNumber, -V8_INFINITY},
|
|
|
|
{kNegative32, kMinInt},
|
|
|
|
{kNegative31, -0x40000000},
|
|
|
|
{kUnsigned30, 0},
|
|
|
|
{kUnsigned31, 0x40000000},
|
|
|
|
{kUnsigned32, 0x80000000},
|
|
|
|
{kPlainNumber, static_cast<double>(kMaxUInt32) + 1}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-11 17:50:02 +00:00
|
|
|
template <class Config>
|
2015-01-28 08:42:15 +00:00
|
|
|
const typename TypeImpl<Config>::BitsetType::Boundary*
|
|
|
|
TypeImpl<Config>::BitsetType::Boundaries() {
|
|
|
|
return BoundariesArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
size_t TypeImpl<Config>::BitsetType::BoundariesSize() {
|
|
|
|
// Windows doesn't like arraysize here.
|
|
|
|
// return arraysize(BoundariesArray);
|
|
|
|
return 7;
|
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::bitset
|
2014-09-30 10:34:54 +00:00
|
|
|
TypeImpl<Config>::BitsetType::Lub(double min, double max) {
|
2014-09-24 07:33:51 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
int lub = kNone;
|
2015-01-28 08:42:15 +00:00
|
|
|
const Boundary* mins = Boundaries();
|
2014-09-24 07:33:51 +00:00
|
|
|
|
2014-12-11 17:50:02 +00:00
|
|
|
// Make sure the min-max range touches 0, so we are guaranteed no holes
|
|
|
|
// in unions of valid bitsets.
|
|
|
|
if (max < -1) max = -1;
|
|
|
|
if (min > 0) min = 0;
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
for (size_t i = 1; i < BoundariesSize(); ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
if (min < mins[i].min) {
|
|
|
|
lub |= mins[i-1].bits;
|
|
|
|
if (max < mins[i].min) return lub;
|
|
|
|
}
|
|
|
|
}
|
2015-01-28 08:42:15 +00:00
|
|
|
return lub |= mins[BoundariesSize() - 1].bits;
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::NumberBits(
|
|
|
|
bitset bits) {
|
|
|
|
return SEMANTIC(bits & kPlainNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
void TypeImpl<Config>::BitsetType::CheckNumberBits(bitset bits) {
|
|
|
|
// Check that the bitset does not contain any holes in number ranges.
|
|
|
|
bitset number_bits = NumberBits(bits);
|
|
|
|
if (number_bits != 0) {
|
|
|
|
bitset lub = SEMANTIC(Lub(Min(number_bits), Max(number_bits)));
|
|
|
|
CHECK(lub == number_bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::Glb(
|
|
|
|
double min, double max) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
int glb = kNone;
|
|
|
|
const Boundary* mins = Boundaries();
|
|
|
|
|
|
|
|
// If the range does not touch 0, the bound is empty.
|
|
|
|
if (max < -1 || min > 0) return glb;
|
|
|
|
|
|
|
|
for (size_t i = 1; i + 1 < BoundariesSize(); ++i) {
|
|
|
|
if (min <= mins[i].min) {
|
|
|
|
if (max + 1 < mins[i + 1].min) break;
|
|
|
|
glb |= mins[i].bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// OtherNumber also contains float numbers, so it can never be
|
|
|
|
// in the greatest lower bound. (There is also the small trouble
|
|
|
|
// of kOtherNumber having a range hole, which we can conveniently
|
|
|
|
// ignore here.)
|
|
|
|
return glb & ~(SEMANTIC(kOtherNumber));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
double TypeImpl<Config>::BitsetType::Min(bitset bits) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(Is(SEMANTIC(bits), kNumber));
|
2015-01-28 08:42:15 +00:00
|
|
|
const Boundary* mins = Boundaries();
|
2014-09-24 07:33:51 +00:00
|
|
|
bool mz = SEMANTIC(bits & kMinusZero);
|
2015-01-28 08:42:15 +00:00
|
|
|
for (size_t i = 0; i < BoundariesSize(); ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
if (Is(SEMANTIC(mins[i].bits), bits)) {
|
|
|
|
return mz ? std::min(0.0, mins[i].min) : mins[i].min;
|
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (mz) return 0;
|
2015-01-21 14:38:49 +00:00
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
template<class Config>
|
|
|
|
double TypeImpl<Config>::BitsetType::Max(bitset bits) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(Is(SEMANTIC(bits), kNumber));
|
2015-01-28 08:42:15 +00:00
|
|
|
const Boundary* mins = Boundaries();
|
2014-10-15 08:21:46 +00:00
|
|
|
bool mz = SEMANTIC(bits & kMinusZero);
|
2015-01-28 08:42:15 +00:00
|
|
|
if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].bits), bits)) {
|
2014-12-20 13:17:20 +00:00
|
|
|
return +V8_INFINITY;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2015-01-28 08:42:15 +00:00
|
|
|
for (size_t i = BoundariesSize() - 1; i-- > 0;) {
|
2014-09-24 07:33:51 +00:00
|
|
|
if (Is(SEMANTIC(mins[i].bits), bits)) {
|
|
|
|
return mz ?
|
|
|
|
std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1;
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (mz) return 0;
|
2015-01-21 14:38:49 +00:00
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Predicates.
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::SimplyEquals(TypeImpl* that) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
if (this->IsClass()) {
|
|
|
|
return that->IsClass()
|
|
|
|
&& *this->AsClass()->Map() == *that->AsClass()->Map();
|
|
|
|
}
|
|
|
|
if (this->IsConstant()) {
|
|
|
|
return that->IsConstant()
|
|
|
|
&& *this->AsConstant()->Value() == *that->AsConstant()->Value();
|
2014-08-07 15:30:16 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsContext()) {
|
|
|
|
return that->IsContext()
|
2014-05-26 13:10:52 +00:00
|
|
|
&& this->AsContext()->Outer()->Equals(that->AsContext()->Outer());
|
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsArray()) {
|
|
|
|
return that->IsArray()
|
2014-04-16 16:16:37 +00:00
|
|
|
&& this->AsArray()->Element()->Equals(that->AsArray()->Element());
|
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsFunction()) {
|
|
|
|
if (!that->IsFunction()) return false;
|
2014-04-16 16:16:37 +00:00
|
|
|
FunctionType* this_fun = this->AsFunction();
|
|
|
|
FunctionType* that_fun = that->AsFunction();
|
|
|
|
if (this_fun->Arity() != that_fun->Arity() ||
|
|
|
|
!this_fun->Result()->Equals(that_fun->Result()) ||
|
2014-09-24 07:33:51 +00:00
|
|
|
!this_fun->Receiver()->Equals(that_fun->Receiver())) {
|
2014-04-16 16:16:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this_fun->Arity(); i < n; ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false;
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
|
|
|
return true;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::bitset TypeImpl<Config>::Representation() {
|
|
|
|
return REPRESENTATION(this->BitsetLub());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Check if [this] <= [that].
|
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
// Fast bitset cases
|
2014-09-24 07:33:51 +00:00
|
|
|
if (that->IsBitset()) {
|
|
|
|
return BitsetType::Is(this->BitsetLub(), that->AsBitset());
|
|
|
|
}
|
2015-02-12 15:21:17 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsBitset()) {
|
|
|
|
return BitsetType::Is(this->AsBitset(), that->BitsetGlb());
|
|
|
|
}
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
// Check the representations.
|
|
|
|
if (!BitsetType::Is(Representation(), that->Representation())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the semantic part.
|
|
|
|
return SemanticIs(that);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check if SEMANTIC([this]) <= SEMANTIC([that]). The result of the method
|
|
|
|
// should be independent of the representation axis of the types.
|
|
|
|
template <class Config>
|
|
|
|
bool TypeImpl<Config>::SemanticIs(TypeImpl* that) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
|
|
|
|
if (this == that) return true;
|
|
|
|
|
|
|
|
if (that->IsBitset()) {
|
|
|
|
return BitsetType::Is(SEMANTIC(this->BitsetLub()), that->AsBitset());
|
|
|
|
}
|
|
|
|
if (this->IsBitset()) {
|
|
|
|
return BitsetType::Is(SEMANTIC(this->AsBitset()), that->BitsetGlb());
|
|
|
|
}
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (!this->AsUnion()->Get(i)->SemanticIs(that)) return false;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn)
|
|
|
|
if (that->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (this->SemanticIs(that->AsUnion()->Get(i)->unhandle())) return true;
|
2014-09-24 07:33:51 +00:00
|
|
|
if (i > 1 && this->IsRange()) return false; // Shortcut.
|
|
|
|
}
|
|
|
|
return false;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
if (that->IsRange()) {
|
2015-01-28 08:42:15 +00:00
|
|
|
return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) ||
|
|
|
|
(this->IsConstant() &&
|
|
|
|
Contains(that->AsRange(), this->AsConstant()));
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
if (this->IsRange()) return false;
|
2014-10-15 11:38:04 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
return this->SimplyEquals(that);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-04-01 13:11:12 +00:00
|
|
|
bool TypeImpl<Config>::NowIs(TypeImpl* that) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
|
2014-04-14 15:35:36 +00:00
|
|
|
// TODO(rossberg): this is incorrect for
|
|
|
|
// Union(Constant(V), T)->NowIs(Class(M))
|
|
|
|
// but fuzzing does not cover that!
|
2014-04-10 08:04:50 +00:00
|
|
|
if (this->IsConstant()) {
|
2014-04-16 16:16:37 +00:00
|
|
|
i::Object* object = *this->AsConstant()->Value();
|
2014-04-10 08:04:50 +00:00
|
|
|
if (object->IsHeapObject()) {
|
|
|
|
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;
|
|
|
|
}
|
2014-04-09 11:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-10 08:04:50 +00:00
|
|
|
return this->Is(that);
|
2013-11-22 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Check if [this] contains only (currently) stable classes.
|
2014-04-17 08:22:22 +00:00
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::NowStable() {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) {
|
|
|
|
if (!it.Current()->is_stable()) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Check if [this] and [that] overlap.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::Maybe(TypeImpl* that) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
// Take care of the representation part (and also approximate
|
|
|
|
// the semantic part).
|
|
|
|
if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return SemanticMaybe(that);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
bool TypeImpl<Config>::SemanticMaybe(TypeImpl* that) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (this->AsUnion()->Get(i)->SemanticMaybe(that)) return true;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (that->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (this->SemanticMaybe(that->AsUnion()->Get(i)->unhandle())) return true;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
if (!BitsetType::SemanticIsInhabited(this->BitsetLub() & that->BitsetLub()))
|
2014-09-24 07:33:51 +00:00
|
|
|
return false;
|
2015-01-28 08:42:15 +00:00
|
|
|
|
|
|
|
if (this->IsBitset() && that->IsBitset()) return true;
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
if (this->IsClass() != that->IsClass()) return true;
|
|
|
|
|
|
|
|
if (this->IsRange()) {
|
|
|
|
if (that->IsConstant()) {
|
2015-01-28 08:42:15 +00:00
|
|
|
return Contains(this->AsRange(), that->AsConstant());
|
|
|
|
}
|
|
|
|
if (that->IsRange()) {
|
|
|
|
return Overlap(this->AsRange(), that->AsRange());
|
|
|
|
}
|
|
|
|
if (that->IsBitset()) {
|
|
|
|
bitset number_bits = BitsetType::NumberBits(that->AsBitset());
|
|
|
|
if (number_bits == BitsetType::kNone) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
double min = std::max(BitsetType::Min(number_bits), this->Min());
|
|
|
|
double max = std::min(BitsetType::Max(number_bits), this->Max());
|
|
|
|
return min <= max;
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (that->IsRange()) {
|
2015-02-12 15:21:17 +00:00
|
|
|
return that->SemanticMaybe(this); // This case is handled above.
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
if (this->IsBitset() || that->IsBitset()) return true;
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
return this->SimplyEquals(that);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Return the range in [this], or [NULL].
|
2014-04-01 13:11:12 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
typename TypeImpl<Config>::RangeType* TypeImpl<Config>::GetRange() {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-09-24 07:33:51 +00:00
|
|
|
if (this->IsRange()) return this->AsRange();
|
|
|
|
if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) {
|
|
|
|
return this->AsUnion()->Get(1)->AsRange();
|
2014-08-07 15:30:16 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::Contains(i::Object* value) {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-04-09 11:12:15 +00:00
|
|
|
for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) {
|
|
|
|
if (*it.Current() == value) return true;
|
2014-04-01 13:11:12 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (IsInteger(value)) {
|
|
|
|
RangeType* range = this->GetRange();
|
|
|
|
if (range != NULL && Contains(range, value)) return true;
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
return BitsetType::New(BitsetType::Lub(value))->Is(this);
|
2014-04-01 13:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-05-27 13:52:31 +00:00
|
|
|
bool TypeImpl<Config>::UnionType::Wellformed() {
|
2014-09-24 07:33:51 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
// This checks the invariants of the union representation:
|
|
|
|
// 1. There are at least two elements.
|
2015-02-12 15:21:17 +00:00
|
|
|
// 2. The first element is a bitset, no other element is a bitset.
|
|
|
|
// 3. At most one element is a range, and it must be the second one.
|
2014-09-24 07:33:51 +00:00
|
|
|
// 4. No element is itself a union.
|
2015-02-12 15:21:17 +00:00
|
|
|
// 5. No element (except the bitset) is a subtype of any other.
|
2015-01-28 08:42:15 +00:00
|
|
|
// 6. If there is a range, then the bitset type does not contain
|
|
|
|
// plain number bits.
|
2014-09-24 07:33:51 +00:00
|
|
|
DCHECK(this->Length() >= 2); // (1)
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(this->Get(0)->IsBitset()); // (2a)
|
2015-01-28 08:42:15 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
for (int i = 0; i < this->Length(); ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2b)
|
2015-01-28 08:42:15 +00:00
|
|
|
if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3)
|
|
|
|
DCHECK(!this->Get(i)->IsUnion()); // (4)
|
2014-05-27 13:52:31 +00:00
|
|
|
for (int j = 0; j < this->Length(); ++j) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (i != j && i != 0)
|
|
|
|
DCHECK(!this->Get(i)->SemanticIs(this->Get(j)->unhandle())); // (5)
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(!this->Get(1)->IsRange() ||
|
|
|
|
(BitsetType::NumberBits(this->Get(0)->AsBitset()) ==
|
|
|
|
BitsetType::kNone)); // (6)
|
2014-05-27 13:52:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Union and intersection
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
static bool AddIsSafe(int x, int y) {
|
|
|
|
return x >= 0 ?
|
|
|
|
y <= std::numeric_limits<int>::max() - x :
|
|
|
|
y >= std::numeric_limits<int>::min() - x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect(
|
|
|
|
TypeHandle type1, TypeHandle type2, Region* region) {
|
|
|
|
|
|
|
|
// Fast case: bit sets.
|
|
|
|
if (type1->IsBitset() && type2->IsBitset()) {
|
2015-02-12 15:21:17 +00:00
|
|
|
return BitsetType::New(type1->AsBitset() & type2->AsBitset(), region);
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
// Fast case: top or bottom types.
|
|
|
|
if (type1->IsNone() || type2->IsAny()) return type1; // Shortcut.
|
|
|
|
if (type2->IsNone() || type1->IsAny()) return type2; // Shortcut.
|
|
|
|
|
|
|
|
// Semi-fast case.
|
|
|
|
if (type1->Is(type2)) return type1;
|
|
|
|
if (type2->Is(type1)) return type2;
|
|
|
|
|
|
|
|
// Slow case: create union.
|
2015-02-12 15:21:17 +00:00
|
|
|
|
|
|
|
// Figure out the representation of the result first.
|
|
|
|
// The rest of the method should not change this representation and
|
|
|
|
// it should not make any decisions based on representations (i.e.,
|
|
|
|
// it should only use the semantic part of types).
|
|
|
|
const bitset representation =
|
|
|
|
type1->Representation() & type2->Representation();
|
|
|
|
|
|
|
|
// Semantic subtyping check - this is needed for consistency with the
|
|
|
|
// semi-fast case above - we should behave the same way regardless of
|
|
|
|
// representations. Intersection with a universal bitset should only update
|
|
|
|
// the representations.
|
|
|
|
if (type1->SemanticIs(type2->unhandle())) {
|
|
|
|
type2 = Any(region);
|
|
|
|
} else if (type2->SemanticIs(type1->unhandle())) {
|
|
|
|
type1 = Any(region);
|
|
|
|
}
|
|
|
|
|
|
|
|
bitset bits =
|
|
|
|
SEMANTIC(type1->BitsetGlb() & type2->BitsetGlb()) | representation;
|
2014-09-24 07:33:51 +00:00
|
|
|
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
|
|
|
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
|
|
|
if (!AddIsSafe(size1, size2)) return Any(region);
|
|
|
|
int size = size1 + size2;
|
|
|
|
if (!AddIsSafe(size, 2)) return Any(region);
|
|
|
|
size += 2;
|
|
|
|
UnionHandle result = UnionType::New(size, region);
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
// Deal with bitsets.
|
|
|
|
result->Set(size++, BitsetType::New(bits, region));
|
2015-01-28 08:42:15 +00:00
|
|
|
|
|
|
|
Limits lims = Limits::Empty(region);
|
|
|
|
size = IntersectAux(type1, type2, result, size, &lims, region);
|
|
|
|
|
|
|
|
// If the range is not empty, then insert it into the union and
|
|
|
|
// remove the number bits from the bitset.
|
|
|
|
if (!IsEmpty(lims)) {
|
2015-02-12 15:21:17 +00:00
|
|
|
size = UpdateRange(RangeType::New(lims, representation, region), result,
|
|
|
|
size, region);
|
2015-01-28 08:42:15 +00:00
|
|
|
|
|
|
|
// Remove the number bits.
|
|
|
|
bitset number_bits = BitsetType::NumberBits(bits);
|
|
|
|
bits &= ~number_bits;
|
|
|
|
result->Set(0, BitsetType::New(bits, region));
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
return NormalizeUnion(result, size);
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
int TypeImpl<Config>::UpdateRange(
|
|
|
|
RangeHandle range, UnionHandle result, int size, Region* region) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (size == 1) {
|
|
|
|
result->Set(size++, range);
|
|
|
|
} else {
|
|
|
|
// Make space for the range.
|
|
|
|
result->Set(size++, result->Get(1));
|
|
|
|
result->Set(1, range);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any components that just got subsumed.
|
|
|
|
for (int i = 2; i < size; ) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (result->Get(i)->SemanticIs(range->unhandle())) {
|
2014-09-24 07:33:51 +00:00
|
|
|
result->Set(i, result->Get(--size));
|
|
|
|
} else {
|
|
|
|
++i;
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-05-27 13:52:31 +00:00
|
|
|
return size;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::Limits TypeImpl<Config>::ToLimits(bitset bits,
|
|
|
|
Region* region) {
|
|
|
|
bitset number_bits = BitsetType::NumberBits(bits);
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
if (number_bits == BitsetType::kNone) {
|
2015-01-28 08:42:15 +00:00
|
|
|
return Limits::Empty(region);
|
|
|
|
}
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
return Limits(BitsetType::Min(number_bits), BitsetType::Max(number_bits));
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::Limits TypeImpl<Config>::IntersectRangeAndBitset(
|
|
|
|
TypeHandle range, TypeHandle bitset, Region* region) {
|
|
|
|
Limits range_lims(range->AsRange());
|
|
|
|
Limits bitset_lims = ToLimits(bitset->AsBitset(), region);
|
|
|
|
return Intersect(range_lims, bitset_lims);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Config>
|
|
|
|
int TypeImpl<Config>::IntersectAux(TypeHandle lhs, TypeHandle rhs,
|
|
|
|
UnionHandle result, int size, Limits* lims,
|
|
|
|
Region* region) {
|
2014-09-24 07:33:51 +00:00
|
|
|
if (lhs->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) {
|
2015-01-28 08:42:15 +00:00
|
|
|
size =
|
|
|
|
IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, lims, region);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
if (rhs->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) {
|
2015-01-28 08:42:15 +00:00
|
|
|
size =
|
|
|
|
IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, region);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
|
|
|
return size;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
if (!BitsetType::SemanticIsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) {
|
2014-09-24 07:33:51 +00:00
|
|
|
return size;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
if (lhs->IsRange()) {
|
2015-01-28 08:42:15 +00:00
|
|
|
if (rhs->IsBitset()) {
|
|
|
|
Limits lim = IntersectRangeAndBitset(lhs, rhs, region);
|
|
|
|
|
|
|
|
if (!IsEmpty(lim)) {
|
|
|
|
*lims = Union(lim, *lims);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
if (rhs->IsClass()) {
|
|
|
|
*lims = Union(Limits(lhs->AsRange()), *lims);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
2015-01-28 08:42:15 +00:00
|
|
|
if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) {
|
2014-09-24 07:33:51 +00:00
|
|
|
return AddToUnion(rhs, result, size, region);
|
|
|
|
}
|
2015-01-28 08:42:15 +00:00
|
|
|
if (rhs->IsRange()) {
|
|
|
|
Limits lim = Intersect(Limits(lhs->AsRange()), Limits(rhs->AsRange()));
|
|
|
|
if (!IsEmpty(lim)) {
|
|
|
|
*lims = Union(lim, *lims);
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
return size;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (rhs->IsRange()) {
|
2015-01-28 08:42:15 +00:00
|
|
|
// This case is handled symmetrically above.
|
|
|
|
return IntersectAux(rhs, lhs, result, size, lims, region);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (lhs->IsBitset() || rhs->IsBitset()) {
|
|
|
|
return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, region);
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (lhs->IsClass() != rhs->IsClass()) {
|
|
|
|
return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, region);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
if (lhs->SimplyEquals(rhs->unhandle())) {
|
|
|
|
return AddToUnion(lhs, result, size, region);
|
|
|
|
}
|
|
|
|
return size;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
// Make sure that we produce a well-formed range and bitset:
|
|
|
|
// If the range is non-empty, the number bits in the bitset should be
|
|
|
|
// clear. Moreover, if we have a canonical range (such as Signed32(),
|
|
|
|
// we want to produce a bitset rather than a range.
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeRangeAndBitset(
|
|
|
|
RangeHandle range, bitset* bits, Region* region) {
|
|
|
|
// Fast path: If the bitset does not mention numbers, we can just keep the
|
|
|
|
// range.
|
|
|
|
bitset number_bits = BitsetType::NumberBits(*bits);
|
|
|
|
if (number_bits == 0) {
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the range is contained within the bitset, return an empty range
|
|
|
|
// (but make sure we take the representation).
|
2015-02-12 15:21:17 +00:00
|
|
|
bitset range_lub = SEMANTIC(range->BitsetLub());
|
2015-01-28 08:42:15 +00:00
|
|
|
if (BitsetType::Is(BitsetType::NumberBits(range_lub), *bits)) {
|
|
|
|
return None(region);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow path: reconcile the bitset range and the range.
|
|
|
|
double bitset_min = BitsetType::Min(number_bits);
|
|
|
|
double bitset_max = BitsetType::Max(number_bits);
|
|
|
|
|
2015-01-28 13:55:35 +00:00
|
|
|
double range_min = range->Min();
|
|
|
|
double range_max = range->Max();
|
2015-01-28 08:42:15 +00:00
|
|
|
|
|
|
|
// Remove the number bits from the bitset, they would just confuse us now.
|
|
|
|
*bits &= ~number_bits;
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
if (range_min <= bitset_min && range_max >= bitset_max) {
|
2015-01-28 08:42:15 +00:00
|
|
|
// Bitset is contained within the range, just return the range.
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitset_min < range_min) {
|
2015-01-28 13:55:35 +00:00
|
|
|
range_min = bitset_min;
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
|
|
|
if (bitset_max > range_max) {
|
2015-01-28 13:55:35 +00:00
|
|
|
range_max = bitset_max;
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
2015-01-28 13:55:35 +00:00
|
|
|
return RangeType::New(range_min, range_max,
|
2015-02-12 15:21:17 +00:00
|
|
|
BitsetType::New(BitsetType::kNone, region), region);
|
2015-01-28 08:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-24 07:33:51 +00:00
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union(
|
2014-01-10 12:19:01 +00:00
|
|
|
TypeHandle type1, TypeHandle type2, Region* region) {
|
2013-06-20 09:10:10 +00:00
|
|
|
// Fast case: bit sets.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (type1->IsBitset() && type2->IsBitset()) {
|
2014-09-24 07:33:51 +00:00
|
|
|
return BitsetType::New(type1->AsBitset() | type2->AsBitset(), region);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
// Fast case: top or bottom types.
|
2014-09-24 07:33:51 +00:00
|
|
|
if (type1->IsAny() || type2->IsNone()) return type1;
|
|
|
|
if (type2->IsAny() || type1->IsNone()) return type2;
|
2013-06-21 11:10:06 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Semi-fast case.
|
|
|
|
if (type1->Is(type2)) return type2;
|
|
|
|
if (type2->Is(type1)) return type1;
|
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
// Figure out the representation of the result.
|
|
|
|
// The rest of the method should not change this representation and
|
|
|
|
// it should make any decisions based on representations (i.e.,
|
|
|
|
// it should only use the semantic part of types).
|
|
|
|
const bitset representation =
|
|
|
|
type1->Representation() | type2->Representation();
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Slow case: create union.
|
|
|
|
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
|
|
|
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
|
|
|
if (!AddIsSafe(size1, size2)) return Any(region);
|
|
|
|
int size = size1 + size2;
|
|
|
|
if (!AddIsSafe(size, 2)) return Any(region);
|
|
|
|
size += 2;
|
|
|
|
UnionHandle result = UnionType::New(size, region);
|
|
|
|
size = 0;
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
// Compute the new bitset.
|
2015-02-12 15:21:17 +00:00
|
|
|
bitset new_bitset = SEMANTIC(type1->BitsetGlb() | type2->BitsetGlb());
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
// Deal with ranges.
|
|
|
|
TypeHandle range = None(region);
|
|
|
|
RangeType* range1 = type1->GetRange();
|
|
|
|
RangeType* range2 = type2->GetRange();
|
|
|
|
if (range1 != NULL && range2 != NULL) {
|
2015-01-28 08:42:15 +00:00
|
|
|
Limits lims = Union(Limits(range1), Limits(range2));
|
2015-02-12 15:21:17 +00:00
|
|
|
RangeHandle union_range = RangeType::New(lims, representation, region);
|
2015-01-28 08:42:15 +00:00
|
|
|
range = NormalizeRangeAndBitset(union_range, &new_bitset, region);
|
2014-09-24 07:33:51 +00:00
|
|
|
} else if (range1 != NULL) {
|
2015-01-28 08:42:15 +00:00
|
|
|
range = NormalizeRangeAndBitset(handle(range1), &new_bitset, region);
|
2014-09-24 07:33:51 +00:00
|
|
|
} else if (range2 != NULL) {
|
2015-01-28 08:42:15 +00:00
|
|
|
range = NormalizeRangeAndBitset(handle(range2), &new_bitset, region);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2015-02-12 15:21:17 +00:00
|
|
|
new_bitset = SEMANTIC(new_bitset) | representation;
|
2015-01-28 08:42:15 +00:00
|
|
|
TypeHandle bits = BitsetType::New(new_bitset, region);
|
|
|
|
result->Set(size++, bits);
|
2015-02-12 15:21:17 +00:00
|
|
|
if (!range->IsNone()) result->Set(size++, range);
|
2014-09-24 07:33:51 +00:00
|
|
|
|
|
|
|
size = AddToUnion(type1, result, size, region);
|
|
|
|
size = AddToUnion(type2, result, size, region);
|
|
|
|
return NormalizeUnion(result, size);
|
|
|
|
}
|
|
|
|
|
2013-06-20 09:10:10 +00:00
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
// Add [type] to [result] unless [type] is bitset, range, or already subsumed.
|
|
|
|
// Return new size of [result].
|
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::AddToUnion(
|
|
|
|
TypeHandle type, UnionHandle result, int size, Region* region) {
|
|
|
|
if (type->IsBitset() || type->IsRange()) return size;
|
|
|
|
if (type->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
|
2014-09-24 07:33:51 +00:00
|
|
|
size = AddToUnion(type->AsUnion()->Get(i), result, size, region);
|
|
|
|
}
|
|
|
|
return size;
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
for (int i = 0; i < size; ++i) {
|
2015-02-12 15:21:17 +00:00
|
|
|
if (type->SemanticIs(result->Get(i)->unhandle())) return size;
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
result->Set(size++, type);
|
|
|
|
return size;
|
|
|
|
}
|
2013-06-20 09:10:10 +00:00
|
|
|
|
|
|
|
|
2014-09-24 07:33:51 +00:00
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NormalizeUnion(
|
|
|
|
UnionHandle unioned, int size) {
|
2015-02-12 15:21:17 +00:00
|
|
|
DCHECK(size >= 1);
|
|
|
|
DCHECK(unioned->Get(0)->IsBitset());
|
|
|
|
// If the union has just one element, return it.
|
|
|
|
if (size == 1) {
|
|
|
|
return unioned->Get(0);
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
2015-02-12 15:21:17 +00:00
|
|
|
bitset bits = unioned->Get(0)->AsBitset();
|
|
|
|
// If the union only consists of a range, we can get rid of the union.
|
|
|
|
if (size == 2 && SEMANTIC(bits) == BitsetType::kNone) {
|
|
|
|
bitset representation = REPRESENTATION(bits);
|
|
|
|
if (representation == unioned->Get(1)->Representation()) {
|
|
|
|
return unioned->Get(1);
|
|
|
|
}
|
|
|
|
// TODO(jarin) If the element at 1 is range of constant, slap
|
|
|
|
// the representation on it and return that.
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
unioned->Shrink(size);
|
|
|
|
SLOW_DCHECK(unioned->Wellformed());
|
|
|
|
return unioned;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
|
2015-02-12 15:21:17 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Component extraction
|
|
|
|
|
|
|
|
// static
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Representation(
|
|
|
|
TypeHandle t, Region* region) {
|
|
|
|
return BitsetType::New(t->Representation(), region);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
template <class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Semantic(
|
|
|
|
TypeHandle t, Region* region) {
|
|
|
|
return Intersect(t, BitsetType::New(BitsetType::kSemantic, region), region);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Iteration.
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::NumClasses() {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
if (this->IsClass()) {
|
|
|
|
return 1;
|
|
|
|
} else if (this->IsUnion()) {
|
|
|
|
int result = 0;
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
|
|
|
if (this->AsUnion()->Get(i)->IsClass()) ++result;
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::NumConstants() {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
if (this->IsConstant()) {
|
|
|
|
return 1;
|
|
|
|
} else if (this->IsUnion()) {
|
|
|
|
int result = 0;
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
|
|
|
if (this->AsUnion()->Get(i)->IsConstant()) ++result;
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config> template<class T>
|
|
|
|
typename TypeImpl<Config>::TypeHandle
|
|
|
|
TypeImpl<Config>::Iterator<T>::get_type() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!Done());
|
2014-05-27 13:52:31 +00:00
|
|
|
return type_->IsUnion() ? type_->AsUnion()->Get(index_) : type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// C++ cannot specialise nested templates, so we have to go through this
|
|
|
|
// contortion with an auxiliary template to simulate it.
|
|
|
|
template<class Config, class T>
|
|
|
|
struct TypeImplIteratorAux {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type);
|
|
|
|
static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
struct TypeImplIteratorAux<Config, i::Map> {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->IsClass();
|
|
|
|
}
|
|
|
|
static i::Handle<i::Map> current(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->AsClass()->Map();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
struct TypeImplIteratorAux<Config, i::Object> {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->IsConstant();
|
|
|
|
}
|
|
|
|
static i::Handle<i::Object> current(
|
|
|
|
typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->AsConstant()->Value();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Config> template<class T>
|
|
|
|
bool TypeImpl<Config>::Iterator<T>::matches(TypeHandle type) {
|
|
|
|
return TypeImplIteratorAux<Config, T>::matches(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Config> template<class T>
|
|
|
|
i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() {
|
|
|
|
return TypeImplIteratorAux<Config, T>::current(get_type());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config> template<class T>
|
|
|
|
void TypeImpl<Config>::Iterator<T>::Advance() {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
++index_;
|
|
|
|
if (type_->IsUnion()) {
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int n = type_->AsUnion()->Length(); index_ < n; ++index_) {
|
|
|
|
if (matches(type_->AsUnion()->Get(index_))) return;
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
|
|
|
} else if (index_ == 0 && matches(type_)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Conversion between low-level representations.
|
|
|
|
|
2014-01-24 11:47:47 +00:00
|
|
|
template<class Config>
|
|
|
|
template<class OtherType>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert(
|
|
|
|
typename OtherType::TypeHandle type, Region* region) {
|
|
|
|
if (type->IsBitset()) {
|
2014-04-16 16:16:37 +00:00
|
|
|
return BitsetType::New(type->AsBitset(), region);
|
2014-01-24 11:47:47 +00:00
|
|
|
} else if (type->IsClass()) {
|
2014-09-24 07:33:51 +00:00
|
|
|
return ClassType::New(type->AsClass()->Map(), region);
|
2014-01-24 11:47:47 +00:00
|
|
|
} else if (type->IsConstant()) {
|
2014-09-24 07:33:51 +00:00
|
|
|
return ConstantType::New(type->AsConstant()->Value(), region);
|
2014-08-07 15:30:16 +00:00
|
|
|
} else if (type->IsRange()) {
|
|
|
|
return RangeType::New(
|
2015-01-28 08:42:15 +00:00
|
|
|
type->AsRange()->Min(), type->AsRange()->Max(),
|
|
|
|
BitsetType::New(REPRESENTATION(type->BitsetLub()), region), region);
|
2014-05-26 13:10:52 +00:00
|
|
|
} else if (type->IsContext()) {
|
|
|
|
TypeHandle outer = Convert<OtherType>(type->AsContext()->Outer(), region);
|
2014-09-24 07:33:51 +00:00
|
|
|
return ContextType::New(outer, region);
|
2014-04-16 16:16:37 +00:00
|
|
|
} else if (type->IsUnion()) {
|
|
|
|
int length = type->AsUnion()->Length();
|
|
|
|
UnionHandle unioned = UnionType::New(length, region);
|
2014-01-24 11:47:47 +00:00
|
|
|
for (int i = 0; i < length; ++i) {
|
2014-08-06 12:41:37 +00:00
|
|
|
TypeHandle t = Convert<OtherType>(type->AsUnion()->Get(i), region);
|
|
|
|
unioned->Set(i, t);
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
|
|
|
return unioned;
|
|
|
|
} else if (type->IsArray()) {
|
2014-08-06 12:41:37 +00:00
|
|
|
TypeHandle element = Convert<OtherType>(type->AsArray()->Element(), region);
|
2014-09-24 07:33:51 +00:00
|
|
|
return ArrayType::New(element, region);
|
2014-04-16 16:16:37 +00:00
|
|
|
} else if (type->IsFunction()) {
|
2014-08-06 12:41:37 +00:00
|
|
|
TypeHandle res = Convert<OtherType>(type->AsFunction()->Result(), region);
|
|
|
|
TypeHandle rcv = Convert<OtherType>(type->AsFunction()->Receiver(), region);
|
2014-04-16 16:16:37 +00:00
|
|
|
FunctionHandle function = FunctionType::New(
|
2014-09-24 07:33:51 +00:00
|
|
|
res, rcv, type->AsFunction()->Arity(), region);
|
2014-04-16 16:16:37 +00:00
|
|
|
for (int i = 0; i < function->Arity(); ++i) {
|
2014-08-06 12:41:37 +00:00
|
|
|
TypeHandle param = Convert<OtherType>(
|
|
|
|
type->AsFunction()->Parameter(i), region);
|
|
|
|
function->InitParameter(i, param);
|
2014-01-24 11:47:47 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
return function;
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
return None(region);
|
2014-01-24 11:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Printing.
|
2013-07-05 09:26:22 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-09-16 12:58:43 +00:00
|
|
|
const char* TypeImpl<Config>::BitsetType::Name(bitset bits) {
|
|
|
|
switch (bits) {
|
2014-05-26 13:10:52 +00:00
|
|
|
case REPRESENTATION(kAny): return "Any";
|
|
|
|
#define RETURN_NAMED_REPRESENTATION_TYPE(type, value) \
|
|
|
|
case REPRESENTATION(k##type): return #type;
|
|
|
|
REPRESENTATION_BITSET_TYPE_LIST(RETURN_NAMED_REPRESENTATION_TYPE)
|
|
|
|
#undef RETURN_NAMED_REPRESENTATION_TYPE
|
2014-03-18 11:50:18 +00:00
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
#define RETURN_NAMED_SEMANTIC_TYPE(type, value) \
|
|
|
|
case SEMANTIC(k##type): return #type;
|
|
|
|
SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE)
|
|
|
|
#undef RETURN_NAMED_SEMANTIC_TYPE
|
2014-03-18 11:50:18 +00:00
|
|
|
|
2013-11-22 12:38:49 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-03 07:18:30 +00:00
|
|
|
template <class Config>
|
2014-09-30 10:29:32 +00:00
|
|
|
void TypeImpl<Config>::BitsetType::Print(std::ostream& os, // NOLINT
|
2014-09-16 12:58:43 +00:00
|
|
|
bitset bits) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-09-16 12:58:43 +00:00
|
|
|
const char* name = Name(bits);
|
2014-03-18 11:50:18 +00:00
|
|
|
if (name != NULL) {
|
2014-07-03 07:18:30 +00:00
|
|
|
os << name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:42:15 +00:00
|
|
|
// clang-format off
|
2014-09-16 12:58:43 +00:00
|
|
|
static const bitset named_bitsets[] = {
|
2014-07-03 07:18:30 +00:00
|
|
|
#define BITSET_CONSTANT(type, value) REPRESENTATION(k##type),
|
2015-01-28 08:42:15 +00:00
|
|
|
REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT)
|
2014-07-03 07:18:30 +00:00
|
|
|
#undef BITSET_CONSTANT
|
2014-03-18 11:50:18 +00:00
|
|
|
|
2014-07-03 07:18:30 +00:00
|
|
|
#define BITSET_CONSTANT(type, value) SEMANTIC(k##type),
|
2015-01-28 08:42:15 +00:00
|
|
|
INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT)
|
|
|
|
SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT)
|
2014-07-03 07:18:30 +00:00
|
|
|
#undef BITSET_CONSTANT
|
|
|
|
};
|
2015-01-28 08:42:15 +00:00
|
|
|
// clang-format on
|
2014-07-03 07:18:30 +00:00
|
|
|
|
|
|
|
bool is_first = true;
|
|
|
|
os << "(";
|
2014-09-16 12:58:43 +00:00
|
|
|
for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) {
|
|
|
|
bitset subset = named_bitsets[i];
|
|
|
|
if ((bits & subset) == subset) {
|
2014-07-03 07:18:30 +00:00
|
|
|
if (!is_first) os << " | ";
|
|
|
|
is_first = false;
|
|
|
|
os << Name(subset);
|
2014-09-16 12:58:43 +00:00
|
|
|
bits -= subset;
|
2014-03-18 11:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-16 12:58:43 +00:00
|
|
|
DCHECK(bits == 0);
|
2014-07-03 07:18:30 +00:00
|
|
|
os << ")";
|
2014-03-18 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-03 07:18:30 +00:00
|
|
|
template <class Config>
|
2014-09-30 10:29:32 +00:00
|
|
|
void TypeImpl<Config>::PrintTo(std::ostream& os, PrintDimension dim) {
|
2014-04-16 16:16:37 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-05-27 13:52:31 +00:00
|
|
|
if (dim != REPRESENTATION_DIM) {
|
|
|
|
if (this->IsBitset()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
BitsetType::Print(os, SEMANTIC(this->AsBitset()));
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsClass()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
os << "Class(" << static_cast<void*>(*this->AsClass()->Map()) << " < ";
|
2014-08-05 11:27:26 +00:00
|
|
|
BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim);
|
2014-07-03 07:18:30 +00:00
|
|
|
os << ")";
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsConstant()) {
|
2014-09-25 08:31:23 +00:00
|
|
|
os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")";
|
2014-07-22 17:33:22 +00:00
|
|
|
} else if (this->IsRange()) {
|
2014-11-13 09:02:07 +00:00
|
|
|
std::ostream::fmtflags saved_flags = os.setf(std::ios::fixed);
|
|
|
|
std::streamsize saved_precision = os.precision(0);
|
2015-01-28 13:55:35 +00:00
|
|
|
os << "Range(" << this->AsRange()->Min() << ", " << this->AsRange()->Max()
|
|
|
|
<< ")";
|
2014-11-13 09:02:07 +00:00
|
|
|
os.flags(saved_flags);
|
|
|
|
os.precision(saved_precision);
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsContext()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
os << "Context(";
|
|
|
|
this->AsContext()->Outer()->PrintTo(os, dim);
|
|
|
|
os << ")";
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsUnion()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
os << "(";
|
2014-09-25 08:02:12 +00:00
|
|
|
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
|
|
|
|
TypeHandle type_i = this->AsUnion()->Get(i);
|
2014-07-03 07:18:30 +00:00
|
|
|
if (i > 0) os << " | ";
|
|
|
|
type_i->PrintTo(os, dim);
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
2014-07-03 07:18:30 +00:00
|
|
|
os << ")";
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsArray()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
os << "Array(";
|
|
|
|
AsArray()->Element()->PrintTo(os, dim);
|
|
|
|
os << ")";
|
2014-05-27 13:52:31 +00:00
|
|
|
} else if (this->IsFunction()) {
|
|
|
|
if (!this->AsFunction()->Receiver()->IsAny()) {
|
2014-07-03 07:18:30 +00:00
|
|
|
this->AsFunction()->Receiver()->PrintTo(os, dim);
|
|
|
|
os << ".";
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
2014-07-03 07:18:30 +00:00
|
|
|
os << "(";
|
2014-05-27 13:52:31 +00:00
|
|
|
for (int i = 0; i < this->AsFunction()->Arity(); ++i) {
|
2014-07-03 07:18:30 +00:00
|
|
|
if (i > 0) os << ", ";
|
|
|
|
this->AsFunction()->Parameter(i)->PrintTo(os, dim);
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
2014-07-03 07:18:30 +00:00
|
|
|
os << ")->";
|
|
|
|
this->AsFunction()->Result()->PrintTo(os, dim);
|
2014-05-27 13:52:31 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
2014-04-16 16:16:37 +00:00
|
|
|
}
|
2014-05-27 13:52:31 +00:00
|
|
|
}
|
2014-07-03 07:18:30 +00:00
|
|
|
if (dim == BOTH_DIMS) os << "/";
|
2014-05-27 13:52:31 +00:00
|
|
|
if (dim != SEMANTIC_DIM) {
|
2014-07-03 07:18:30 +00:00
|
|
|
BitsetType::Print(os, REPRESENTATION(this->BitsetLub()));
|
2013-07-10 11:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-06 09:26:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
template <class Config>
|
|
|
|
void TypeImpl<Config>::Print() {
|
|
|
|
OFStream os(stdout);
|
|
|
|
PrintTo(os);
|
2014-09-30 10:29:32 +00:00
|
|
|
os << std::endl;
|
2014-08-06 09:26:49 +00:00
|
|
|
}
|
2014-09-24 07:33:51 +00:00
|
|
|
template <class Config>
|
|
|
|
void TypeImpl<Config>::BitsetType::Print(bitset bits) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
Print(os, bits);
|
2014-09-30 10:29:32 +00:00
|
|
|
os << std::endl;
|
2014-09-24 07:33:51 +00:00
|
|
|
}
|
2014-08-06 09:26:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Instantiations.
|
|
|
|
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
template class TypeImpl<ZoneTypeConfig>;
|
|
|
|
template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>;
|
|
|
|
template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>;
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template class TypeImpl<HeapTypeConfig>;
|
|
|
|
template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>;
|
|
|
|
template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>;
|
|
|
|
|
2014-01-24 11:47:47 +00:00
|
|
|
template TypeImpl<ZoneTypeConfig>::TypeHandle
|
|
|
|
TypeImpl<ZoneTypeConfig>::Convert<HeapType>(
|
|
|
|
TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*);
|
|
|
|
template TypeImpl<HeapTypeConfig>::TypeHandle
|
|
|
|
TypeImpl<HeapTypeConfig>::Convert<Type>(
|
|
|
|
TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
} } // namespace v8::internal
|