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

Side by Side Diff: src/types.h

Issue 17589013: Introduce Unsigned32 and RegExp types (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ic.cc ('k') | src/types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 30 matching lines...) Expand all
41 // obvious primitive types and some predefined unions, the type language also 41 // obvious primitive types and some predefined unions, the type language also
42 // can express class types (a.k.a. specific maps) and singleton types (i.e., 42 // can express class types (a.k.a. specific maps) and singleton types (i.e.,
43 // concrete constants). 43 // concrete constants).
44 // 44 //
45 // The following equations and inequations hold: 45 // The following equations and inequations hold:
46 // 46 //
47 // None <= T 47 // None <= T
48 // T <= Any 48 // T <= Any
49 // 49 //
50 // Oddball = Boolean \/ Null \/ Undefined 50 // Oddball = Boolean \/ Null \/ Undefined
51 // Number = Integer32 \/ Double 51 // Number = Signed32 \/ Unsigned32 \/ Double
52 // Integer31 < Integer32 52 // Smi <= Signed32
53 // Name = String \/ Symbol 53 // Name = String \/ Symbol
54 // UniqueName = InternalizedString \/ Symbol 54 // UniqueName = InternalizedString \/ Symbol
55 // InternalizedString < String 55 // InternalizedString < String
56 // 56 //
57 // Allocated = Receiver \/ Number \/ Name 57 // Allocated = Receiver \/ Number \/ Name
58 // Detectable = Allocated - Undetectable 58 // Detectable = Allocated - Undetectable
59 // Undetectable < Object 59 // Undetectable < Object
60 // Receiver = Object \/ Proxy 60 // Receiver = Object \/ Proxy
61 // Array < Object 61 // Array < Object
62 // Function < Object 62 // Function < Object
63 // RegExp < Object
63 // 64 //
64 // Class(map) < T iff instance_type(map) < T 65 // Class(map) < T iff instance_type(map) < T
65 // Constant(x) < T iff instance_type(map(x)) < T 66 // Constant(x) < T iff instance_type(map(x)) < T
66 // 67 //
67 // Note that Constant(x) < Class(map(x)) does _not_ hold, since x's map can 68 // Note that Constant(x) < Class(map(x)) does _not_ hold, since x's map can
68 // change! (Its instance type cannot, however.) 69 // change! (Its instance type cannot, however.)
69 // TODO(rossberg): the latter is not currently true for proxies, because of fix, 70 // TODO(rossberg): the latter is not currently true for proxies, because of fix,
70 // but will hold once we implement direct proxies. 71 // but will hold once we implement direct proxies.
71 // 72 //
72 // There are two main functions for testing types: 73 // There are two main functions for testing types:
73 // 74 //
74 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2) 75 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2)
75 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0) 76 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0)
76 // 77 //
77 // Typically, the former is to be used to select representations (e.g., via 78 // Typically, the former is to be used to select representations (e.g., via
78 // T->Is(Integer31())), and the to check whether a specific case needs handling 79 // T->Is(Integer31())), and the to check whether a specific case needs handling
79 // (e.g., via T->Maybe(Number())). 80 // (e.g., via T->Maybe(Number())).
80 // 81 //
81 // There is no functionality to discover whether a type is a leaf in the 82 // 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 83 // lattice. That is intentional. It should always be possible to refine the
83 // lattice (e.g., splitting up number types further) without invalidating any 84 // lattice (e.g., splitting up number types further) without invalidating any
84 // existing assumptions or tests. 85 // existing assumptions or tests.
85 // 86 //
87 // Consequently, do not use pointer equality for type tests, always use Is!
88 //
86 // Internally, all 'primitive' types, and their unions, are represented as 89 // Internally, all 'primitive' types, and their unions, are represented as
87 // bitsets via smis. Class is a heap pointer to the respective map. Only 90 // 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. 91 // 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. 92 // Note that the bitset representation is closed under both Union and Intersect.
90 // 93 //
91 // The type representation is heap-allocated, so cannot (currently) be used in 94 // The type representation is heap-allocated, so cannot (currently) be used in
92 // a parallel compilation context. 95 // a parallel compilation context.
93 96
94 class Type : public Object { 97 class Type : public Object {
95 public: 98 public:
96 static Type* None() { return from_bitset(kNone); } 99 static Type* None() { return from_bitset(kNone); }
97 static Type* Any() { return from_bitset(kAny); } 100 static Type* Any() { return from_bitset(kAny); }
98 static Type* Allocated() { return from_bitset(kAllocated); } 101 static Type* Allocated() { return from_bitset(kAllocated); }
99 static Type* Detectable() { return from_bitset(kDetectable); } 102 static Type* Detectable() { return from_bitset(kDetectable); }
100 103
101 static Type* Oddball() { return from_bitset(kOddball); } 104 static Type* Oddball() { return from_bitset(kOddball); }
102 static Type* Boolean() { return from_bitset(kBoolean); } 105 static Type* Boolean() { return from_bitset(kBoolean); }
103 static Type* Null() { return from_bitset(kNull); } 106 static Type* Null() { return from_bitset(kNull); }
104 static Type* Undefined() { return from_bitset(kUndefined); } 107 static Type* Undefined() { return from_bitset(kUndefined); }
105 108
106 static Type* Number() { return from_bitset(kNumber); } 109 static Type* Number() { return from_bitset(kNumber); }
107 static Type* Integer31() { return from_bitset(kInteger31); } 110 static Type* Smi() { return from_bitset(kSmi); }
108 static Type* Integer32() { return from_bitset(kInteger32); } 111 static Type* Signed32() { return from_bitset(kSigned32); }
112 static Type* Unsigned32() { return from_bitset(kUnsigned32); }
109 static Type* Double() { return from_bitset(kDouble); } 113 static Type* Double() { return from_bitset(kDouble); }
114 static Type* NumberOrString() { return from_bitset(kNumberOrString); }
110 115
111 static Type* Name() { return from_bitset(kName); } 116 static Type* Name() { return from_bitset(kName); }
112 static Type* UniqueName() { return from_bitset(kUniqueName); } 117 static Type* UniqueName() { return from_bitset(kUniqueName); }
113 static Type* String() { return from_bitset(kString); } 118 static Type* String() { return from_bitset(kString); }
114 static Type* InternalizedString() { return from_bitset(kInternalizedString); } 119 static Type* InternalizedString() { return from_bitset(kInternalizedString); }
115 static Type* Symbol() { return from_bitset(kSymbol); } 120 static Type* Symbol() { return from_bitset(kSymbol); }
116 121
117 static Type* Receiver() { return from_bitset(kReceiver); } 122 static Type* Receiver() { return from_bitset(kReceiver); }
118 static Type* Object() { return from_bitset(kObject); } 123 static Type* Object() { return from_bitset(kObject); }
119 static Type* Undetectable() { return from_bitset(kUndetectable); } 124 static Type* Undetectable() { return from_bitset(kUndetectable); }
120 static Type* Array() { return from_bitset(kArray); } 125 static Type* Array() { return from_bitset(kArray); }
121 static Type* Function() { return from_bitset(kFunction); } 126 static Type* Function() { return from_bitset(kFunction); }
127 static Type* RegExp() { return from_bitset(kRegExp); }
122 static Type* Proxy() { return from_bitset(kProxy); } 128 static Type* Proxy() { return from_bitset(kProxy); }
123 129
124 static Type* Class(Handle<Map> map) { return from_handle(map); } 130 static Type* Class(Handle<Map> map) { return from_handle(map); }
125 static Type* Constant(Handle<HeapObject> value) { 131 static Type* Constant(Handle<HeapObject> value) {
126 return Constant(value, value->GetIsolate()); 132 return Constant(value, value->GetIsolate());
127 } 133 }
128 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { 134 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) {
129 return from_handle(isolate->factory()->NewBox(value)); 135 return from_handle(isolate->factory()->NewBox(value));
130 } 136 }
131 137
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // A union is a fixed array containing types. Invariants: 187 // A union is a fixed array containing types. Invariants:
182 // - its length is at least 2 188 // - its length is at least 2
183 // - at most one field is a bitset, and it must go into index 0 189 // - at most one field is a bitset, and it must go into index 0
184 // - no field is a union 190 // - no field is a union
185 typedef FixedArray Unioned; 191 typedef FixedArray Unioned;
186 192
187 enum { 193 enum {
188 kNull = 1 << 0, 194 kNull = 1 << 0,
189 kUndefined = 1 << 1, 195 kUndefined = 1 << 1,
190 kBoolean = 1 << 2, 196 kBoolean = 1 << 2,
191 kInteger31 = 1 << 3, 197 kSmi = 1 << 3,
192 kOtherInteger = 1 << 4, 198 kOtherSigned32 = 1 << 4,
193 kDouble = 1 << 5, 199 kUnsigned32 = 1 << 5,
194 kSymbol = 1 << 6, 200 kDouble = 1 << 6,
195 kInternalizedString = 1 << 7, 201 kSymbol = 1 << 7,
196 kOtherString = 1 << 8, 202 kInternalizedString = 1 << 8,
197 kUndetectable = 1 << 9, 203 kOtherString = 1 << 9,
198 kArray = 1 << 10, 204 kUndetectable = 1 << 10,
199 kFunction = 1 << 11, 205 kArray = 1 << 11,
200 kOtherObject = 1 << 12, 206 kFunction = 1 << 12,
201 kProxy = 1 << 13, 207 kRegExp = 1 << 13,
208 kOtherObject = 1 << 14,
209 kProxy = 1 << 15,
202 210
203 kOddball = kBoolean | kNull | kUndefined, 211 kOddball = kBoolean | kNull | kUndefined,
204 kInteger32 = kInteger31 | kOtherInteger, 212 kSigned32 = kSmi | kOtherSigned32,
205 kNumber = kInteger32 | kDouble, 213 kNumber = kSigned32 | kUnsigned32 | kDouble,
206 kString = kInternalizedString | kOtherString, 214 kString = kInternalizedString | kOtherString,
207 kUniqueName = kSymbol | kInternalizedString, 215 kUniqueName = kSymbol | kInternalizedString,
208 kName = kSymbol | kString, 216 kName = kSymbol | kString,
209 kObject = kUndetectable | kArray | kFunction | kOtherObject, 217 kNumberOrString = kNumber | kString,
218 kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject,
210 kReceiver = kObject | kProxy, 219 kReceiver = kObject | kProxy,
211 kAllocated = kDouble | kName | kReceiver, 220 kAllocated = kDouble | kName | kReceiver,
212 kAny = kOddball | kNumber | kAllocated, 221 kAny = kOddball | kNumber | kAllocated,
213 kDetectable = kAllocated - kUndetectable, 222 kDetectable = kAllocated - kUndetectable,
214 kNone = 0 223 kNone = 0
215 }; 224 };
216 225
217 bool is_bitset() { return this->IsSmi(); } 226 bool is_bitset() { return this->IsSmi(); }
218 bool is_class() { return this->IsMap(); } 227 bool is_class() { return this->IsMap(); }
219 bool is_constant() { return this->IsBox(); } 228 bool is_constant() { return this->IsBox(); }
(...skipping 30 matching lines...) Expand all
250 int GlbBitset(); // greatest lower bound that's a bitset 259 int GlbBitset(); // greatest lower bound that's a bitset
251 bool InUnion(Handle<Unioned> unioned, int current_size); 260 bool InUnion(Handle<Unioned> unioned, int current_size);
252 int ExtendUnion(Handle<Unioned> unioned, int current_size); 261 int ExtendUnion(Handle<Unioned> unioned, int current_size);
253 int ExtendIntersection( 262 int ExtendIntersection(
254 Handle<Unioned> unioned, Handle<Type> type, int current_size); 263 Handle<Unioned> unioned, Handle<Type> type, int current_size);
255 }; 264 };
256 265
257 } } // namespace v8::internal 266 } } // namespace v8::internal
258 267
259 #endif // V8_TYPES_H_ 268 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/ic.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698