OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // (e.g., via T->Maybe(Number())). | 79 // (e.g., via T->Maybe(Number())). |
80 // | 80 // |
81 // There is no functionality to discover whether a type is a leaf in the | 81 // There is no functionality to discover whether a type is a leaf in the |
82 // lattice. That is intentional. It should always be possible to refine the | 82 // lattice. That is intentional. It should always be possible to refine the |
83 // lattice (e.g., splitting up number types further) without invalidating any | 83 // lattice (e.g., splitting up number types further) without invalidating any |
84 // existing assumptions or tests. | 84 // existing assumptions or tests. |
85 // | 85 // |
86 // Internally, all 'primitive' types, and their unions, are represented as | 86 // Internally, all 'primitive' types, and their unions, are represented as |
87 // bitsets via smis. Class is a heap pointer to the respective map. Only | 87 // bitsets via smis. Class is a heap pointer to the respective map. Only |
88 // Constant's, or unions containing Class'es or Constant's, require allocation. | 88 // Constant's, or unions containing Class'es or Constant's, require allocation. |
| 89 // Note that the bitset representation is closed under both Union and Intersect. |
89 // | 90 // |
90 // The type representation is heap-allocated, so cannot (currently) be used in | 91 // The type representation is heap-allocated, so cannot (currently) be used in |
91 // a parallel compilation context. | 92 // a parallel compilation context. |
92 | 93 |
93 class Type : public Object { | 94 class Type : public Object { |
94 public: | 95 public: |
95 static Type* None() { return from_bitset(kNone); } | 96 static Type* None() { return from_bitset(kNone); } |
96 static Type* Any() { return from_bitset(kAny); } | 97 static Type* Any() { return from_bitset(kAny); } |
97 static Type* Allocated() { return from_bitset(kAllocated); } | 98 static Type* Allocated() { return from_bitset(kAllocated); } |
98 static Type* Detectable() { return from_bitset(kDetectable); } | 99 static Type* Detectable() { return from_bitset(kDetectable); } |
(...skipping 23 matching lines...) Expand all Loading... |
122 | 123 |
123 static Type* Class(Handle<Map> map) { return from_handle(map); } | 124 static Type* Class(Handle<Map> map) { return from_handle(map); } |
124 static Type* Constant(Handle<HeapObject> value) { | 125 static Type* Constant(Handle<HeapObject> value) { |
125 return Constant(value, value->GetIsolate()); | 126 return Constant(value, value->GetIsolate()); |
126 } | 127 } |
127 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { | 128 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { |
128 return from_handle(isolate->factory()->NewBox(value)); | 129 return from_handle(isolate->factory()->NewBox(value)); |
129 } | 130 } |
130 | 131 |
131 static Type* Union(Handle<Type> type1, Handle<Type> type2); | 132 static Type* Union(Handle<Type> type1, Handle<Type> type2); |
| 133 static Type* Intersect(Handle<Type> type1, Handle<Type> type2); |
132 static Type* Optional(Handle<Type> type); // type \/ Undefined | 134 static Type* Optional(Handle<Type> type); // type \/ Undefined |
133 | 135 |
134 bool Is(Type* that); | 136 bool Is(Type* that); |
135 bool Is(Handle<Type> that) { return this->Is(*that); } | 137 bool Is(Handle<Type> that) { return this->Is(*that); } |
136 bool Maybe(Type* that); | 138 bool Maybe(Type* that); |
137 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } | 139 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } |
138 | 140 |
139 bool IsClass() { return is_class(); } | 141 bool IsClass() { return is_class(); } |
140 bool IsConstant() { return is_constant(); } | 142 bool IsConstant() { return is_constant(); } |
141 Handle<Map> AsClass() { return as_class(); } | 143 Handle<Map> AsClass() { return as_class(); } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 static Handle<Type> union_get(Handle<Unioned> unioned, int i) { | 243 static Handle<Type> union_get(Handle<Unioned> unioned, int i) { |
242 Type* type = static_cast<Type*>(unioned->get(i)); | 244 Type* type = static_cast<Type*>(unioned->get(i)); |
243 ASSERT(!type->is_union()); | 245 ASSERT(!type->is_union()); |
244 return type->handle_via_isolate_of(from_handle(unioned)); | 246 return type->handle_via_isolate_of(from_handle(unioned)); |
245 } | 247 } |
246 | 248 |
247 int LubBitset(); // least upper bound that's a bitset | 249 int LubBitset(); // least upper bound that's a bitset |
248 int GlbBitset(); // greatest lower bound that's a bitset | 250 int GlbBitset(); // greatest lower bound that's a bitset |
249 bool InUnion(Handle<Unioned> unioned, int current_size); | 251 bool InUnion(Handle<Unioned> unioned, int current_size); |
250 int ExtendUnion(Handle<Unioned> unioned, int current_size); | 252 int ExtendUnion(Handle<Unioned> unioned, int current_size); |
| 253 int ExtendIntersection( |
| 254 Handle<Unioned> unioned, Handle<Type> type, int current_size); |
251 }; | 255 }; |
252 | 256 |
253 } } // namespace v8::internal | 257 } } // namespace v8::internal |
254 | 258 |
255 #endif // V8_TYPES_H_ | 259 #endif // V8_TYPES_H_ |
OLD | NEW |