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 23 matching lines...) Expand all Loading... |
34 static bool IsBitset(Type* type) { return type->IsSmi(); } | 34 static bool IsBitset(Type* type) { return type->IsSmi(); } |
35 static bool IsClass(Type* type) { return type->IsMap(); } | 35 static bool IsClass(Type* type) { return type->IsMap(); } |
36 static bool IsConstant(Type* type) { return type->IsBox(); } | 36 static bool IsConstant(Type* type) { return type->IsBox(); } |
37 static bool IsUnion(Type* type) { return type->IsFixedArray(); } | 37 static bool IsUnion(Type* type) { return type->IsFixedArray(); } |
38 | 38 |
39 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } | 39 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } |
40 static Map* AsClass(Type* type) { return Map::cast(type); } | 40 static Map* AsClass(Type* type) { return Map::cast(type); } |
41 static Object* AsConstant(Type* type) { return Box::cast(type)->value(); } | 41 static Object* AsConstant(Type* type) { return Box::cast(type)->value(); } |
42 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } | 42 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } |
43 | 43 |
| 44 |
| 45 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { |
| 46 CHECK_EQ(IsBitset(*type1), IsBitset(*type2)); |
| 47 CHECK_EQ(IsClass(*type1), IsClass(*type2)); |
| 48 CHECK_EQ(IsConstant(*type1), IsConstant(*type2)); |
| 49 CHECK_EQ(IsUnion(*type1), IsUnion(*type2)); |
| 50 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); |
| 51 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); |
| 52 if (IsBitset(*type1)) { |
| 53 CHECK_EQ(AsBitset(*type1), AsBitset(*type2)); |
| 54 } else if (IsClass(*type1)) { |
| 55 CHECK_EQ(AsClass(*type1), AsClass(*type2)); |
| 56 } else if (IsConstant(*type1)) { |
| 57 CHECK_EQ(AsConstant(*type1), AsConstant(*type2)); |
| 58 } else if (IsUnion(*type1)) { |
| 59 CHECK_EQ(AsUnion(*type1)->length(), AsUnion(*type2)->length()); |
| 60 } |
| 61 CHECK(type1->Is(type2)); |
| 62 CHECK(type2->Is(type1)); |
| 63 } |
| 64 |
| 65 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { |
| 66 CHECK(type1->Is(type2)); |
| 67 CHECK(!type2->Is(type1)); |
| 68 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 69 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); |
| 70 } |
| 71 } |
| 72 |
| 73 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { |
| 74 CHECK(!type1->Is(type2)); |
| 75 CHECK(!type2->Is(type1)); |
| 76 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 77 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); |
| 78 } |
| 79 } |
| 80 |
| 81 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { |
| 82 CHECK(type1->Maybe(type2)); |
| 83 CHECK(type2->Maybe(type1)); |
| 84 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 85 CHECK_NE(0, AsBitset(*type1) & AsBitset(*type2)); |
| 86 } |
| 87 } |
| 88 |
| 89 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { |
| 90 CHECK(!type1->Is(type2)); |
| 91 CHECK(!type2->Is(type1)); |
| 92 CHECK(!type1->Maybe(type2)); |
| 93 CHECK(!type2->Maybe(type1)); |
| 94 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 95 CHECK_EQ(0, AsBitset(*type1) & AsBitset(*type2)); |
| 96 } |
| 97 } |
| 98 |
| 99 |
44 class HandlifiedTypes { | 100 class HandlifiedTypes { |
45 public: | 101 public: |
46 explicit HandlifiedTypes(Isolate* isolate) : | 102 explicit HandlifiedTypes(Isolate* isolate) : |
47 None(Type::None(), isolate), | 103 None(Type::None(), isolate), |
48 Any(Type::Any(), isolate), | 104 Any(Type::Any(), isolate), |
49 Oddball(Type::Oddball(), isolate), | 105 Oddball(Type::Oddball(), isolate), |
50 Boolean(Type::Boolean(), isolate), | 106 Boolean(Type::Boolean(), isolate), |
51 Null(Type::Null(), isolate), | 107 Null(Type::Null(), isolate), |
52 Undefined(Type::Undefined(), isolate), | 108 Undefined(Type::Undefined(), isolate), |
53 Number(Type::Number(), isolate), | 109 Number(Type::Number(), isolate), |
(...skipping 15 matching lines...) Expand all Loading... |
69 isolate_(isolate) { | 125 isolate_(isolate) { |
70 smi = handle(Smi::FromInt(666), isolate); | 126 smi = handle(Smi::FromInt(666), isolate); |
71 object1 = isolate->factory()->NewJSObjectFromMap(object_map); | 127 object1 = isolate->factory()->NewJSObjectFromMap(object_map); |
72 object2 = isolate->factory()->NewJSObjectFromMap(object_map); | 128 object2 = isolate->factory()->NewJSObjectFromMap(object_map); |
73 array = isolate->factory()->NewJSArray(20); | 129 array = isolate->factory()->NewJSArray(20); |
74 ObjectClass = handle(Type::Class(object_map), isolate); | 130 ObjectClass = handle(Type::Class(object_map), isolate); |
75 ArrayClass = handle(Type::Class(array_map), isolate); | 131 ArrayClass = handle(Type::Class(array_map), isolate); |
76 Integer31Constant = handle(Type::Constant(smi, isolate), isolate); | 132 Integer31Constant = handle(Type::Constant(smi, isolate), isolate); |
77 ObjectConstant1 = handle(Type::Constant(object1), isolate); | 133 ObjectConstant1 = handle(Type::Constant(object1), isolate); |
78 ObjectConstant2 = handle(Type::Constant(object2), isolate); | 134 ObjectConstant2 = handle(Type::Constant(object2), isolate); |
79 ArrayConstant = handle(Type::Constant(array), isolate); | 135 ArrayConstant1 = handle(Type::Constant(array), isolate); |
| 136 ArrayConstant2 = handle(Type::Constant(array), isolate); |
80 } | 137 } |
81 | 138 |
82 Handle<Type> None; | 139 Handle<Type> None; |
83 Handle<Type> Any; | 140 Handle<Type> Any; |
84 Handle<Type> Oddball; | 141 Handle<Type> Oddball; |
85 Handle<Type> Boolean; | 142 Handle<Type> Boolean; |
86 Handle<Type> Null; | 143 Handle<Type> Null; |
87 Handle<Type> Undefined; | 144 Handle<Type> Undefined; |
88 Handle<Type> Number; | 145 Handle<Type> Number; |
89 Handle<Type> Integer31; | 146 Handle<Type> Integer31; |
90 Handle<Type> Integer32; | 147 Handle<Type> Integer32; |
91 Handle<Type> Double; | 148 Handle<Type> Double; |
92 Handle<Type> Name; | 149 Handle<Type> Name; |
93 Handle<Type> UniqueName; | 150 Handle<Type> UniqueName; |
94 Handle<Type> String; | 151 Handle<Type> String; |
95 Handle<Type> InternalizedString; | 152 Handle<Type> InternalizedString; |
96 Handle<Type> Symbol; | 153 Handle<Type> Symbol; |
97 Handle<Type> Receiver; | 154 Handle<Type> Receiver; |
98 Handle<Type> Object; | 155 Handle<Type> Object; |
99 Handle<Type> Array; | 156 Handle<Type> Array; |
100 Handle<Type> Function; | 157 Handle<Type> Function; |
101 Handle<Type> Proxy; | 158 Handle<Type> Proxy; |
102 | 159 |
103 Handle<Type> ObjectClass; | 160 Handle<Type> ObjectClass; |
104 Handle<Type> ArrayClass; | 161 Handle<Type> ArrayClass; |
105 | 162 |
106 Handle<Type> Integer31Constant; | 163 Handle<Type> Integer31Constant; |
107 Handle<Type> ObjectConstant1; | 164 Handle<Type> ObjectConstant1; |
108 Handle<Type> ObjectConstant2; | 165 Handle<Type> ObjectConstant2; |
109 Handle<Type> ArrayConstant; | 166 Handle<Type> ArrayConstant1; |
| 167 Handle<Type> ArrayConstant2; |
110 | 168 |
111 Handle<Map> object_map; | 169 Handle<Map> object_map; |
112 Handle<Map> array_map; | 170 Handle<Map> array_map; |
113 | 171 |
114 Handle<v8::internal::Smi> smi; | 172 Handle<v8::internal::Smi> smi; |
115 Handle<JSObject> object1; | 173 Handle<JSObject> object1; |
116 Handle<JSObject> object2; | 174 Handle<JSObject> object2; |
117 Handle<JSArray> array; | 175 Handle<JSArray> array; |
118 | 176 |
119 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) { | 177 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) { |
120 return handle(Type::Union(type1, type2), isolate_); | 178 return handle(Type::Union(type1, type2), isolate_); |
121 } | 179 } |
| 180 Handle<Type> Intersect(Handle<Type> type1, Handle<Type> type2) { |
| 181 return handle(Type::Intersect(type1, type2), isolate_); |
| 182 } |
122 | 183 |
123 private: | 184 private: |
124 Isolate* isolate_; | 185 Isolate* isolate_; |
125 }; | 186 }; |
126 | 187 |
127 | 188 |
128 TEST(Bitset) { | 189 TEST(Bitset) { |
129 CcTest::InitializeVM(); | 190 CcTest::InitializeVM(); |
130 Isolate* isolate = Isolate::Current(); | 191 Isolate* isolate = Isolate::Current(); |
131 HandleScope scope(isolate); | 192 HandleScope scope(isolate); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 227 |
167 TEST(Constant) { | 228 TEST(Constant) { |
168 CcTest::InitializeVM(); | 229 CcTest::InitializeVM(); |
169 Isolate* isolate = Isolate::Current(); | 230 Isolate* isolate = Isolate::Current(); |
170 HandleScope scope(isolate); | 231 HandleScope scope(isolate); |
171 HandlifiedTypes T(isolate); | 232 HandlifiedTypes T(isolate); |
172 | 233 |
173 CHECK(IsConstant(*T.Integer31Constant)); | 234 CHECK(IsConstant(*T.Integer31Constant)); |
174 CHECK(IsConstant(*T.ObjectConstant1)); | 235 CHECK(IsConstant(*T.ObjectConstant1)); |
175 CHECK(IsConstant(*T.ObjectConstant2)); | 236 CHECK(IsConstant(*T.ObjectConstant2)); |
176 CHECK(IsConstant(*T.ArrayConstant)); | 237 CHECK(IsConstant(*T.ArrayConstant1)); |
| 238 CHECK(IsConstant(*T.ArrayConstant2)); |
177 | 239 |
178 CHECK(*T.smi == AsConstant(*T.Integer31Constant)); | 240 CHECK(*T.smi == AsConstant(*T.Integer31Constant)); |
179 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); | 241 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); |
180 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); | 242 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); |
181 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); | 243 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); |
182 CHECK(*T.array == AsConstant(*T.ArrayConstant)); | 244 CHECK(*T.array == AsConstant(*T.ArrayConstant1)); |
| 245 CHECK(*T.array == AsConstant(*T.ArrayConstant2)); |
183 } | 246 } |
184 | 247 |
185 | 248 |
186 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { | |
187 CHECK(type1->Is(type2)); | |
188 CHECK(!type2->Is(type1)); | |
189 if (IsBitset(*type1) && IsBitset(*type2)) { | |
190 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); | |
191 } | |
192 } | |
193 | |
194 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { | |
195 CHECK(!type1->Is(type2)); | |
196 CHECK(!type2->Is(type1)); | |
197 if (IsBitset(*type1) && IsBitset(*type2)) { | |
198 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); | |
199 } | |
200 } | |
201 | |
202 TEST(Is) { | 249 TEST(Is) { |
203 CcTest::InitializeVM(); | 250 CcTest::InitializeVM(); |
204 Isolate* isolate = Isolate::Current(); | 251 Isolate* isolate = Isolate::Current(); |
205 HandleScope scope(isolate); | 252 HandleScope scope(isolate); |
206 HandlifiedTypes T(isolate); | 253 HandlifiedTypes T(isolate); |
207 | 254 |
208 // Reflexivity | 255 // Reflexivity |
209 CHECK(T.None->Is(T.None)); | 256 CHECK(T.None->Is(T.None)); |
210 CHECK(T.Any->Is(T.Any)); | 257 CHECK(T.Any->Is(T.Any)); |
211 CHECK(T.Object->Is(T.Object)); | 258 CHECK(T.Object->Is(T.Object)); |
212 | 259 |
213 CHECK(T.ObjectClass->Is(T.ObjectClass)); | 260 CHECK(T.ObjectClass->Is(T.ObjectClass)); |
214 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); | 261 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); |
| 262 CHECK(T.ArrayConstant1->Is(T.ArrayConstant2)); |
215 | 263 |
216 // Symmetry and Transitivity | 264 // Symmetry and Transitivity |
217 CheckSub(T.None, T.Number); | 265 CheckSub(T.None, T.Number); |
218 CheckSub(T.None, T.Any); | 266 CheckSub(T.None, T.Any); |
219 | 267 |
220 CheckSub(T.Oddball, T.Any); | 268 CheckSub(T.Oddball, T.Any); |
221 CheckSub(T.Boolean, T.Oddball); | 269 CheckSub(T.Boolean, T.Oddball); |
222 CheckSub(T.Null, T.Oddball); | 270 CheckSub(T.Null, T.Oddball); |
223 CheckSub(T.Undefined, T.Oddball); | 271 CheckSub(T.Undefined, T.Oddball); |
224 CheckUnordered(T.Boolean, T.Null); | 272 CheckUnordered(T.Boolean, T.Null); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Structured subtyping | 306 // Structured subtyping |
259 CheckSub(T.ObjectClass, T.Object); | 307 CheckSub(T.ObjectClass, T.Object); |
260 CheckSub(T.ArrayClass, T.Object); | 308 CheckSub(T.ArrayClass, T.Object); |
261 CheckUnordered(T.ObjectClass, T.ArrayClass); | 309 CheckUnordered(T.ObjectClass, T.ArrayClass); |
262 | 310 |
263 CheckSub(T.Integer31Constant, T.Integer31); | 311 CheckSub(T.Integer31Constant, T.Integer31); |
264 CheckSub(T.Integer31Constant, T.Integer32); | 312 CheckSub(T.Integer31Constant, T.Integer32); |
265 CheckSub(T.Integer31Constant, T.Number); | 313 CheckSub(T.Integer31Constant, T.Number); |
266 CheckSub(T.ObjectConstant1, T.Object); | 314 CheckSub(T.ObjectConstant1, T.Object); |
267 CheckSub(T.ObjectConstant2, T.Object); | 315 CheckSub(T.ObjectConstant2, T.Object); |
268 CheckSub(T.ArrayConstant, T.Object); | 316 CheckSub(T.ArrayConstant1, T.Object); |
269 CheckSub(T.ArrayConstant, T.Array); | 317 CheckSub(T.ArrayConstant1, T.Array); |
270 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); | 318 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); |
271 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); | 319 CheckUnordered(T.ObjectConstant1, T.ArrayConstant1); |
272 | 320 |
273 CheckUnordered(T.ObjectConstant1, T.ObjectClass); | 321 CheckUnordered(T.ObjectConstant1, T.ObjectClass); |
274 CheckUnordered(T.ObjectConstant2, T.ObjectClass); | 322 CheckUnordered(T.ObjectConstant2, T.ObjectClass); |
275 CheckUnordered(T.ObjectConstant1, T.ArrayClass); | 323 CheckUnordered(T.ObjectConstant1, T.ArrayClass); |
276 CheckUnordered(T.ObjectConstant2, T.ArrayClass); | 324 CheckUnordered(T.ObjectConstant2, T.ArrayClass); |
277 CheckUnordered(T.ArrayConstant, T.ObjectClass); | 325 CheckUnordered(T.ArrayConstant1, T.ObjectClass); |
278 } | 326 } |
279 | 327 |
280 | 328 |
281 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { | |
282 CHECK(type1->Maybe(type2)); | |
283 CHECK(type2->Maybe(type1)); | |
284 if (IsBitset(*type1) && IsBitset(*type2)) { | |
285 CHECK_NE(0, AsBitset(*type1) & AsBitset(*type2)); | |
286 } | |
287 } | |
288 | |
289 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { | |
290 CHECK(!type1->Is(type2)); | |
291 CHECK(!type2->Is(type1)); | |
292 CHECK(!type1->Maybe(type2)); | |
293 CHECK(!type2->Maybe(type1)); | |
294 if (IsBitset(*type1) && IsBitset(*type2)) { | |
295 CHECK_EQ(0, AsBitset(*type1) & AsBitset(*type2)); | |
296 } | |
297 } | |
298 | |
299 TEST(Maybe) { | 329 TEST(Maybe) { |
300 CcTest::InitializeVM(); | 330 CcTest::InitializeVM(); |
301 Isolate* isolate = Isolate::Current(); | 331 Isolate* isolate = Isolate::Current(); |
302 HandleScope scope(isolate); | 332 HandleScope scope(isolate); |
303 HandlifiedTypes T(isolate); | 333 HandlifiedTypes T(isolate); |
304 | 334 |
305 CheckOverlap(T.Any, T.Any); | 335 CheckOverlap(T.Any, T.Any); |
306 CheckOverlap(T.Object, T.Object); | 336 CheckOverlap(T.Object, T.Object); |
307 | 337 |
308 CheckOverlap(T.Oddball, T.Any); | 338 CheckOverlap(T.Oddball, T.Any); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 CheckOverlap(T.ObjectClass, T.ObjectClass); | 375 CheckOverlap(T.ObjectClass, T.ObjectClass); |
346 CheckOverlap(T.ArrayClass, T.ArrayClass); | 376 CheckOverlap(T.ArrayClass, T.ArrayClass); |
347 CheckDisjoint(T.ObjectClass, T.ArrayClass); | 377 CheckDisjoint(T.ObjectClass, T.ArrayClass); |
348 | 378 |
349 CheckOverlap(T.Integer31Constant, T.Integer31); | 379 CheckOverlap(T.Integer31Constant, T.Integer31); |
350 CheckOverlap(T.Integer31Constant, T.Integer32); | 380 CheckOverlap(T.Integer31Constant, T.Integer32); |
351 CheckOverlap(T.Integer31Constant, T.Number); | 381 CheckOverlap(T.Integer31Constant, T.Number); |
352 CheckDisjoint(T.Integer31Constant, T.Double); | 382 CheckDisjoint(T.Integer31Constant, T.Double); |
353 CheckOverlap(T.ObjectConstant1, T.Object); | 383 CheckOverlap(T.ObjectConstant1, T.Object); |
354 CheckOverlap(T.ObjectConstant2, T.Object); | 384 CheckOverlap(T.ObjectConstant2, T.Object); |
355 CheckOverlap(T.ArrayConstant, T.Object); | 385 CheckOverlap(T.ArrayConstant1, T.Object); |
356 CheckOverlap(T.ArrayConstant, T.Array); | 386 CheckOverlap(T.ArrayConstant1, T.Array); |
| 387 CheckOverlap(T.ArrayConstant1, T.ArrayConstant2); |
357 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); | 388 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); |
358 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); | 389 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); |
359 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant); | 390 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant1); |
360 | 391 |
361 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); | 392 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); |
362 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); | 393 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); |
363 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); | 394 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); |
364 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); | 395 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); |
365 CheckDisjoint(T.ArrayConstant, T.ObjectClass); | 396 CheckDisjoint(T.ArrayConstant1, T.ObjectClass); |
366 } | 397 } |
367 | 398 |
368 | 399 |
369 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { | |
370 CHECK_EQ(IsBitset(*type1), IsBitset(*type2)); | |
371 CHECK_EQ(IsClass(*type1), IsClass(*type2)); | |
372 CHECK_EQ(IsConstant(*type1), IsConstant(*type2)); | |
373 CHECK_EQ(IsUnion(*type1), IsUnion(*type2)); | |
374 if (IsBitset(*type1)) { | |
375 CHECK_EQ(AsBitset(*type1), AsBitset(*type2)); | |
376 } else if (IsClass(*type1)) { | |
377 CHECK_EQ(AsClass(*type1), AsClass(*type2)); | |
378 } else if (IsConstant(*type1)) { | |
379 CHECK_EQ(AsConstant(*type1), AsConstant(*type2)); | |
380 } else if (IsUnion(*type1)) { | |
381 CHECK_EQ(AsUnion(*type1)->length(), AsUnion(*type2)->length()); | |
382 } | |
383 CHECK(type1->Is(type2)); | |
384 CHECK(type2->Is(type1)); | |
385 } | |
386 | |
387 TEST(Union) { | 400 TEST(Union) { |
388 CcTest::InitializeVM(); | 401 CcTest::InitializeVM(); |
389 Isolate* isolate = Isolate::Current(); | 402 Isolate* isolate = Isolate::Current(); |
390 HandleScope scope(isolate); | 403 HandleScope scope(isolate); |
391 HandlifiedTypes T(isolate); | 404 HandlifiedTypes T(isolate); |
392 | 405 |
393 // Bitset-bitset | 406 // Bitset-bitset |
394 CHECK(IsBitset(Type::Union(T.Object, T.Number))); | 407 CHECK(IsBitset(Type::Union(T.Object, T.Number))); |
395 CHECK(IsBitset(Type::Union(T.Object, T.Object))); | 408 CHECK(IsBitset(Type::Union(T.Object, T.Object))); |
396 CHECK(IsBitset(Type::Union(T.Any, T.None))); | 409 CHECK(IsBitset(Type::Union(T.Any, T.None))); |
(...skipping 10 matching lines...) Expand all Loading... |
407 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); | 420 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); |
408 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); | 421 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); |
409 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); | 422 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); |
410 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); | 423 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); |
411 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | 424 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
412 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | 425 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
413 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); | 426 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); |
414 | 427 |
415 // Constant-constant | 428 // Constant-constant |
416 CHECK(IsConstant(Type::Union(T.ObjectConstant1, T.ObjectConstant1))); | 429 CHECK(IsConstant(Type::Union(T.ObjectConstant1, T.ObjectConstant1))); |
| 430 CHECK(IsConstant(Type::Union(T.ArrayConstant1, T.ArrayConstant1))); |
417 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectConstant2))); | 431 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectConstant2))); |
418 | 432 |
419 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); | 433 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); |
| 434 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1); |
| 435 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2); |
420 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | 436 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
421 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | 437 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 438 CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2)); |
422 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); | 439 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); |
423 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); | 440 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); |
424 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); | 441 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); |
425 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); | 442 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); |
426 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number); | 443 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2); |
427 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass); | 444 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number); |
| 445 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass); |
428 | 446 |
429 // Bitset-class | 447 // Bitset-class |
430 CHECK(IsBitset(Type::Union(T.ObjectClass, T.Object))); | 448 CHECK(IsBitset(Type::Union(T.ObjectClass, T.Object))); |
431 CHECK(IsUnion(Type::Union(T.ObjectClass, T.Number))); | 449 CHECK(IsUnion(Type::Union(T.ObjectClass, T.Number))); |
432 | 450 |
433 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); | 451 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); |
434 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); | 452 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); |
435 CheckSub(T.Union(T.ObjectClass, T.Integer31), T.Union(T.Object, T.Number)); | 453 CheckSub(T.Union(T.ObjectClass, T.Integer31), T.Union(T.Object, T.Number)); |
436 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); | 454 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); |
437 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); | 455 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); |
(...skipping 18 matching lines...) Expand all Loading... |
456 // Class-constant | 474 // Class-constant |
457 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); | 475 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); |
458 CHECK(IsUnion(Type::Union(T.ArrayClass, T.ObjectConstant2))); | 476 CHECK(IsUnion(Type::Union(T.ArrayClass, T.ObjectConstant2))); |
459 | 477 |
460 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); | 478 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); |
461 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); | 479 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); |
462 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | 480 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
463 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | 481 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
464 CheckSub( | 482 CheckSub( |
465 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); | 483 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); |
466 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant); | 484 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1); |
467 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); | 485 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); |
468 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); | 486 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); |
469 | 487 |
470 // Bitset-union | 488 // Bitset-union |
471 CHECK(IsBitset( | 489 CHECK(IsBitset( |
472 Type::Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); | 490 Type::Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); |
473 CHECK(IsUnion( | 491 CHECK(IsUnion( |
474 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); | 492 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); |
475 | 493 |
476 CheckEqual( | 494 CheckEqual( |
(...skipping 28 matching lines...) Expand all Loading... |
505 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), | 523 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
506 T.Object); | 524 T.Object); |
507 CheckEqual( | 525 CheckEqual( |
508 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), | 526 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), |
509 T.Union(T.ArrayClass, T.ObjectConstant2)); | 527 T.Union(T.ArrayClass, T.ObjectConstant2)); |
510 | 528 |
511 // Constant-union | 529 // Constant-union |
512 CHECK(IsUnion(Type::Union( | 530 CHECK(IsUnion(Type::Union( |
513 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); | 531 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); |
514 CHECK(IsUnion(Type::Union( | 532 CHECK(IsUnion(Type::Union( |
515 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1))); | 533 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); |
516 CHECK(IsUnion(Type::Union( | 534 CHECK(IsUnion(Type::Union( |
517 T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1))); | 535 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1))); |
518 | 536 |
519 CheckEqual( | 537 CheckEqual( |
520 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 538 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
521 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 539 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
522 CheckEqual( | 540 CheckEqual( |
523 T.Union(T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1), | 541 T.Union(T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1), |
524 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1))); | 542 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1))); |
525 | 543 |
526 // Union-union | 544 // Union-union |
527 CHECK(IsBitset(Type::Union( | 545 CHECK(IsBitset(Type::Union( |
528 T.Union(T.Number, T.ArrayClass), T.Union(T.Integer32, T.Array)))); | 546 T.Union(T.Number, T.ArrayClass), T.Union(T.Integer32, T.Array)))); |
| 547 CHECK(IsUnion(Type::Union( |
| 548 T.Union(T.Number, T.ArrayClass), T.Union(T.ObjectClass, T.ArrayClass)))); |
529 | 549 |
530 CheckEqual( | 550 CheckEqual( |
531 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), | 551 T.Union( |
532 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 552 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 553 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
533 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 554 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
534 CheckEqual( | 555 CheckEqual( |
535 T.Union(T.Union(T.ObjectConstant2, T.ArrayConstant), | 556 T.Union( |
536 T.Union(T.ObjectConstant1, T.ArrayConstant)), | 557 T.Union(T.ObjectConstant2, T.ArrayConstant1), |
537 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant)); | 558 T.Union(T.ObjectConstant1, T.ArrayConstant2)), |
| 559 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant1)); |
538 CheckEqual( | 560 CheckEqual( |
539 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Integer31, T.Array)), | 561 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Integer31, T.Array)), |
540 T.Union(T.Number, T.Array)); | 562 T.Union(T.Number, T.Array)); |
541 } | 563 } |
| 564 |
| 565 |
| 566 TEST(Intersect) { |
| 567 CcTest::InitializeVM(); |
| 568 Isolate* isolate = Isolate::Current(); |
| 569 HandleScope scope(isolate); |
| 570 HandlifiedTypes T(isolate); |
| 571 |
| 572 // Bitset-bitset |
| 573 CHECK(IsBitset(Type::Intersect(T.Object, T.Number))); |
| 574 CHECK(IsBitset(Type::Intersect(T.Object, T.Object))); |
| 575 CHECK(IsBitset(Type::Intersect(T.Any, T.None))); |
| 576 |
| 577 CheckEqual(T.Intersect(T.None, T.Number), T.None); |
| 578 CheckEqual(T.Intersect(T.Object, T.Proxy), T.None); |
| 579 CheckEqual(T.Intersect(T.Name, T.String), T.Intersect(T.String, T.Name)); |
| 580 CheckEqual(T.Intersect(T.UniqueName, T.String), T.InternalizedString); |
| 581 |
| 582 // Class-class |
| 583 CHECK(IsClass(Type::Intersect(T.ObjectClass, T.ObjectClass))); |
| 584 CHECK(IsBitset(Type::Intersect(T.ObjectClass, T.ArrayClass))); |
| 585 |
| 586 CheckEqual(T.Intersect(T.ObjectClass, T.ObjectClass), T.ObjectClass); |
| 587 CheckEqual(T.Intersect(T.ObjectClass, T.ArrayClass), T.None); |
| 588 |
| 589 // Constant-constant |
| 590 CHECK(IsConstant(Type::Intersect(T.ObjectConstant1, T.ObjectConstant1))); |
| 591 CHECK(IsConstant(Type::Intersect(T.ArrayConstant1, T.ArrayConstant2))); |
| 592 CHECK(IsBitset(Type::Intersect(T.ObjectConstant1, T.ObjectConstant2))); |
| 593 |
| 594 CheckEqual( |
| 595 T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); |
| 596 CheckEqual( |
| 597 T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1); |
| 598 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None); |
| 599 |
| 600 // Bitset-class |
| 601 CHECK(IsClass(Type::Intersect(T.ObjectClass, T.Object))); |
| 602 CHECK(IsBitset(Type::Intersect(T.ObjectClass, T.Number))); |
| 603 |
| 604 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); |
| 605 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); |
| 606 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); |
| 607 |
| 608 // Bitset-constant |
| 609 CHECK(IsBitset(Type::Intersect(T.Integer31, T.Number))); |
| 610 CHECK(IsConstant(Type::Intersect(T.Integer31Constant, T.Number))); |
| 611 CHECK(IsConstant(Type::Intersect(T.ObjectConstant1, T.Object))); |
| 612 |
| 613 CheckEqual(T.Intersect(T.Integer31, T.Number), T.Integer31); |
| 614 CheckEqual(T.Intersect(T.Integer31Constant, T.Number), T.Integer31Constant); |
| 615 CheckEqual(T.Intersect(T.ObjectConstant1, T.Object), T.ObjectConstant1); |
| 616 |
| 617 // Class-constant |
| 618 CHECK(IsBitset(Type::Intersect(T.ObjectConstant1, T.ObjectClass))); |
| 619 CHECK(IsBitset(Type::Intersect(T.ArrayClass, T.ObjectConstant2))); |
| 620 |
| 621 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); |
| 622 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); |
| 623 |
| 624 // Bitset-union |
| 625 CHECK(IsUnion( |
| 626 Type::Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); |
| 627 CHECK(IsBitset( |
| 628 Type::Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); |
| 629 |
| 630 CheckEqual( |
| 631 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 632 T.Union(T.ObjectConstant1, T.ObjectClass)); |
| 633 CheckEqual( |
| 634 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), |
| 635 T.None); |
| 636 |
| 637 // Class-union |
| 638 CHECK(IsClass( |
| 639 Type::Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); |
| 640 CHECK(IsClass( |
| 641 Type::Intersect(T.Union(T.Object, T.Integer31Constant), T.ArrayClass))); |
| 642 CHECK(IsBitset( |
| 643 Type::Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass))); |
| 644 |
| 645 CheckEqual( |
| 646 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), |
| 647 T.ArrayClass); |
| 648 CheckEqual( |
| 649 T.Intersect(T.ArrayClass, T.Union(T.Object, T.Integer31Constant)), |
| 650 T.ArrayClass); |
| 651 CheckEqual( |
| 652 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass), |
| 653 T.None); |
| 654 |
| 655 // Constant-union |
| 656 CHECK(IsConstant(Type::Intersect( |
| 657 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); |
| 658 CHECK(IsConstant(Type::Intersect( |
| 659 T.Union(T.Number, T.ObjectClass), T.Integer31Constant))); |
| 660 CHECK(IsBitset(Type::Intersect( |
| 661 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); |
| 662 |
| 663 CheckEqual( |
| 664 T.Intersect( |
| 665 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 666 T.ObjectConstant1); |
| 667 CheckEqual( |
| 668 T.Intersect(T.Integer31Constant, T.Union(T.Number, T.ObjectConstant2)), |
| 669 T.Integer31Constant); |
| 670 CheckEqual( |
| 671 T.Intersect(T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1), |
| 672 T.None); |
| 673 |
| 674 // Union-union |
| 675 CHECK(IsUnion(Type::Intersect( |
| 676 T.Union(T.Number, T.ArrayClass), T.Union(T.Integer32, T.Array)))); |
| 677 CHECK(IsBitset(Type::Intersect( |
| 678 T.Union(T.Number, T.ObjectClass), T.Union(T.Integer32, T.Array)))); |
| 679 |
| 680 CheckEqual( |
| 681 T.Intersect( |
| 682 T.Union(T.Number, T.ArrayClass), |
| 683 T.Union(T.Integer31, T.Array)), |
| 684 T.Union(T.Integer31, T.ArrayClass)); |
| 685 CheckEqual( |
| 686 T.Intersect( |
| 687 T.Union(T.Number, T.ObjectClass), |
| 688 T.Union(T.Integer32, T.Array)), |
| 689 T.Integer32); |
| 690 CheckEqual( |
| 691 T.Intersect( |
| 692 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 693 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 694 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 695 CheckEqual( |
| 696 T.Intersect( |
| 697 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), |
| 698 T.Union( |
| 699 T.ObjectConstant1, T.Union(T.ArrayConstant1, T.ObjectConstant2))), |
| 700 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 701 CheckEqual( |
| 702 T.Intersect( |
| 703 T.Union(T.ObjectConstant2, T.ArrayConstant1), |
| 704 T.Union(T.ObjectConstant1, T.ArrayConstant2)), |
| 705 T.ArrayConstant1); |
| 706 } |
OLD | NEW |