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
|
|
|
|
|
|
|
#ifndef V8_TYPES_H_
|
|
|
|
#define V8_TYPES_H_
|
|
|
|
|
2014-07-22 17:33:22 +00:00
|
|
|
#include "src/factory.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/handles.h"
|
2013-06-05 15:43:53 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
class OStream;
|
|
|
|
|
2014-04-10 11:49:18 +00:00
|
|
|
// SUMMARY
|
|
|
|
//
|
2013-06-05 15:43:53 +00:00
|
|
|
// A simple type system for compiler-internal use. It is based entirely on
|
|
|
|
// union types, and all subtyping hence amounts to set inclusion. Besides the
|
|
|
|
// obvious primitive types and some predefined unions, the type language also
|
|
|
|
// can express class types (a.k.a. specific maps) and singleton types (i.e.,
|
|
|
|
// concrete constants).
|
|
|
|
//
|
2014-03-18 11:50:18 +00:00
|
|
|
// Types consist of two dimensions: semantic (value range) and representation.
|
|
|
|
// Both are related through subtyping.
|
|
|
|
//
|
2014-04-10 11:49:18 +00:00
|
|
|
// SEMANTIC DIMENSION
|
|
|
|
//
|
2014-03-18 11:50:18 +00:00
|
|
|
// The following equations and inequations hold for the semantic axis:
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
|
|
|
// None <= T
|
|
|
|
// T <= Any
|
|
|
|
//
|
2013-06-26 09:51:57 +00:00
|
|
|
// Number = Signed32 \/ Unsigned32 \/ Double
|
|
|
|
// Smi <= Signed32
|
2013-06-05 15:43:53 +00:00
|
|
|
// Name = String \/ Symbol
|
|
|
|
// UniqueName = InternalizedString \/ Symbol
|
|
|
|
// InternalizedString < String
|
|
|
|
//
|
|
|
|
// Receiver = Object \/ Proxy
|
|
|
|
// Array < Object
|
|
|
|
// Function < Object
|
2013-06-26 09:51:57 +00:00
|
|
|
// RegExp < Object
|
2014-03-18 11:50:18 +00:00
|
|
|
// Undetectable < Object
|
|
|
|
// Detectable = Receiver \/ Number \/ Name - Undetectable
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
|
|
|
// Class(map) < T iff instance_type(map) < T
|
|
|
|
// Constant(x) < T iff instance_type(map(x)) < T
|
2014-04-16 16:16:37 +00:00
|
|
|
// Array(T) < Array
|
|
|
|
// Function(R, S, T0, T1, ...) < Function
|
2014-05-26 13:10:52 +00:00
|
|
|
// Context(T) < Internal
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
2014-05-26 13:10:52 +00:00
|
|
|
// Both structural Array and Function types are invariant in all parameters;
|
|
|
|
// relaxing this would make Union and Intersect operations more involved.
|
|
|
|
// There is no subtyping relation between Array, Function, or Context types
|
|
|
|
// and respective Constant types, since these types cannot be reconstructed
|
|
|
|
// for arbitrary heap values.
|
|
|
|
// Note also that Constant(x) < Class(map(x)) does _not_ hold, since x's map can
|
2013-06-05 15:43:53 +00:00
|
|
|
// change! (Its instance type cannot, however.)
|
|
|
|
// TODO(rossberg): the latter is not currently true for proxies, because of fix,
|
|
|
|
// but will hold once we implement direct proxies.
|
2014-04-10 11:49:18 +00:00
|
|
|
// However, we also define a 'temporal' variant of the subtyping relation that
|
|
|
|
// considers the _current_ state only, i.e., Constant(x) <_now Class(map(x)).
|
|
|
|
//
|
|
|
|
// REPRESENTATIONAL DIMENSION
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
2014-03-18 11:50:18 +00:00
|
|
|
// For the representation axis, the following holds:
|
|
|
|
//
|
|
|
|
// None <= R
|
|
|
|
// R <= Any
|
|
|
|
//
|
2014-07-23 17:17:48 +00:00
|
|
|
// UntaggedInt = UntaggedInt1 \/ UntaggedInt8 \/
|
|
|
|
// UntaggedInt16 \/ UntaggedInt32
|
|
|
|
// UntaggedFloat = UntaggedFloat32 \/ UntaggedFloat64
|
|
|
|
// UntaggedNumber = UntaggedInt \/ UntaggedFloat
|
|
|
|
// Untagged = UntaggedNumber \/ UntaggedPtr
|
|
|
|
// Tagged = TaggedInt \/ TaggedPtr
|
2014-03-18 11:50:18 +00:00
|
|
|
//
|
|
|
|
// Subtyping relates the two dimensions, for example:
|
|
|
|
//
|
|
|
|
// Number <= Tagged \/ UntaggedNumber
|
|
|
|
// Object <= TaggedPtr \/ UntaggedPtr
|
|
|
|
//
|
|
|
|
// That holds because the semantic type constructors defined by the API create
|
|
|
|
// types that allow for all possible representations, and dually, the ones for
|
|
|
|
// representation types initially include all semantic ranges. Representations
|
|
|
|
// can then e.g. be narrowed for a given semantic type using intersection:
|
|
|
|
//
|
|
|
|
// SignedSmall /\ TaggedInt (a 'smi')
|
|
|
|
// Number /\ TaggedPtr (a heap number)
|
|
|
|
//
|
2014-04-10 11:49:18 +00:00
|
|
|
// PREDICATES
|
|
|
|
//
|
2013-06-05 15:43:53 +00:00
|
|
|
// There are two main functions for testing types:
|
|
|
|
//
|
|
|
|
// T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2)
|
|
|
|
// T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0)
|
|
|
|
//
|
2013-06-12 17:20:37 +00:00
|
|
|
// Typically, the former is to be used to select representations (e.g., via
|
2014-03-18 11:50:18 +00:00
|
|
|
// T->Is(SignedSmall())), and the latter to check whether a specific case needs
|
|
|
|
// handling (e.g., via T->Maybe(Number())).
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
|
|
|
// There is no functionality to discover whether a type is a leaf in the
|
|
|
|
// lattice. That is intentional. It should always be possible to refine the
|
|
|
|
// lattice (e.g., splitting up number types further) without invalidating any
|
|
|
|
// existing assumptions or tests.
|
2014-04-16 16:16:37 +00:00
|
|
|
// Consequently, do not normally use Equals for type tests, always use Is!
|
2013-06-26 09:51:57 +00:00
|
|
|
//
|
2014-04-10 11:49:18 +00:00
|
|
|
// The NowIs operator implements state-sensitive subtying, as described above.
|
|
|
|
// Any compilation decision based on such temporary properties requires runtime
|
|
|
|
// guarding!
|
|
|
|
//
|
|
|
|
// PROPERTIES
|
|
|
|
//
|
|
|
|
// Various formal properties hold for constructors, operators, and predicates
|
2014-04-14 15:35:36 +00:00
|
|
|
// over types. For example, constructors are injective, subtyping is a complete
|
|
|
|
// partial order, union and intersection satisfy the usual algebraic properties.
|
2014-04-10 11:49:18 +00:00
|
|
|
//
|
|
|
|
// See test/cctest/test-types.cc for a comprehensive executable specification,
|
2014-04-14 15:35:36 +00:00
|
|
|
// especially with respect to the properties of the more exotic 'temporal'
|
2014-04-10 11:49:18 +00:00
|
|
|
// constructors and predicates (those prefixed 'Now').
|
|
|
|
//
|
|
|
|
// IMPLEMENTATION
|
|
|
|
//
|
2013-06-05 15:43:53 +00:00
|
|
|
// Internally, all 'primitive' types, and their unions, are represented as
|
2014-03-11 10:28:38 +00:00
|
|
|
// bitsets. Class is a heap pointer to the respective map. Only Constant's, or
|
|
|
|
// unions containing Class'es or Constant's, currently require allocation.
|
2013-06-20 09:10:10 +00:00
|
|
|
// Note that the bitset representation is closed under both Union and Intersect.
|
2013-06-05 15:43:53 +00:00
|
|
|
//
|
2014-03-11 10:28:38 +00:00
|
|
|
// There are two type representations, using different allocation:
|
|
|
|
//
|
|
|
|
// - class Type (zone-allocated, for compiler and concurrent compilation)
|
|
|
|
// - class HeapType (heap-allocated, for persistent types)
|
|
|
|
//
|
|
|
|
// Both provide the same API, and the Convert method can be used to interconvert
|
|
|
|
// them. For zone types, no query method touches the heap, only constructors do.
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2013-07-10 11:20:00 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Values for bitset types
|
|
|
|
|
2014-03-18 11:50:18 +00:00
|
|
|
#define MASK_BITSET_TYPE_LIST(V) \
|
2014-05-26 13:10:52 +00:00
|
|
|
V(Representation, static_cast<int>(0xffc00000)) \
|
|
|
|
V(Semantic, static_cast<int>(0x003fffff))
|
2014-03-18 11:50:18 +00:00
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
#define REPRESENTATION(k) ((k) & BitsetType::kRepresentation)
|
|
|
|
#define SEMANTIC(k) ((k) & BitsetType::kSemantic)
|
2014-03-18 11:50:18 +00:00
|
|
|
|
|
|
|
#define REPRESENTATION_BITSET_TYPE_LIST(V) \
|
|
|
|
V(None, 0) \
|
2014-05-26 13:10:52 +00:00
|
|
|
V(UntaggedInt1, 1 << 22 | kSemantic) \
|
2014-03-18 11:50:18 +00:00
|
|
|
V(UntaggedInt8, 1 << 23 | kSemantic) \
|
|
|
|
V(UntaggedInt16, 1 << 24 | kSemantic) \
|
|
|
|
V(UntaggedInt32, 1 << 25 | kSemantic) \
|
|
|
|
V(UntaggedFloat32, 1 << 26 | kSemantic) \
|
|
|
|
V(UntaggedFloat64, 1 << 27 | kSemantic) \
|
|
|
|
V(UntaggedPtr, 1 << 28 | kSemantic) \
|
|
|
|
V(TaggedInt, 1 << 29 | kSemantic) \
|
|
|
|
V(TaggedPtr, -1 << 30 | kSemantic) /* MSB has to be sign-extended */ \
|
|
|
|
\
|
2014-05-26 13:10:52 +00:00
|
|
|
V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \
|
|
|
|
kUntaggedInt16 | kUntaggedInt32) \
|
|
|
|
V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \
|
|
|
|
V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \
|
|
|
|
V(Untagged, kUntaggedNumber | kUntaggedPtr) \
|
2014-03-18 11:50:18 +00:00
|
|
|
V(Tagged, kTaggedInt | kTaggedPtr)
|
|
|
|
|
|
|
|
#define SEMANTIC_BITSET_TYPE_LIST(V) \
|
|
|
|
V(Null, 1 << 0 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Undefined, 1 << 1 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Boolean, 1 << 2 | REPRESENTATION(kTaggedPtr)) \
|
2014-05-26 13:10:52 +00:00
|
|
|
V(UnsignedSmall, 1 << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(OtherSignedSmall, 1 << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(OtherUnsigned31, 1 << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(OtherUnsigned32, 1 << 6 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(OtherSigned32, 1 << 7 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(MinusZero, 1 << 8 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(NaN, 1 << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(OtherNumber, 1 << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \
|
|
|
|
V(Symbol, 1 << 11 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(InternalizedString, 1 << 12 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(OtherString, 1 << 13 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Undetectable, 1 << 14 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Array, 1 << 15 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Buffer, 1 << 16 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Function, 1 << 17 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(RegExp, 1 << 18 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(OtherObject, 1 << 19 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Proxy, 1 << 20 | REPRESENTATION(kTaggedPtr)) \
|
|
|
|
V(Internal, 1 << 21 | REPRESENTATION(kTagged | kUntagged)) \
|
2013-11-22 12:38:49 +00:00
|
|
|
\
|
2014-05-26 13:10:52 +00:00
|
|
|
V(SignedSmall, kUnsignedSmall | kOtherSignedSmall) \
|
|
|
|
V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \
|
|
|
|
V(Unsigned32, kUnsignedSmall | kOtherUnsigned31 | kOtherUnsigned32) \
|
|
|
|
V(Integral32, kSigned32 | kUnsigned32) \
|
|
|
|
V(Number, kIntegral32 | kMinusZero | kNaN | kOtherNumber) \
|
|
|
|
V(String, kInternalizedString | kOtherString) \
|
|
|
|
V(UniqueName, kSymbol | kInternalizedString) \
|
|
|
|
V(Name, kSymbol | kString) \
|
|
|
|
V(NumberOrString, kNumber | kString) \
|
|
|
|
V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \
|
|
|
|
V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \
|
|
|
|
V(DetectableReceiver, kDetectableObject | kProxy) \
|
|
|
|
V(Detectable, kDetectableReceiver | kNumber | kName) \
|
|
|
|
V(Object, kDetectableObject | kUndetectable) \
|
|
|
|
V(Receiver, kObject | kProxy) \
|
|
|
|
V(NonNumber, kBoolean | kName | kNull | kReceiver | \
|
|
|
|
kUndefined | kInternal) \
|
2014-04-09 11:12:15 +00:00
|
|
|
V(Any, -1)
|
2014-03-18 11:50:18 +00:00
|
|
|
|
|
|
|
#define BITSET_TYPE_LIST(V) \
|
|
|
|
MASK_BITSET_TYPE_LIST(V) \
|
|
|
|
REPRESENTATION_BITSET_TYPE_LIST(V) \
|
|
|
|
SEMANTIC_BITSET_TYPE_LIST(V)
|
2013-07-10 11:20:00 +00:00
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// The abstract Type class, parameterized over the low-level representation.
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
// struct Config {
|
2014-04-16 16:16:37 +00:00
|
|
|
// typedef TypeImpl<Config> Type;
|
2014-01-10 12:19:01 +00:00
|
|
|
// typedef Base;
|
2014-04-08 10:50:56 +00:00
|
|
|
// typedef Struct;
|
2014-01-10 12:19:01 +00:00
|
|
|
// typedef Region;
|
|
|
|
// template<class> struct Handle { typedef type; } // No template typedefs...
|
2014-04-16 16:16:37 +00:00
|
|
|
// template<class T> static Handle<T>::type handle(T* t); // !is_bitset(t)
|
|
|
|
// template<class T> static Handle<T>::type cast(Handle<Type>::type);
|
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
|
|
|
// static bool is_bitset(Type*);
|
|
|
|
// static bool is_class(Type*);
|
2014-04-16 16:16:37 +00:00
|
|
|
// static bool is_struct(Type*, int tag);
|
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
|
|
|
// static int as_bitset(Type*);
|
|
|
|
// static i::Handle<i::Map> as_class(Type*);
|
2014-04-08 10:50:56 +00:00
|
|
|
// static Handle<Struct>::type as_struct(Type*);
|
2014-01-10 12:19:01 +00:00
|
|
|
// static Type* from_bitset(int bitset);
|
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
|
|
|
// static Handle<Type>::type from_bitset(int bitset, Region*);
|
2014-05-27 13:52:31 +00:00
|
|
|
// static Handle<Type>::type from_class(i::Handle<Map>, Region*);
|
2014-04-16 16:16:37 +00:00
|
|
|
// static Handle<Type>::type from_struct(Handle<Struct>::type, int tag);
|
2014-04-08 10:50:56 +00:00
|
|
|
// static Handle<Struct>::type struct_create(int tag, int length, Region*);
|
|
|
|
// static void struct_shrink(Handle<Struct>::type, int length);
|
|
|
|
// static int struct_tag(Handle<Struct>::type);
|
|
|
|
// static int struct_length(Handle<Struct>::type);
|
|
|
|
// static Handle<Type>::type struct_get(Handle<Struct>::type, int);
|
|
|
|
// static void struct_set(Handle<Struct>::type, int, Handle<Type>::type);
|
2014-05-27 13:52:31 +00:00
|
|
|
// template<class V>
|
|
|
|
// static i::Handle<V> struct_get_value(Handle<Struct>::type, int);
|
|
|
|
// template<class V>
|
|
|
|
// static void struct_set_value(Handle<Struct>::type, int, i::Handle<V>);
|
2014-01-10 12:19:01 +00:00
|
|
|
// }
|
|
|
|
template<class Config>
|
|
|
|
class TypeImpl : public Config::Base {
|
2013-06-05 15:43:53 +00:00
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
// Auxiliary types.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
class BitsetType; // Internal
|
|
|
|
class StructuralType; // Internal
|
|
|
|
class UnionType; // Internal
|
|
|
|
|
|
|
|
class ClassType;
|
|
|
|
class ConstantType;
|
2014-07-22 17:33:22 +00:00
|
|
|
class RangeType;
|
2014-05-26 13:10:52 +00:00
|
|
|
class ContextType;
|
2014-04-16 16:16:37 +00:00
|
|
|
class ArrayType;
|
|
|
|
class FunctionType;
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
typedef typename Config::template Handle<TypeImpl>::type TypeHandle;
|
2014-04-16 16:16:37 +00:00
|
|
|
typedef typename Config::template Handle<ClassType>::type ClassHandle;
|
|
|
|
typedef typename Config::template Handle<ConstantType>::type ConstantHandle;
|
2014-07-22 17:33:22 +00:00
|
|
|
typedef typename Config::template Handle<RangeType>::type RangeHandle;
|
2014-05-26 13:10:52 +00:00
|
|
|
typedef typename Config::template Handle<ContextType>::type ContextHandle;
|
2014-04-16 16:16:37 +00:00
|
|
|
typedef typename Config::template Handle<ArrayType>::type ArrayHandle;
|
|
|
|
typedef typename Config::template Handle<FunctionType>::type FunctionHandle;
|
|
|
|
typedef typename Config::template Handle<UnionType>::type UnionHandle;
|
2014-01-10 12:19:01 +00:00
|
|
|
typedef typename Config::Region Region;
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Constructors.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
#define DEFINE_TYPE_CONSTRUCTOR(type, value) \
|
|
|
|
static TypeImpl* type() { return BitsetType::New(BitsetType::k##type); } \
|
|
|
|
static TypeHandle type(Region* region) { \
|
|
|
|
return BitsetType::New(BitsetType::k##type, region); \
|
2014-01-10 12:19:01 +00:00
|
|
|
}
|
2013-11-22 12:38:49 +00:00
|
|
|
BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
|
2013-07-10 11:20:00 +00:00
|
|
|
#undef DEFINE_TYPE_CONSTRUCTOR
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
static TypeHandle Class(i::Handle<i::Map> map, Region* region) {
|
2014-04-16 16:16:37 +00:00
|
|
|
return ClassType::New(map, region);
|
2013-06-06 15:40:28 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
static TypeHandle Constant(i::Handle<i::Object> value, Region* region) {
|
2014-07-22 17:33:22 +00:00
|
|
|
// TODO(neis): return RangeType for numerical values
|
2014-04-16 16:16:37 +00:00
|
|
|
return ConstantType::New(value, region);
|
|
|
|
}
|
2014-07-22 17:33:22 +00:00
|
|
|
static TypeHandle Range(double min, double max, Region* region) {
|
|
|
|
return RangeType::New(min, max, region);
|
|
|
|
}
|
2014-05-26 13:10:52 +00:00
|
|
|
static TypeHandle Context(TypeHandle outer, Region* region) {
|
|
|
|
return ContextType::New(outer, region);
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
static TypeHandle Array(TypeHandle element, Region* region) {
|
|
|
|
return ArrayType::New(element, region);
|
|
|
|
}
|
|
|
|
static FunctionHandle Function(
|
|
|
|
TypeHandle result, TypeHandle receiver, int arity, Region* region) {
|
|
|
|
return FunctionType::New(result, receiver, arity, region);
|
|
|
|
}
|
|
|
|
static TypeHandle Function(TypeHandle result, Region* region) {
|
|
|
|
return Function(result, Any(region), 0, region);
|
|
|
|
}
|
|
|
|
static TypeHandle Function(
|
|
|
|
TypeHandle result, TypeHandle param0, Region* region) {
|
|
|
|
FunctionHandle function = Function(result, Any(region), 1, region);
|
|
|
|
function->InitParameter(0, param0);
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
static TypeHandle Function(
|
|
|
|
TypeHandle result, TypeHandle param0, TypeHandle param1, Region* region) {
|
|
|
|
FunctionHandle function = Function(result, Any(region), 2, region);
|
|
|
|
function->InitParameter(0, param0);
|
|
|
|
function->InitParameter(1, param1);
|
|
|
|
return function;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-05-26 13:10:52 +00:00
|
|
|
static TypeHandle Function(
|
|
|
|
TypeHandle result, TypeHandle param0, TypeHandle param1,
|
|
|
|
TypeHandle param2, Region* region) {
|
|
|
|
FunctionHandle function = Function(result, Any(region), 3, region);
|
|
|
|
function->InitParameter(0, param0);
|
|
|
|
function->InitParameter(1, param1);
|
|
|
|
function->InitParameter(2, param2);
|
|
|
|
return function;
|
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
|
|
|
|
static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg);
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
static TypeHandle Of(double value, Region* region) {
|
|
|
|
return Config::from_bitset(BitsetType::Lub(value), region);
|
|
|
|
}
|
2014-04-02 07:01:43 +00:00
|
|
|
static TypeHandle Of(i::Object* value, Region* region) {
|
2014-04-16 16:16:37 +00:00
|
|
|
return Config::from_bitset(BitsetType::Lub(value), region);
|
2014-04-02 07:01:43 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
static TypeHandle Of(i::Handle<i::Object> value, Region* region) {
|
2014-04-02 07:01:43 +00:00
|
|
|
return Of(*value, region);
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Predicates.
|
|
|
|
|
|
|
|
bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); }
|
2014-04-09 11:12:15 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
bool Is(TypeImpl* that) { return this == that || this->SlowIs(that); }
|
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 TypeHandle>
|
2014-01-10 12:19:01 +00:00
|
|
|
bool Is(TypeHandle that) { return this->Is(*that); }
|
2014-04-01 13:11:12 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
bool Maybe(TypeImpl* that);
|
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 TypeHandle>
|
2014-01-10 12:19:01 +00:00
|
|
|
bool Maybe(TypeHandle that) { return this->Maybe(*that); }
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
bool Equals(TypeImpl* that) { return this->Is(that) && that->Is(this); }
|
|
|
|
template<class TypeHandle>
|
|
|
|
bool Equals(TypeHandle that) { return this->Equals(*that); }
|
|
|
|
|
2014-04-01 13:11:12 +00:00
|
|
|
// Equivalent to Constant(value)->Is(this), but avoiding allocation.
|
|
|
|
bool Contains(i::Object* val);
|
|
|
|
bool Contains(i::Handle<i::Object> val) { return this->Contains(*val); }
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// State-dependent versions of the above that consider subtyping between
|
2013-11-22 13:16:40 +00:00
|
|
|
// a constant and its map class.
|
2014-05-27 13:52:31 +00:00
|
|
|
inline static TypeHandle NowOf(i::Object* value, Region* region);
|
2014-04-02 07:01:43 +00:00
|
|
|
static TypeHandle NowOf(i::Handle<i::Object> value, Region* region) {
|
|
|
|
return NowOf(*value, region);
|
|
|
|
}
|
2014-04-01 13:11:12 +00:00
|
|
|
bool NowIs(TypeImpl* that);
|
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 TypeHandle>
|
2014-04-01 13:11:12 +00:00
|
|
|
bool NowIs(TypeHandle that) { return this->NowIs(*that); }
|
2014-04-11 09:24:35 +00:00
|
|
|
inline bool NowContains(i::Object* val);
|
2014-04-01 13:11:12 +00:00
|
|
|
bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); }
|
2013-11-22 13:16:40 +00:00
|
|
|
|
2014-04-17 08:22:22 +00:00
|
|
|
bool NowStable();
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Inspection.
|
|
|
|
|
|
|
|
bool IsClass() {
|
|
|
|
return Config::is_class(this)
|
|
|
|
|| Config::is_struct(this, StructuralType::kClassTag);
|
|
|
|
}
|
|
|
|
bool IsConstant() {
|
|
|
|
return Config::is_struct(this, StructuralType::kConstantTag);
|
|
|
|
}
|
2014-07-22 17:33:22 +00:00
|
|
|
bool IsRange() {
|
|
|
|
return Config::is_struct(this, StructuralType::kRangeTag);
|
|
|
|
}
|
2014-05-26 13:10:52 +00:00
|
|
|
bool IsContext() {
|
|
|
|
return Config::is_struct(this, StructuralType::kContextTag);
|
|
|
|
}
|
2014-05-27 13:52:31 +00:00
|
|
|
bool IsArray() {
|
|
|
|
return Config::is_struct(this, StructuralType::kArrayTag);
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
bool IsFunction() {
|
|
|
|
return Config::is_struct(this, StructuralType::kFunctionTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassType* AsClass() { return ClassType::cast(this); }
|
|
|
|
ConstantType* AsConstant() { return ConstantType::cast(this); }
|
2014-07-22 17:33:22 +00:00
|
|
|
RangeType* AsRange() { return RangeType::cast(this); }
|
2014-05-26 13:10:52 +00:00
|
|
|
ContextType* AsContext() { return ContextType::cast(this); }
|
2014-04-16 16:16:37 +00:00
|
|
|
ArrayType* AsArray() { return ArrayType::cast(this); }
|
|
|
|
FunctionType* AsFunction() { return FunctionType::cast(this); }
|
2013-06-12 17:20:37 +00:00
|
|
|
|
|
|
|
int NumClasses();
|
|
|
|
int NumConstants();
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class T> class Iterator;
|
2014-04-16 16:36:27 +00:00
|
|
|
Iterator<i::Map> Classes() {
|
|
|
|
if (this->IsBitset()) return Iterator<i::Map>();
|
|
|
|
return Iterator<i::Map>(Config::handle(this));
|
|
|
|
}
|
|
|
|
Iterator<i::Object> Constants() {
|
|
|
|
if (this->IsBitset()) return Iterator<i::Object>();
|
|
|
|
return Iterator<i::Object>(Config::handle(this));
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Casting and conversion.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static inline TypeImpl* cast(typename Config::Base* object);
|
|
|
|
|
|
|
|
template<class OtherTypeImpl>
|
|
|
|
static TypeHandle Convert(
|
|
|
|
typename OtherTypeImpl::TypeHandle type, Region* region);
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Printing.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM };
|
2014-05-27 13:52:31 +00:00
|
|
|
|
2014-07-03 07:18:30 +00:00
|
|
|
void PrintTo(OStream& os, PrintDimension dim = BOTH_DIMS); // NOLINT
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
protected:
|
2014-05-27 13:52:31 +00:00
|
|
|
// Friends.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class> friend class Iterator;
|
|
|
|
template<class> friend class TypeImpl;
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Handle conversion.
|
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
template<class T>
|
2014-04-16 16:16:37 +00:00
|
|
|
static typename Config::template Handle<T>::type handle(T* type) {
|
|
|
|
return Config::handle(type);
|
|
|
|
}
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeImpl* unhandle() { return this; }
|
|
|
|
|
|
|
|
// Internal inspection.
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
bool IsNone() { return this == None(); }
|
|
|
|
bool IsAny() { return this == Any(); }
|
|
|
|
bool IsBitset() { return Config::is_bitset(this); }
|
|
|
|
bool IsUnion() { return Config::is_struct(this, StructuralType::kUnionTag); }
|
|
|
|
|
|
|
|
int AsBitset() {
|
|
|
|
ASSERT(this->IsBitset());
|
|
|
|
return static_cast<BitsetType*>(this)->Bitset();
|
|
|
|
}
|
|
|
|
UnionType* AsUnion() { return UnionType::cast(this); }
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// Auxiliary functions.
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
int BitsetGlb() { return BitsetType::Glb(this); }
|
|
|
|
int BitsetLub() { return BitsetType::Lub(this); }
|
2014-05-27 13:52:31 +00:00
|
|
|
int InherentBitsetLub() { return BitsetType::InherentLub(this); }
|
|
|
|
|
|
|
|
bool SlowIs(TypeImpl* that);
|
|
|
|
|
2014-07-23 17:17:48 +00:00
|
|
|
TypeHandle Rebound(int bitset, Region* region);
|
2014-05-27 13:52:31 +00:00
|
|
|
int BoundBy(TypeImpl* that);
|
|
|
|
int IndexInUnion(int bound, UnionHandle unioned, int current_size);
|
|
|
|
static int ExtendUnion(
|
|
|
|
UnionHandle unioned, int current_size, TypeHandle t,
|
|
|
|
TypeHandle other, bool is_intersect, Region* region);
|
|
|
|
static int NormalizeUnion(UnionHandle unioned, int current_size, int bitset);
|
2014-04-16 16:16:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Bitset types (internal).
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::BitsetType : public TypeImpl<Config> {
|
2014-05-27 14:26:32 +00:00
|
|
|
protected:
|
2014-04-16 16:16:37 +00:00
|
|
|
friend class TypeImpl<Config>;
|
2013-06-12 17:20:37 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
enum {
|
|
|
|
#define DECLARE_TYPE(type, value) k##type = (value),
|
|
|
|
BITSET_TYPE_LIST(DECLARE_TYPE)
|
|
|
|
#undef DECLARE_TYPE
|
|
|
|
kUnusedEOL = 0
|
2013-06-12 17:20:37 +00:00
|
|
|
};
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
int Bitset() { return Config::as_bitset(this); }
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static TypeImpl* New(int bitset) {
|
2014-04-16 16:16:37 +00:00
|
|
|
return static_cast<BitsetType*>(Config::from_bitset(bitset));
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
static TypeHandle New(int bitset, Region* region) {
|
|
|
|
return Config::from_bitset(bitset, region);
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static bool IsInhabited(int bitset) {
|
|
|
|
return (bitset & kRepresentation) && (bitset & kSemantic);
|
2013-07-08 13:07:41 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 17:17:48 +00:00
|
|
|
static bool Is(int bitset1, int bitset2) {
|
|
|
|
return (bitset1 | bitset2) == bitset2;
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
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);
|
2014-05-26 13:10:52 +00:00
|
|
|
static int Lub(double value);
|
2014-04-16 16:16:37 +00:00
|
|
|
static int Lub(i::Map* map);
|
2014-05-27 13:52:31 +00:00
|
|
|
static int InherentLub(TypeImpl* type);
|
2014-04-16 13:44:26 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static const char* Name(int bitset);
|
2014-07-03 07:18:30 +00:00
|
|
|
static void Print(OStream& os, int bitset); // NOLINT
|
2014-05-26 13:10:52 +00:00
|
|
|
using TypeImpl::PrintTo;
|
2014-04-16 16:16:37 +00:00
|
|
|
};
|
2014-04-16 15:42:22 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Superclass for non-bitset types (internal).
|
|
|
|
// Contains a tag and a variable number of type or value fields.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::StructuralType : public TypeImpl<Config> {
|
|
|
|
protected:
|
2014-01-24 11:47:47 +00:00
|
|
|
template<class> friend class TypeImpl;
|
2014-04-16 16:16:37 +00:00
|
|
|
friend struct ZoneTypeConfig; // For tags.
|
2014-04-08 10:50:56 +00:00
|
|
|
friend struct HeapTypeConfig;
|
2014-01-10 12:19:01 +00:00
|
|
|
|
2014-04-08 10:50:56 +00:00
|
|
|
enum Tag {
|
|
|
|
kClassTag,
|
|
|
|
kConstantTag,
|
2014-07-22 17:33:22 +00:00
|
|
|
kRangeTag,
|
2014-05-26 13:10:52 +00:00
|
|
|
kContextTag,
|
2014-04-16 16:16:37 +00:00
|
|
|
kArrayTag,
|
|
|
|
kFunctionTag,
|
2014-04-08 10:50:56 +00:00
|
|
|
kUnionTag
|
|
|
|
};
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
int Length() {
|
|
|
|
return Config::struct_length(Config::as_struct(this));
|
|
|
|
}
|
|
|
|
TypeHandle Get(int i) {
|
2014-05-27 13:52:31 +00:00
|
|
|
ASSERT(0 <= i && i < this->Length());
|
2014-04-16 16:16:37 +00:00
|
|
|
return Config::struct_get(Config::as_struct(this), i);
|
|
|
|
}
|
|
|
|
void Set(int i, TypeHandle type) {
|
2014-05-27 13:52:31 +00:00
|
|
|
ASSERT(0 <= i && i < this->Length());
|
2014-04-16 16:16:37 +00:00
|
|
|
Config::struct_set(Config::as_struct(this), i, type);
|
|
|
|
}
|
|
|
|
void Shrink(int length) {
|
2014-05-27 13:52:31 +00:00
|
|
|
ASSERT(2 <= length && length <= this->Length());
|
2014-04-16 16:16:37 +00:00
|
|
|
Config::struct_shrink(Config::as_struct(this), length);
|
|
|
|
}
|
2014-05-27 13:52:31 +00:00
|
|
|
template<class V> i::Handle<V> GetValue(int i) {
|
|
|
|
ASSERT(0 <= i && i < this->Length());
|
|
|
|
return Config::template struct_get_value<V>(Config::as_struct(this), i);
|
|
|
|
}
|
|
|
|
template<class V> void SetValue(int i, i::Handle<V> x) {
|
|
|
|
ASSERT(0 <= i && i < this->Length());
|
|
|
|
Config::struct_set_value(Config::as_struct(this), i, x);
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
static TypeHandle New(Tag tag, int length, Region* region) {
|
2014-05-27 13:52:31 +00:00
|
|
|
ASSERT(1 <= length);
|
2014-04-16 16:16:37 +00:00
|
|
|
return Config::from_struct(Config::struct_create(tag, length, region));
|
|
|
|
}
|
|
|
|
};
|
2014-04-16 13:44:26 +00:00
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Union types (internal).
|
|
|
|
// A union is a structured type with the following invariants:
|
|
|
|
// - its length is at least 2
|
|
|
|
// - at most one field is a bitset, and it must go into index 0
|
|
|
|
// - no field is a union
|
|
|
|
// - no field is a subtype of any other field
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
2014-05-27 13:52:31 +00:00
|
|
|
class TypeImpl<Config>::UnionType : public StructuralType {
|
2014-04-16 16:16:37 +00:00
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
static UnionHandle New(int length, Region* region) {
|
|
|
|
return Config::template cast<UnionType>(
|
|
|
|
StructuralType::New(StructuralType::kUnionTag, length, region));
|
|
|
|
}
|
|
|
|
|
|
|
|
static UnionType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsUnion());
|
|
|
|
return static_cast<UnionType*>(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wellformed();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Class types.
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::ClassType : public StructuralType {
|
|
|
|
public:
|
|
|
|
TypeHandle Bound(Region* region) {
|
|
|
|
return Config::is_class(this)
|
|
|
|
? BitsetType::New(BitsetType::Lub(*Config::as_class(this)), region)
|
|
|
|
: this->Get(0);
|
|
|
|
}
|
|
|
|
i::Handle<i::Map> Map() {
|
|
|
|
return Config::is_class(this)
|
|
|
|
? Config::as_class(this)
|
|
|
|
: this->template GetValue<i::Map>(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ClassHandle New(
|
|
|
|
i::Handle<i::Map> map, TypeHandle bound, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::Lub(*map)));
|
2014-05-27 13:52:31 +00:00
|
|
|
ClassHandle type = Config::template cast<ClassType>(
|
|
|
|
StructuralType::New(StructuralType::kClassTag, 2, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
type->SetValue(1, map);
|
|
|
|
return type;
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
static ClassHandle New(i::Handle<i::Map> map, Region* region) {
|
2014-05-27 13:52:31 +00:00
|
|
|
ClassHandle type =
|
|
|
|
Config::template cast<ClassType>(Config::from_class(map, region));
|
|
|
|
if (type->IsClass()) {
|
|
|
|
return type;
|
|
|
|
} else {
|
|
|
|
TypeHandle bound = BitsetType::New(BitsetType::Lub(*map), region);
|
|
|
|
return New(map, bound, region);
|
|
|
|
}
|
2014-04-16 13:44:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static ClassType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsClass());
|
|
|
|
return static_cast<ClassType*>(type);
|
2014-04-16 15:42:22 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
};
|
|
|
|
|
2014-04-16 13:44:26 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Constant types.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
2014-05-27 13:52:31 +00:00
|
|
|
class TypeImpl<Config>::ConstantType : public StructuralType {
|
2014-04-16 16:16:37 +00:00
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeHandle Bound() { return this->Get(0); }
|
|
|
|
i::Handle<i::Object> Value() { return this->template GetValue<i::Object>(1); }
|
|
|
|
|
|
|
|
static ConstantHandle New(
|
|
|
|
i::Handle<i::Object> value, TypeHandle bound, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::Lub(*value)));
|
2014-05-27 13:52:31 +00:00
|
|
|
ConstantHandle type = Config::template cast<ConstantType>(
|
|
|
|
StructuralType::New(StructuralType::kConstantTag, 2, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
type->SetValue(1, value);
|
|
|
|
return type;
|
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
static ConstantHandle New(i::Handle<i::Object> value, Region* region) {
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeHandle bound = BitsetType::New(BitsetType::Lub(*value), region);
|
|
|
|
return New(value, bound, region);
|
2014-04-16 15:42:22 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
static ConstantType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsConstant());
|
|
|
|
return static_cast<ConstantType*>(type);
|
2014-04-16 15:42:22 +00:00
|
|
|
}
|
2014-04-16 16:16:37 +00:00
|
|
|
};
|
2014-04-16 15:42:22 +00:00
|
|
|
|
|
|
|
|
2014-07-22 17:33:22 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Range types.
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::RangeType : public StructuralType {
|
|
|
|
public:
|
|
|
|
TypeHandle Bound() { return this->Get(0); }
|
|
|
|
double Min() { return this->template GetValue<i::HeapNumber>(1)->value(); }
|
|
|
|
double Max() { return this->template GetValue<i::HeapNumber>(2)->value(); }
|
|
|
|
|
|
|
|
static RangeHandle New(
|
|
|
|
double min, double max, TypeHandle bound, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kNumber));
|
2014-07-22 17:33:22 +00:00
|
|
|
ASSERT(!std::isnan(min) && !std::isnan(max) && min <= max);
|
|
|
|
RangeHandle type = Config::template cast<RangeType>(
|
|
|
|
StructuralType::New(StructuralType::kRangeTag, 3, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
Factory* factory = Config::isolate(region)->factory();
|
2014-07-23 14:11:30 +00:00
|
|
|
Handle<HeapNumber> minV = factory->NewHeapNumber(min);
|
|
|
|
Handle<HeapNumber> maxV = factory->NewHeapNumber(max);
|
|
|
|
type->SetValue(1, minV);
|
|
|
|
type->SetValue(2, maxV);
|
2014-07-22 17:33:22 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static RangeHandle New(double min, double max, Region* region) {
|
|
|
|
TypeHandle bound = BitsetType::New(BitsetType::kNumber, region);
|
|
|
|
return New(min, max, bound, region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static RangeType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsRange());
|
|
|
|
return static_cast<RangeType*>(type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Context types.
|
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::ContextType : public StructuralType {
|
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeHandle Bound() { return this->Get(0); }
|
|
|
|
TypeHandle Outer() { return this->Get(1); }
|
2014-05-26 13:10:52 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static ContextHandle New(TypeHandle outer, TypeHandle bound, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(
|
|
|
|
bound->AsBitset(), BitsetType::kInternal & BitsetType::kTaggedPtr));
|
2014-05-26 13:10:52 +00:00
|
|
|
ContextHandle type = Config::template cast<ContextType>(
|
2014-05-27 13:52:31 +00:00
|
|
|
StructuralType::New(StructuralType::kContextTag, 2, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
type->Set(1, outer);
|
2014-05-26 13:10:52 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static ContextHandle New(TypeHandle outer, Region* region) {
|
|
|
|
TypeHandle bound = BitsetType::New(
|
|
|
|
BitsetType::kInternal & BitsetType::kTaggedPtr, region);
|
|
|
|
return New(outer, bound, region);
|
|
|
|
}
|
|
|
|
|
2014-05-26 13:10:52 +00:00
|
|
|
static ContextType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsContext());
|
|
|
|
return static_cast<ContextType*>(type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Array types.
|
2014-04-16 15:42:22 +00:00
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::ArrayType : public StructuralType {
|
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeHandle Bound() { return this->Get(0); }
|
|
|
|
TypeHandle Element() { return this->Get(1); }
|
2014-04-16 15:42:22 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static ArrayHandle New(TypeHandle element, TypeHandle bound, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kArray));
|
2014-04-16 16:16:37 +00:00
|
|
|
ArrayHandle type = Config::template cast<ArrayType>(
|
2014-05-27 13:52:31 +00:00
|
|
|
StructuralType::New(StructuralType::kArrayTag, 2, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
type->Set(1, element);
|
2014-04-16 16:16:37 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static ArrayHandle New(TypeHandle element, Region* region) {
|
|
|
|
TypeHandle bound = BitsetType::New(BitsetType::kArray, region);
|
|
|
|
return New(element, bound, region);
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static ArrayType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsArray());
|
|
|
|
return static_cast<ArrayType*>(type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Function types.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config>
|
|
|
|
class TypeImpl<Config>::FunctionType : public StructuralType {
|
|
|
|
public:
|
2014-05-27 13:52:31 +00:00
|
|
|
int Arity() { return this->Length() - 3; }
|
|
|
|
TypeHandle Bound() { return this->Get(0); }
|
|
|
|
TypeHandle Result() { return this->Get(1); }
|
|
|
|
TypeHandle Receiver() { return this->Get(2); }
|
|
|
|
TypeHandle Parameter(int i) { return this->Get(3 + i); }
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
void InitParameter(int i, TypeHandle type) { this->Set(3 + i, type); }
|
2014-04-16 16:16:37 +00:00
|
|
|
|
|
|
|
static FunctionHandle New(
|
2014-05-27 13:52:31 +00:00
|
|
|
TypeHandle result, TypeHandle receiver, TypeHandle bound,
|
|
|
|
int arity, Region* region) {
|
2014-07-23 17:17:48 +00:00
|
|
|
ASSERT(BitsetType::Is(bound->AsBitset(), BitsetType::kFunction));
|
2014-04-16 16:16:37 +00:00
|
|
|
FunctionHandle type = Config::template cast<FunctionType>(
|
2014-05-27 13:52:31 +00:00
|
|
|
StructuralType::New(StructuralType::kFunctionTag, 3 + arity, region));
|
|
|
|
type->Set(0, bound);
|
|
|
|
type->Set(1, result);
|
|
|
|
type->Set(2, receiver);
|
2014-04-16 16:16:37 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
static FunctionHandle New(
|
|
|
|
TypeHandle result, TypeHandle receiver, int arity, Region* region) {
|
|
|
|
TypeHandle bound = BitsetType::New(BitsetType::kFunction, region);
|
|
|
|
return New(result, receiver, bound, arity, region);
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
static FunctionType* cast(TypeImpl* type) {
|
|
|
|
ASSERT(type->IsFunction());
|
|
|
|
return static_cast<FunctionType*>(type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Type iterators.
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class Config> template<class T>
|
|
|
|
class TypeImpl<Config>::Iterator {
|
|
|
|
public:
|
|
|
|
bool Done() const { return index_ < 0; }
|
|
|
|
i::Handle<T> Current();
|
|
|
|
void Advance();
|
|
|
|
|
|
|
|
private:
|
|
|
|
template<class> friend class TypeImpl;
|
|
|
|
|
|
|
|
Iterator() : index_(-1) {}
|
|
|
|
explicit Iterator(TypeHandle type) : type_(type), index_(-1) {
|
|
|
|
Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool matches(TypeHandle type);
|
|
|
|
inline TypeHandle get_type();
|
|
|
|
|
|
|
|
TypeHandle type_;
|
|
|
|
int index_;
|
2013-06-05 15:43:53 +00:00
|
|
|
};
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Zone-allocated types; they are either (odd) integers to represent bitsets, or
|
2014-04-08 10:50:56 +00:00
|
|
|
// (even) pointers to structures for everything else.
|
2014-05-27 13:52:31 +00:00
|
|
|
|
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
|
|
|
struct ZoneTypeConfig {
|
|
|
|
typedef TypeImpl<ZoneTypeConfig> Type;
|
|
|
|
class Base {};
|
2014-04-08 10:50:56 +00:00
|
|
|
typedef void* Struct;
|
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
|
|
|
typedef i::Zone Region;
|
|
|
|
template<class T> struct Handle { typedef T* type; };
|
|
|
|
|
2014-07-22 17:33:22 +00:00
|
|
|
// TODO(neis): This will be removed again once we have struct_get_double().
|
|
|
|
static inline i::Isolate* isolate(Region* region) {
|
|
|
|
return region->isolate();
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class T> static inline T* handle(T* type);
|
|
|
|
template<class T> static inline T* cast(Type* type);
|
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline bool is_bitset(Type* type);
|
|
|
|
static inline bool is_class(Type* type);
|
2014-04-16 16:16:37 +00:00
|
|
|
static inline bool is_struct(Type* type, int tag);
|
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline int as_bitset(Type* type);
|
|
|
|
static inline i::Handle<i::Map> as_class(Type* type);
|
2014-05-27 13:52:31 +00:00
|
|
|
static inline Struct* as_struct(Type* type);
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline Type* from_bitset(int bitset);
|
|
|
|
static inline Type* from_bitset(int bitset, Zone* zone);
|
2014-05-27 13:52:31 +00:00
|
|
|
static inline Type* from_class(i::Handle<i::Map> map, Zone* zone);
|
2014-04-08 10:50:56 +00:00
|
|
|
static inline Type* from_struct(Struct* structured);
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-04-08 10:50:56 +00:00
|
|
|
static inline Struct* struct_create(int tag, int length, Zone* zone);
|
2014-05-27 13:52:31 +00:00
|
|
|
static inline void struct_shrink(Struct* structure, int length);
|
|
|
|
static inline int struct_tag(Struct* structure);
|
|
|
|
static inline int struct_length(Struct* structure);
|
|
|
|
static inline Type* struct_get(Struct* structure, int i);
|
|
|
|
static inline void struct_set(Struct* structure, int i, Type* type);
|
|
|
|
template<class V>
|
|
|
|
static inline i::Handle<V> struct_get_value(Struct* structure, int i);
|
|
|
|
template<class V> static inline void struct_set_value(
|
|
|
|
Struct* structure, int i, i::Handle<V> x);
|
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-04-01 13:11:12 +00:00
|
|
|
typedef TypeImpl<ZoneTypeConfig> Type;
|
|
|
|
|
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-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Heap-allocated types; either smis for bitsets, maps for classes, boxes for
|
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
|
|
|
// constants, or fixed arrays for unions.
|
2014-05-27 13:52:31 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
struct HeapTypeConfig {
|
|
|
|
typedef TypeImpl<HeapTypeConfig> Type;
|
|
|
|
typedef i::Object Base;
|
2014-04-08 10:50:56 +00:00
|
|
|
typedef i::FixedArray Struct;
|
2014-01-10 12:19:01 +00:00
|
|
|
typedef i::Isolate Region;
|
|
|
|
template<class T> struct Handle { typedef i::Handle<T> type; };
|
2014-01-09 17:12:48 +00:00
|
|
|
|
2014-07-22 17:33:22 +00:00
|
|
|
// TODO(neis): This will be removed again once we have struct_get_double().
|
|
|
|
static inline i::Isolate* isolate(Region* region) {
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:16:37 +00:00
|
|
|
template<class T> static inline i::Handle<T> handle(T* type);
|
|
|
|
template<class T> static inline i::Handle<T> cast(i::Handle<Type> type);
|
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline bool is_bitset(Type* type);
|
|
|
|
static inline bool is_class(Type* type);
|
2014-04-16 16:16:37 +00:00
|
|
|
static inline bool is_struct(Type* type, int tag);
|
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline int as_bitset(Type* type);
|
|
|
|
static inline i::Handle<i::Map> as_class(Type* type);
|
2014-04-08 10:50:56 +00:00
|
|
|
static inline i::Handle<Struct> as_struct(Type* type);
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-04-01 11:07:09 +00:00
|
|
|
static inline Type* from_bitset(int bitset);
|
|
|
|
static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate);
|
|
|
|
static inline i::Handle<Type> from_class(
|
2014-05-27 13:52:31 +00:00
|
|
|
i::Handle<i::Map> map, Isolate* isolate);
|
|
|
|
static inline i::Handle<Type> from_struct(i::Handle<Struct> structure);
|
2014-04-16 16:16:37 +00:00
|
|
|
|
2014-04-08 10:50:56 +00:00
|
|
|
static inline i::Handle<Struct> struct_create(
|
|
|
|
int tag, int length, Isolate* isolate);
|
2014-05-27 13:52:31 +00:00
|
|
|
static inline void struct_shrink(i::Handle<Struct> structure, int length);
|
|
|
|
static inline int struct_tag(i::Handle<Struct> structure);
|
|
|
|
static inline int struct_length(i::Handle<Struct> structure);
|
|
|
|
static inline i::Handle<Type> struct_get(i::Handle<Struct> structure, int i);
|
2014-04-08 10:50:56 +00:00
|
|
|
static inline void struct_set(
|
2014-05-27 13:52:31 +00:00
|
|
|
i::Handle<Struct> structure, int i, i::Handle<Type> type);
|
|
|
|
template<class V>
|
|
|
|
static inline i::Handle<V> struct_get_value(
|
|
|
|
i::Handle<Struct> structure, int i);
|
|
|
|
template<class V>
|
|
|
|
static inline void struct_set_value(
|
|
|
|
i::Handle<Struct> structure, int i, i::Handle<V> x);
|
2014-01-10 12:19:01 +00:00
|
|
|
};
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
typedef TypeImpl<HeapTypeConfig> HeapType;
|
2014-01-10 12:19:01 +00:00
|
|
|
|
|
|
|
|
2014-05-27 13:52:31 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Type bounds. A simple struct to represent a pair of lower/upper types.
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
struct BoundsImpl {
|
|
|
|
typedef TypeImpl<Config> Type;
|
|
|
|
typedef typename Type::TypeHandle TypeHandle;
|
|
|
|
typedef typename Type::Region Region;
|
|
|
|
|
|
|
|
TypeHandle lower;
|
|
|
|
TypeHandle upper;
|
|
|
|
|
|
|
|
BoundsImpl() {}
|
|
|
|
explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {}
|
|
|
|
BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) {
|
2013-10-14 12:14:42 +00:00
|
|
|
ASSERT(lower->Is(upper));
|
|
|
|
}
|
2013-07-11 11:47:05 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
// Unrestricted bounds.
|
2014-01-10 12:19:01 +00:00
|
|
|
static BoundsImpl Unbounded(Region* region) {
|
|
|
|
return BoundsImpl(Type::None(region), Type::Any(region));
|
2013-08-06 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
// Meet: both b1 and b2 are known to hold.
|
2014-01-10 12:19:01 +00:00
|
|
|
static BoundsImpl Both(BoundsImpl b1, BoundsImpl b2, Region* region) {
|
|
|
|
TypeHandle lower = Type::Union(b1.lower, b2.lower, region);
|
|
|
|
TypeHandle upper = Type::Intersect(b1.upper, b2.upper, region);
|
2013-10-14 12:14:42 +00:00
|
|
|
// Lower bounds are considered approximate, correct as necessary.
|
2014-01-10 12:19:01 +00:00
|
|
|
lower = Type::Intersect(lower, upper, region);
|
|
|
|
return BoundsImpl(lower, upper);
|
2013-07-11 11:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Join: either b1 or b2 is known to hold.
|
2014-01-10 12:19:01 +00:00
|
|
|
static BoundsImpl Either(BoundsImpl b1, BoundsImpl b2, Region* region) {
|
|
|
|
TypeHandle lower = Type::Intersect(b1.lower, b2.lower, region);
|
|
|
|
TypeHandle upper = Type::Union(b1.upper, b2.upper, region);
|
|
|
|
return BoundsImpl(lower, upper);
|
2013-07-11 11:47:05 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
static BoundsImpl NarrowLower(BoundsImpl b, TypeHandle t, Region* region) {
|
2013-10-14 12:14:42 +00:00
|
|
|
// Lower bounds are considered approximate, correct as necessary.
|
2014-01-10 12:19:01 +00:00
|
|
|
t = Type::Intersect(t, b.upper, region);
|
|
|
|
TypeHandle lower = Type::Union(b.lower, t, region);
|
|
|
|
return BoundsImpl(lower, b.upper);
|
2013-07-11 11:47:05 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
static BoundsImpl NarrowUpper(BoundsImpl b, TypeHandle t, Region* region) {
|
|
|
|
TypeHandle lower = Type::Intersect(b.lower, t, region);
|
|
|
|
TypeHandle upper = Type::Intersect(b.upper, t, region);
|
|
|
|
return BoundsImpl(lower, upper);
|
2013-07-11 11:47:05 +00:00
|
|
|
}
|
2014-02-19 10:52:06 +00:00
|
|
|
|
|
|
|
bool Narrows(BoundsImpl that) {
|
|
|
|
return that.lower->Is(this->lower) && this->upper->Is(that.upper);
|
|
|
|
}
|
2013-07-11 11:47:05 +00:00
|
|
|
};
|
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
typedef BoundsImpl<ZoneTypeConfig> Bounds;
|
2014-01-10 12:19:01 +00:00
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TYPES_H_
|