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

Side by Side Diff: test/cctest/test-types.cc

Issue 133683002: Retry "Templatise type representation" after making clang happy (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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/typing.cc ('k') | no next file » | 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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "cctest.h" 28 #include "cctest.h"
29 #include "types.h" 29 #include "types.h"
30 30
31 using namespace v8::internal; 31 using namespace v8::internal;
32 32
33 // Testing auxiliaries (breaking the Type abstraction). 33 // Testing auxiliaries (breaking the Type abstraction).
34 static bool IsBitset(Type* type) { return type->IsSmi(); } 34 static bool IsBitset(Handle<Type> t) { return t->IsSmi(); }
35 static bool IsClass(Type* type) { return type->IsMap(); } 35 static bool IsClass(Handle<Type> t) { return t->IsMap(); }
36 static bool IsConstant(Type* type) { return type->IsBox(); } 36 static bool IsConstant(Handle<Type> t) { return t->IsBox(); }
37 static bool IsUnion(Type* type) { return type->IsFixedArray(); } 37 static bool IsUnion(Handle<Type> t) { return t->IsFixedArray(); }
38 38
39 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } 39 static int AsBitset(Handle<Type> t) { return Smi::cast(*t)->value(); }
40 static Map* AsClass(Type* type) { return Map::cast(type); } 40 static Map* AsClass(Handle<Type> t) { return Map::cast(*t); }
41 static Object* AsConstant(Type* type) { return Box::cast(type)->value(); } 41 static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
42 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } 42 static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
43 43
44 44
45 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { 45 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) {
46 CHECK_EQ(IsBitset(*type1), IsBitset(*type2)); 46 CHECK_EQ(IsBitset(type1), IsBitset(type2));
47 CHECK_EQ(IsClass(*type1), IsClass(*type2)); 47 CHECK_EQ(IsClass(type1), IsClass(type2));
48 CHECK_EQ(IsConstant(*type1), IsConstant(*type2)); 48 CHECK_EQ(IsConstant(type1), IsConstant(type2));
49 CHECK_EQ(IsUnion(*type1), IsUnion(*type2)); 49 CHECK_EQ(IsUnion(type1), IsUnion(type2));
50 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); 50 CHECK_EQ(type1->NumClasses(), type2->NumClasses());
51 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); 51 CHECK_EQ(type1->NumConstants(), type2->NumConstants());
52 if (IsBitset(*type1)) { 52 if (IsBitset(type1)) {
53 CHECK_EQ(AsBitset(*type1), AsBitset(*type2)); 53 CHECK_EQ(AsBitset(type1), AsBitset(type2));
54 } else if (IsClass(*type1)) { 54 } else if (IsClass(type1)) {
55 CHECK_EQ(AsClass(*type1), AsClass(*type2)); 55 CHECK_EQ(AsClass(type1), AsClass(type2));
56 } else if (IsConstant(*type1)) { 56 } else if (IsConstant(type1)) {
57 CHECK_EQ(AsConstant(*type1), AsConstant(*type2)); 57 CHECK_EQ(AsConstant(type1), AsConstant(type2));
58 } else if (IsUnion(*type1)) { 58 } else if (IsUnion(type1)) {
59 CHECK_EQ(AsUnion(*type1)->length(), AsUnion(*type2)->length()); 59 CHECK_EQ(AsUnion(type1)->length(), AsUnion(type2)->length());
60 } 60 }
61 CHECK(type1->Is(type2)); 61 CHECK(type1->Is(type2));
62 CHECK(type2->Is(type1)); 62 CHECK(type2->Is(type1));
63 } 63 }
64 64
65 65
66 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { 66 static void CheckSub(Handle<Type> type1, Handle<Type> type2) {
67 CHECK(type1->Is(type2)); 67 CHECK(type1->Is(type2));
68 CHECK(!type2->Is(type1)); 68 CHECK(!type2->Is(type1));
69 if (IsBitset(*type1) && IsBitset(*type2)) { 69 if (IsBitset(type1) && IsBitset(type2)) {
70 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); 70 CHECK_NE(AsBitset(type1), AsBitset(type2));
71 } 71 }
72 } 72 }
73 73
74 74
75 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { 75 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) {
76 CHECK(!type1->Is(type2)); 76 CHECK(!type1->Is(type2));
77 CHECK(!type2->Is(type1)); 77 CHECK(!type2->Is(type1));
78 if (IsBitset(*type1) && IsBitset(*type2)) { 78 if (IsBitset(type1) && IsBitset(type2)) {
79 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); 79 CHECK_NE(AsBitset(type1), AsBitset(type2));
80 } 80 }
81 } 81 }
82 82
83 83
84 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { 84 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) {
85 CHECK(type1->Maybe(type2)); 85 CHECK(type1->Maybe(type2));
86 CHECK(type2->Maybe(type1)); 86 CHECK(type2->Maybe(type1));
87 if (IsBitset(*type1) && IsBitset(*type2)) { 87 if (IsBitset(type1) && IsBitset(type2)) {
88 CHECK_NE(0, AsBitset(*type1) & AsBitset(*type2)); 88 CHECK_NE(0, AsBitset(type1) & AsBitset(type2));
89 } 89 }
90 } 90 }
91 91
92 92
93 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { 93 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) {
94 CHECK(!type1->Is(type2)); 94 CHECK(!type1->Is(type2));
95 CHECK(!type2->Is(type1)); 95 CHECK(!type2->Is(type1));
96 CHECK(!type1->Maybe(type2)); 96 CHECK(!type1->Maybe(type2));
97 CHECK(!type2->Maybe(type1)); 97 CHECK(!type2->Maybe(type1));
98 if (IsBitset(*type1) && IsBitset(*type2)) { 98 if (IsBitset(type1) && IsBitset(type2)) {
99 CHECK_EQ(0, AsBitset(*type1) & AsBitset(*type2)); 99 CHECK_EQ(0, AsBitset(type1) & AsBitset(type2));
100 } 100 }
101 } 101 }
102 102
103 103
104 class HandlifiedTypes { 104 class HandlifiedTypes {
105 public: 105 public:
106 explicit HandlifiedTypes(Isolate* isolate) : 106 explicit HandlifiedTypes(Isolate* isolate) :
107 None(Type::None(), isolate), 107 None(Type::None(isolate)),
108 Any(Type::Any(), isolate), 108 Any(Type::Any(isolate)),
109 Oddball(Type::Oddball(), isolate), 109 Oddball(Type::Oddball(isolate)),
110 Boolean(Type::Boolean(), isolate), 110 Boolean(Type::Boolean(isolate)),
111 Null(Type::Null(), isolate), 111 Null(Type::Null(isolate)),
112 Undefined(Type::Undefined(), isolate), 112 Undefined(Type::Undefined(isolate)),
113 Number(Type::Number(), isolate), 113 Number(Type::Number(isolate)),
114 Smi(Type::Smi(), isolate), 114 Smi(Type::Smi(isolate)),
115 Signed32(Type::Signed32(), isolate), 115 Signed32(Type::Signed32(isolate)),
116 Double(Type::Double(), isolate), 116 Double(Type::Double(isolate)),
117 Name(Type::Name(), isolate), 117 Name(Type::Name(isolate)),
118 UniqueName(Type::UniqueName(), isolate), 118 UniqueName(Type::UniqueName(isolate)),
119 String(Type::String(), isolate), 119 String(Type::String(isolate)),
120 InternalizedString(Type::InternalizedString(), isolate), 120 InternalizedString(Type::InternalizedString(isolate)),
121 Symbol(Type::Symbol(), isolate), 121 Symbol(Type::Symbol(isolate)),
122 Receiver(Type::Receiver(), isolate), 122 Receiver(Type::Receiver(isolate)),
123 Object(Type::Object(), isolate), 123 Object(Type::Object(isolate)),
124 Array(Type::Array(), isolate), 124 Array(Type::Array(isolate)),
125 Function(Type::Function(), isolate), 125 Function(Type::Function(isolate)),
126 Proxy(Type::Proxy(), isolate), 126 Proxy(Type::Proxy(isolate)),
127 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), 127 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)),
128 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), 128 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)),
129 isolate_(isolate) { 129 isolate_(isolate) {
130 smi = handle(Smi::FromInt(666), isolate); 130 smi = handle(Smi::FromInt(666), isolate);
131 signed32 = isolate->factory()->NewHeapNumber(0x40000000); 131 signed32 = isolate->factory()->NewHeapNumber(0x40000000);
132 object1 = isolate->factory()->NewJSObjectFromMap(object_map); 132 object1 = isolate->factory()->NewJSObjectFromMap(object_map);
133 object2 = isolate->factory()->NewJSObjectFromMap(object_map); 133 object2 = isolate->factory()->NewJSObjectFromMap(object_map);
134 array = isolate->factory()->NewJSArray(20); 134 array = isolate->factory()->NewJSArray(20);
135 ObjectClass = Class(object_map); 135 ObjectClass = Type::Class(object_map, isolate);
136 ArrayClass = Class(array_map); 136 ArrayClass = Type::Class(array_map, isolate);
137 SmiConstant = Constant(smi); 137 SmiConstant = Type::Constant(smi, isolate);
138 Signed32Constant = Constant(signed32); 138 Signed32Constant = Type::Constant(signed32, isolate);
139 ObjectConstant1 = Constant(object1); 139 ObjectConstant1 = Type::Constant(object1, isolate);
140 ObjectConstant2 = Constant(object2); 140 ObjectConstant2 = Type::Constant(object2, isolate);
141 ArrayConstant1 = Constant(array); 141 ArrayConstant1 = Type::Constant(array, isolate);
142 ArrayConstant2 = Constant(array); 142 ArrayConstant2 = Type::Constant(array, isolate);
143 } 143 }
144 144
145 Handle<Type> None; 145 Handle<Type> None;
146 Handle<Type> Any; 146 Handle<Type> Any;
147 Handle<Type> Oddball; 147 Handle<Type> Oddball;
148 Handle<Type> Boolean; 148 Handle<Type> Boolean;
149 Handle<Type> Null; 149 Handle<Type> Null;
150 Handle<Type> Undefined; 150 Handle<Type> Undefined;
151 Handle<Type> Number; 151 Handle<Type> Number;
152 Handle<Type> Smi; 152 Handle<Type> Smi;
(...skipping 22 matching lines...) Expand all
175 175
176 Handle<Map> object_map; 176 Handle<Map> object_map;
177 Handle<Map> array_map; 177 Handle<Map> array_map;
178 178
179 Handle<i::Smi> smi; 179 Handle<i::Smi> smi;
180 Handle<HeapNumber> signed32; 180 Handle<HeapNumber> signed32;
181 Handle<JSObject> object1; 181 Handle<JSObject> object1;
182 Handle<JSObject> object2; 182 Handle<JSObject> object2;
183 Handle<JSArray> array; 183 Handle<JSArray> array;
184 184
185 Handle<Type> Class(Handle<Map> map) { 185 Handle<Type> Union(Handle<Type> t1, Handle<Type> t2) {
186 return handle(Type::Class(map), isolate_); 186 return Type::Union(t1, t2, isolate_);
187 } 187 }
188 Handle<Type> Constant(Handle<i::Object> value) { 188 Handle<Type> Intersect(Handle<Type> t1, Handle<Type> t2) {
189 return handle(Type::Constant(value, isolate_), isolate_); 189 return Type::Intersect(t1, t2, isolate_);
190 }
191 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) {
192 return handle(Type::Union(type1, type2), isolate_);
193 }
194 Handle<Type> Intersect(Handle<Type> type1, Handle<Type> type2) {
195 return handle(Type::Intersect(type1, type2), isolate_);
196 } 190 }
197 191
198 private: 192 private:
199 Isolate* isolate_; 193 Isolate* isolate_;
200 }; 194 };
201 195
202 196
203 TEST(Bitset) { 197 TEST(Bitset) {
204 CcTest::InitializeVM(); 198 CcTest::InitializeVM();
205 Isolate* isolate = CcTest::i_isolate(); 199 Isolate* isolate = CcTest::i_isolate();
206 HandleScope scope(isolate); 200 HandleScope scope(isolate);
207 HandlifiedTypes T(isolate); 201 HandlifiedTypes T(isolate);
208 202
209 CHECK(IsBitset(*T.None)); 203 CHECK(IsBitset(T.None));
210 CHECK(IsBitset(*T.Any)); 204 CHECK(IsBitset(T.Any));
211 CHECK(IsBitset(*T.String)); 205 CHECK(IsBitset(T.String));
212 CHECK(IsBitset(*T.Object)); 206 CHECK(IsBitset(T.Object));
213 207
214 CHECK(IsBitset(Type::Union(T.String, T.Number))); 208 CHECK(IsBitset(T.Union(T.String, T.Number)));
215 CHECK(IsBitset(Type::Union(T.String, T.Receiver))); 209 CHECK(IsBitset(T.Union(T.String, T.Receiver)));
216 CHECK(IsBitset(Type::Optional(T.Object)));
217 210
218 CHECK_EQ(0, AsBitset(*T.None)); 211 CHECK_EQ(0, AsBitset(T.None));
219 CHECK_EQ(AsBitset(*T.Number) | AsBitset(*T.String), 212 CHECK_EQ(AsBitset(T.Number) | AsBitset(T.String),
220 AsBitset(Type::Union(T.String, T.Number))); 213 AsBitset(T.Union(T.String, T.Number)));
221 CHECK_EQ(AsBitset(*T.Receiver), 214 CHECK_EQ(AsBitset(T.Receiver),
222 AsBitset(Type::Union(T.Receiver, T.Object))); 215 AsBitset(T.Union(T.Receiver, T.Object)));
223 CHECK_EQ(AsBitset(*T.String) | AsBitset(*T.Undefined),
224 AsBitset(Type::Optional(T.String)));
225 } 216 }
226 217
227 218
228 TEST(Class) { 219 TEST(Class) {
229 CcTest::InitializeVM(); 220 CcTest::InitializeVM();
230 Isolate* isolate = CcTest::i_isolate(); 221 Isolate* isolate = CcTest::i_isolate();
231 HandleScope scope(isolate); 222 HandleScope scope(isolate);
232 HandlifiedTypes T(isolate); 223 HandlifiedTypes T(isolate);
233 224
234 CHECK(IsClass(*T.ObjectClass)); 225 CHECK(IsClass(T.ObjectClass));
235 CHECK(IsClass(*T.ArrayClass)); 226 CHECK(IsClass(T.ArrayClass));
236 227
237 CHECK(*T.object_map == AsClass(*T.ObjectClass)); 228 CHECK(*T.object_map == AsClass(T.ObjectClass));
238 CHECK(*T.array_map == AsClass(*T.ArrayClass)); 229 CHECK(*T.array_map == AsClass(T.ArrayClass));
239 } 230 }
240 231
241 232
242 TEST(Constant) { 233 TEST(Constant) {
243 CcTest::InitializeVM(); 234 CcTest::InitializeVM();
244 Isolate* isolate = CcTest::i_isolate(); 235 Isolate* isolate = CcTest::i_isolate();
245 HandleScope scope(isolate); 236 HandleScope scope(isolate);
246 HandlifiedTypes T(isolate); 237 HandlifiedTypes T(isolate);
247 238
248 CHECK(IsConstant(*T.SmiConstant)); 239 CHECK(IsConstant(T.SmiConstant));
249 CHECK(IsConstant(*T.ObjectConstant1)); 240 CHECK(IsConstant(T.ObjectConstant1));
250 CHECK(IsConstant(*T.ObjectConstant2)); 241 CHECK(IsConstant(T.ObjectConstant2));
251 CHECK(IsConstant(*T.ArrayConstant1)); 242 CHECK(IsConstant(T.ArrayConstant1));
252 CHECK(IsConstant(*T.ArrayConstant2)); 243 CHECK(IsConstant(T.ArrayConstant2));
253 244
254 CHECK(*T.smi == AsConstant(*T.SmiConstant)); 245 CHECK(*T.smi == AsConstant(T.SmiConstant));
255 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); 246 CHECK(*T.object1 == AsConstant(T.ObjectConstant1));
256 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); 247 CHECK(*T.object2 == AsConstant(T.ObjectConstant2));
257 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); 248 CHECK(*T.object1 != AsConstant(T.ObjectConstant2));
258 CHECK(*T.array == AsConstant(*T.ArrayConstant1)); 249 CHECK(*T.array == AsConstant(T.ArrayConstant1));
259 CHECK(*T.array == AsConstant(*T.ArrayConstant2)); 250 CHECK(*T.array == AsConstant(T.ArrayConstant2));
260 } 251 }
261 252
262 253
263 TEST(Is) { 254 TEST(Is) {
264 CcTest::InitializeVM(); 255 CcTest::InitializeVM();
265 Isolate* isolate = CcTest::i_isolate(); 256 Isolate* isolate = CcTest::i_isolate();
266 HandleScope scope(isolate); 257 HandleScope scope(isolate);
267 HandlifiedTypes T(isolate); 258 HandlifiedTypes T(isolate);
268 259
269 // Reflexivity 260 // Reflexivity
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 410 }
420 411
421 412
422 TEST(Union) { 413 TEST(Union) {
423 CcTest::InitializeVM(); 414 CcTest::InitializeVM();
424 Isolate* isolate = CcTest::i_isolate(); 415 Isolate* isolate = CcTest::i_isolate();
425 HandleScope scope(isolate); 416 HandleScope scope(isolate);
426 HandlifiedTypes T(isolate); 417 HandlifiedTypes T(isolate);
427 418
428 // Bitset-bitset 419 // Bitset-bitset
429 CHECK(IsBitset(Type::Union(T.Object, T.Number))); 420 CHECK(IsBitset(T.Union(T.Object, T.Number)));
430 CHECK(IsBitset(Type::Union(T.Object, T.Object))); 421 CHECK(IsBitset(T.Union(T.Object, T.Object)));
431 CHECK(IsBitset(Type::Union(T.Any, T.None))); 422 CHECK(IsBitset(T.Union(T.Any, T.None)));
432 423
433 CheckEqual(T.Union(T.None, T.Number), T.Number); 424 CheckEqual(T.Union(T.None, T.Number), T.Number);
434 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver); 425 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver);
435 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number)); 426 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number));
436 CheckSub(T.Union(T.Number, T.String), T.Any); 427 CheckSub(T.Union(T.Number, T.String), T.Any);
437 428
438 // Class-class 429 // Class-class
439 CHECK(IsClass(Type::Union(T.ObjectClass, T.ObjectClass))); 430 CHECK(IsClass(T.Union(T.ObjectClass, T.ObjectClass)));
440 CHECK(IsUnion(Type::Union(T.ObjectClass, T.ArrayClass))); 431 CHECK(IsUnion(T.Union(T.ObjectClass, T.ArrayClass)));
441 432
442 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); 433 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass);
443 CheckSub(T.None, T.Union(T.ObjectClass, T.ArrayClass)); 434 CheckSub(T.None, T.Union(T.ObjectClass, T.ArrayClass));
444 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Any); 435 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Any);
445 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); 436 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass));
446 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); 437 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass));
447 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); 438 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object);
448 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); 439 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array);
449 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); 440 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array);
450 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); 441 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number);
451 442
452 // Constant-constant 443 // Constant-constant
453 CHECK(IsConstant(Type::Union(T.ObjectConstant1, T.ObjectConstant1))); 444 CHECK(IsConstant(T.Union(T.ObjectConstant1, T.ObjectConstant1)));
454 CHECK(IsConstant(Type::Union(T.ArrayConstant1, T.ArrayConstant1))); 445 CHECK(IsConstant(T.Union(T.ArrayConstant1, T.ArrayConstant1)));
455 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectConstant2))); 446 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectConstant2)));
456 447
457 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); 448 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1);
458 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1); 449 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1);
459 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2); 450 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2);
460 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2)); 451 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2));
461 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any); 452 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any);
462 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); 453 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2));
463 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); 454 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2));
464 CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2)); 455 CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2));
465 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); 456 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object);
466 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); 457 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass);
467 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); 458 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array);
468 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); 459 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array);
469 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2); 460 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2);
470 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number); 461 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number);
471 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass); 462 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass);
472 463
473 // Bitset-class 464 // Bitset-class
474 CHECK(IsBitset(Type::Union(T.ObjectClass, T.Object))); 465 CHECK(IsBitset(T.Union(T.ObjectClass, T.Object)));
475 CHECK(IsUnion(Type::Union(T.ObjectClass, T.Number))); 466 CHECK(IsUnion(T.Union(T.ObjectClass, T.Number)));
476 467
477 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); 468 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object);
478 CheckSub(T.None, T.Union(T.ObjectClass, T.Number)); 469 CheckSub(T.None, T.Union(T.ObjectClass, T.Number));
479 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); 470 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any);
480 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); 471 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number));
481 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); 472 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object);
482 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); 473 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array);
483 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); 474 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object);
484 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); 475 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number);
485 476
486 // Bitset-constant 477 // Bitset-constant
487 CHECK(IsBitset(Type::Union(T.SmiConstant, T.Number))); 478 CHECK(IsBitset(T.Union(T.SmiConstant, T.Number)));
488 CHECK(IsBitset(Type::Union(T.ObjectConstant1, T.Object))); 479 CHECK(IsBitset(T.Union(T.ObjectConstant1, T.Object)));
489 CHECK(IsUnion(Type::Union(T.ObjectConstant2, T.Number))); 480 CHECK(IsUnion(T.Union(T.ObjectConstant2, T.Number)));
490 481
491 CheckEqual(T.Union(T.SmiConstant, T.Number), T.Number); 482 CheckEqual(T.Union(T.SmiConstant, T.Number), T.Number);
492 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); 483 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object);
493 CheckSub(T.None, T.Union(T.ObjectConstant1, T.Number)); 484 CheckSub(T.None, T.Union(T.ObjectConstant1, T.Number));
494 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); 485 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any);
495 CheckSub(T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); 486 CheckSub(T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number));
496 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); 487 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object);
497 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); 488 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array);
498 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); 489 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object);
499 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); 490 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number);
500 CheckEqual(T.Union(T.Signed32, T.Signed32Constant), T.Signed32); 491 CheckEqual(T.Union(T.Signed32, T.Signed32Constant), T.Signed32);
501 492
502 // Class-constant 493 // Class-constant
503 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); 494 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectClass)));
504 CHECK(IsUnion(Type::Union(T.ArrayClass, T.ObjectConstant2))); 495 CHECK(IsUnion(T.Union(T.ArrayClass, T.ObjectConstant2)));
505 496
506 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ArrayClass)); 497 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ArrayClass));
507 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Any); 498 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Any);
508 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); 499 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object);
509 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); 500 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass));
510 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); 501 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass));
511 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); 502 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass));
512 CheckSub( 503 CheckSub(
513 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); 504 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object));
514 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1); 505 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1);
515 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); 506 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2);
516 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); 507 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass);
517 508
518 // Bitset-union 509 // Bitset-union
519 CHECK(IsBitset( 510 CHECK(IsBitset(T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass))));
520 Type::Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); 511 CHECK(IsUnion(T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number)));
521 CHECK(IsUnion(
522 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number)));
523 512
524 CheckEqual( 513 CheckEqual(
525 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), 514 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)),
526 T.Object); 515 T.Object);
527 CheckEqual( 516 CheckEqual(
528 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), 517 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number),
529 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); 518 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass)));
530 CheckSub( 519 CheckSub(
531 T.Double, 520 T.Double,
532 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); 521 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number));
533 CheckSub( 522 CheckSub(
534 T.ObjectConstant1, 523 T.ObjectConstant1,
535 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); 524 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double));
536 CheckSub( 525 CheckSub(
537 T.None, 526 T.None,
538 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); 527 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double));
539 CheckSub( 528 CheckSub(
540 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), 529 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double),
541 T.Any); 530 T.Any);
542 CheckSub( 531 CheckSub(
543 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), 532 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double),
544 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); 533 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass)));
545 534
546 // Class-union 535 // Class-union
547 CHECK(IsUnion( 536 CHECK(IsUnion(
548 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); 537 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass)));
549 CHECK(IsUnion( 538 CHECK(IsUnion(
550 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ObjectClass))); 539 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ObjectClass)));
551 540
552 CheckEqual( 541 CheckEqual(
553 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), 542 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)),
554 T.Union(T.ObjectClass, T.ObjectConstant1)); 543 T.Union(T.ObjectClass, T.ObjectConstant1));
555 CheckSub( 544 CheckSub(
556 T.None, 545 T.None,
557 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass))); 546 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)));
558 CheckSub( 547 CheckSub(
559 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), 548 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)),
560 T.Any); 549 T.Any);
561 CheckSub( 550 CheckSub(
562 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), 551 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)),
563 T.Object); 552 T.Object);
564 CheckEqual( 553 CheckEqual(
565 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), 554 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass),
566 T.Union(T.ArrayClass, T.ObjectConstant2)); 555 T.Union(T.ArrayClass, T.ObjectConstant2));
567 556
568 // Constant-union 557 // Constant-union
569 CHECK(IsUnion(Type::Union( 558 CHECK(IsUnion(T.Union(
570 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); 559 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2))));
571 CHECK(IsUnion(Type::Union( 560 CHECK(IsUnion(T.Union(
572 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); 561 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1)));
573 CHECK(IsUnion(Type::Union( 562 CHECK(IsUnion(T.Union(
574 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1))); 563 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1)));
575 564
576 CheckEqual( 565 CheckEqual(
577 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), 566 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)),
578 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 567 T.Union(T.ObjectConstant2, T.ObjectConstant1));
579 CheckEqual( 568 CheckEqual(
580 T.Union(T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1), 569 T.Union(T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1),
581 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1))); 570 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1)));
582 571
583 // Union-union 572 // Union-union
584 CHECK(IsBitset(Type::Union( 573 CHECK(IsBitset(T.Union(
585 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array)))); 574 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array))));
586 CHECK(IsUnion(Type::Union( 575 CHECK(IsUnion(T.Union(
587 T.Union(T.Number, T.ArrayClass), T.Union(T.ObjectClass, T.ArrayClass)))); 576 T.Union(T.Number, T.ArrayClass), T.Union(T.ObjectClass, T.ArrayClass))));
588 577
589 CheckEqual( 578 CheckEqual(
590 T.Union( 579 T.Union(
591 T.Union(T.ObjectConstant2, T.ObjectConstant1), 580 T.Union(T.ObjectConstant2, T.ObjectConstant1),
592 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 581 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
593 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 582 T.Union(T.ObjectConstant2, T.ObjectConstant1));
594 CheckEqual( 583 CheckEqual(
595 T.Union( 584 T.Union(
596 T.Union(T.ObjectConstant2, T.ArrayConstant1), 585 T.Union(T.ObjectConstant2, T.ArrayConstant1),
597 T.Union(T.ObjectConstant1, T.ArrayConstant2)), 586 T.Union(T.ObjectConstant1, T.ArrayConstant2)),
598 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant1)); 587 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant1));
599 CheckEqual( 588 CheckEqual(
600 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), 589 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)),
601 T.Union(T.Number, T.Array)); 590 T.Union(T.Number, T.Array));
602 } 591 }
603 592
604 593
605 TEST(Intersect) { 594 TEST(Intersect) {
606 CcTest::InitializeVM(); 595 CcTest::InitializeVM();
607 Isolate* isolate = CcTest::i_isolate(); 596 Isolate* isolate = CcTest::i_isolate();
608 HandleScope scope(isolate); 597 HandleScope scope(isolate);
609 HandlifiedTypes T(isolate); 598 HandlifiedTypes T(isolate);
610 599
611 // Bitset-bitset 600 // Bitset-bitset
612 CHECK(IsBitset(Type::Intersect(T.Object, T.Number))); 601 CHECK(IsBitset(T.Intersect(T.Object, T.Number)));
613 CHECK(IsBitset(Type::Intersect(T.Object, T.Object))); 602 CHECK(IsBitset(T.Intersect(T.Object, T.Object)));
614 CHECK(IsBitset(Type::Intersect(T.Any, T.None))); 603 CHECK(IsBitset(T.Intersect(T.Any, T.None)));
615 604
616 CheckEqual(T.Intersect(T.None, T.Number), T.None); 605 CheckEqual(T.Intersect(T.None, T.Number), T.None);
617 CheckEqual(T.Intersect(T.Object, T.Proxy), T.None); 606 CheckEqual(T.Intersect(T.Object, T.Proxy), T.None);
618 CheckEqual(T.Intersect(T.Name, T.String), T.Intersect(T.String, T.Name)); 607 CheckEqual(T.Intersect(T.Name, T.String), T.Intersect(T.String, T.Name));
619 CheckEqual(T.Intersect(T.UniqueName, T.String), T.InternalizedString); 608 CheckEqual(T.Intersect(T.UniqueName, T.String), T.InternalizedString);
620 609
621 // Class-class 610 // Class-class
622 CHECK(IsClass(Type::Intersect(T.ObjectClass, T.ObjectClass))); 611 CHECK(IsClass(T.Intersect(T.ObjectClass, T.ObjectClass)));
623 CHECK(IsBitset(Type::Intersect(T.ObjectClass, T.ArrayClass))); 612 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.ArrayClass)));
624 613
625 CheckEqual(T.Intersect(T.ObjectClass, T.ObjectClass), T.ObjectClass); 614 CheckEqual(T.Intersect(T.ObjectClass, T.ObjectClass), T.ObjectClass);
626 CheckEqual(T.Intersect(T.ObjectClass, T.ArrayClass), T.None); 615 CheckEqual(T.Intersect(T.ObjectClass, T.ArrayClass), T.None);
627 616
628 // Constant-constant 617 // Constant-constant
629 CHECK(IsConstant(Type::Intersect(T.ObjectConstant1, T.ObjectConstant1))); 618 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.ObjectConstant1)));
630 CHECK(IsConstant(Type::Intersect(T.ArrayConstant1, T.ArrayConstant2))); 619 CHECK(IsConstant(T.Intersect(T.ArrayConstant1, T.ArrayConstant2)));
631 CHECK(IsBitset(Type::Intersect(T.ObjectConstant1, T.ObjectConstant2))); 620 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectConstant2)));
632 621
633 CheckEqual( 622 CheckEqual(
634 T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); 623 T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1);
635 CheckEqual( 624 CheckEqual(
636 T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1); 625 T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1);
637 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None); 626 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None);
638 627
639 // Bitset-class 628 // Bitset-class
640 CHECK(IsClass(Type::Intersect(T.ObjectClass, T.Object))); 629 CHECK(IsClass(T.Intersect(T.ObjectClass, T.Object)));
641 CHECK(IsBitset(Type::Intersect(T.ObjectClass, T.Number))); 630 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.Number)));
642 631
643 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); 632 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass);
644 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); 633 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None);
645 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); 634 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None);
646 635
647 // Bitset-constant 636 // Bitset-constant
648 CHECK(IsBitset(Type::Intersect(T.Smi, T.Number))); 637 CHECK(IsBitset(T.Intersect(T.Smi, T.Number)));
649 CHECK(IsConstant(Type::Intersect(T.SmiConstant, T.Number))); 638 CHECK(IsConstant(T.Intersect(T.SmiConstant, T.Number)));
650 CHECK(IsConstant(Type::Intersect(T.ObjectConstant1, T.Object))); 639 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.Object)));
651 640
652 CheckEqual(T.Intersect(T.Smi, T.Number), T.Smi); 641 CheckEqual(T.Intersect(T.Smi, T.Number), T.Smi);
653 CheckEqual(T.Intersect(T.SmiConstant, T.Number), T.SmiConstant); 642 CheckEqual(T.Intersect(T.SmiConstant, T.Number), T.SmiConstant);
654 CheckEqual(T.Intersect(T.ObjectConstant1, T.Object), T.ObjectConstant1); 643 CheckEqual(T.Intersect(T.ObjectConstant1, T.Object), T.ObjectConstant1);
655 644
656 // Class-constant 645 // Class-constant
657 CHECK(IsBitset(Type::Intersect(T.ObjectConstant1, T.ObjectClass))); 646 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectClass)));
658 CHECK(IsBitset(Type::Intersect(T.ArrayClass, T.ObjectConstant2))); 647 CHECK(IsBitset(T.Intersect(T.ArrayClass, T.ObjectConstant2)));
659 648
660 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); 649 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None);
661 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); 650 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None);
662 651
663 // Bitset-union 652 // Bitset-union
664 CHECK(IsUnion( 653 CHECK(IsUnion(
665 Type::Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); 654 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass))));
666 CHECK(IsBitset( 655 CHECK(IsBitset(
667 Type::Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); 656 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number)));
668 657
669 CheckEqual( 658 CheckEqual(
670 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), 659 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)),
671 T.Union(T.ObjectConstant1, T.ObjectClass)); 660 T.Union(T.ObjectConstant1, T.ObjectClass));
672 CheckEqual( 661 CheckEqual(
673 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), 662 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number),
674 T.None); 663 T.None);
675 664
676 // Class-union 665 // Class-union
677 CHECK(IsClass( 666 CHECK(IsClass(
678 Type::Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); 667 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass)));
679 CHECK(IsClass( 668 CHECK(IsClass(
680 Type::Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass))); 669 T.Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass)));
681 CHECK(IsBitset( 670 CHECK(IsBitset(
682 Type::Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass))); 671 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass)));
683 672
684 CheckEqual( 673 CheckEqual(
685 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), 674 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)),
686 T.ArrayClass); 675 T.ArrayClass);
687 CheckEqual( 676 CheckEqual(
688 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), 677 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)),
689 T.ArrayClass); 678 T.ArrayClass);
690 CheckEqual( 679 CheckEqual(
691 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass), 680 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass),
692 T.None); 681 T.None);
693 682
694 // Constant-union 683 // Constant-union
695 CHECK(IsConstant(Type::Intersect( 684 CHECK(IsConstant(T.Intersect(
696 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); 685 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2))));
697 CHECK(IsConstant(Type::Intersect( 686 CHECK(IsConstant(T.Intersect(
698 T.Union(T.Number, T.ObjectClass), T.SmiConstant))); 687 T.Union(T.Number, T.ObjectClass), T.SmiConstant)));
699 CHECK(IsBitset(Type::Intersect( 688 CHECK(IsBitset(T.Intersect(
700 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); 689 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1)));
701 690
702 CheckEqual( 691 CheckEqual(
703 T.Intersect( 692 T.Intersect(
704 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), 693 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)),
705 T.ObjectConstant1); 694 T.ObjectConstant1);
706 CheckEqual( 695 CheckEqual(
707 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), 696 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
708 T.SmiConstant); 697 T.SmiConstant);
709 CheckEqual( 698 CheckEqual(
710 T.Intersect(T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1), 699 T.Intersect(T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1),
711 T.None); 700 T.None);
712 701
713 // Union-union 702 // Union-union
714 CHECK(IsUnion(Type::Intersect( 703 CHECK(IsUnion(T.Intersect(
715 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array)))); 704 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array))));
716 CHECK(IsBitset(Type::Intersect( 705 CHECK(IsBitset(T.Intersect(
717 T.Union(T.Number, T.ObjectClass), T.Union(T.Signed32, T.Array)))); 706 T.Union(T.Number, T.ObjectClass), T.Union(T.Signed32, T.Array))));
718 707
719 CheckEqual( 708 CheckEqual(
720 T.Intersect( 709 T.Intersect(
721 T.Union(T.Number, T.ArrayClass), 710 T.Union(T.Number, T.ArrayClass),
722 T.Union(T.Smi, T.Array)), 711 T.Union(T.Smi, T.Array)),
723 T.Union(T.Smi, T.ArrayClass)); 712 T.Union(T.Smi, T.ArrayClass));
724 CheckEqual( 713 CheckEqual(
725 T.Intersect( 714 T.Intersect(
726 T.Union(T.Number, T.ObjectClass), 715 T.Union(T.Number, T.ObjectClass),
727 T.Union(T.Signed32, T.Array)), 716 T.Union(T.Signed32, T.Array)),
728 T.Signed32); 717 T.Signed32);
729 CheckEqual( 718 CheckEqual(
730 T.Intersect( 719 T.Intersect(
731 T.Union(T.ObjectConstant2, T.ObjectConstant1), 720 T.Union(T.ObjectConstant2, T.ObjectConstant1),
732 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 721 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
733 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 722 T.Union(T.ObjectConstant2, T.ObjectConstant1));
734 CheckEqual( 723 CheckEqual(
735 T.Intersect( 724 T.Intersect(
736 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), 725 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass),
737 T.Union( 726 T.Union(
738 T.ObjectConstant1, T.Union(T.ArrayConstant1, T.ObjectConstant2))), 727 T.ObjectConstant1, T.Union(T.ArrayConstant1, T.ObjectConstant2))),
739 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 728 T.Union(T.ObjectConstant2, T.ObjectConstant1));
740 CheckEqual( 729 CheckEqual(
741 T.Intersect( 730 T.Intersect(
742 T.Union(T.ObjectConstant2, T.ArrayConstant1), 731 T.Union(T.ObjectConstant2, T.ArrayConstant1),
743 T.Union(T.ObjectConstant1, T.ArrayConstant2)), 732 T.Union(T.ObjectConstant1, T.ArrayConstant2)),
744 T.ArrayConstant1); 733 T.ArrayConstant1);
745 } 734 }
OLDNEW
« no previous file with comments | « src/typing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698