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 15 matching lines...) Expand all Loading... |
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(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 IsUnion(Type* type) { return type->IsFixedArray(); } | 37 static bool IsUnion(Type* type) { return type->IsFixedArray(); } |
37 static bool IsConstant(Type* type) { | |
38 return !(IsBitset(type) || IsClass(type) || IsUnion(type)); | |
39 } | |
40 | 38 |
41 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } | 39 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } |
42 static Map* AsClass(Type* type) { return Map::cast(type); } | 40 static Map* AsClass(Type* type) { return Map::cast(type); } |
43 static HeapObject* AsConstant(Type* type) { return HeapObject::cast(type); } | 41 static Object* AsConstant(Type* type) { return Box::cast(type)->value(); } |
44 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } | 42 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } |
45 | 43 |
46 class HandlifiedTypes { | 44 class HandlifiedTypes { |
47 public: | 45 public: |
48 explicit HandlifiedTypes(Isolate* isolate) : | 46 explicit HandlifiedTypes(Isolate* isolate) : |
49 None(Type::None(), isolate), | 47 None(Type::None(), isolate), |
50 Any(Type::Any(), isolate), | 48 Any(Type::Any(), isolate), |
51 Oddball(Type::Oddball(), isolate), | 49 Oddball(Type::Oddball(), isolate), |
52 Boolean(Type::Boolean(), isolate), | 50 Boolean(Type::Boolean(), isolate), |
53 Null(Type::Null(), isolate), | 51 Null(Type::Null(), isolate), |
54 Undefined(Type::Undefined(), isolate), | 52 Undefined(Type::Undefined(), isolate), |
55 Number(Type::Number(), isolate), | 53 Number(Type::Number(), isolate), |
56 Smi(Type::Smi(), isolate), | 54 Smi(Type::Smi(), isolate), |
57 Double(Type::Double(), isolate), | 55 Double(Type::Double(), isolate), |
58 Name(Type::Name(), isolate), | 56 Name(Type::Name(), isolate), |
59 UniqueName(Type::UniqueName(), isolate), | 57 UniqueName(Type::UniqueName(), isolate), |
60 String(Type::String(), isolate), | 58 String(Type::String(), isolate), |
61 InternalizedString(Type::InternalizedString(), isolate), | 59 InternalizedString(Type::InternalizedString(), isolate), |
62 Symbol(Type::Symbol(), isolate), | 60 Symbol(Type::Symbol(), isolate), |
63 Receiver(Type::Receiver(), isolate), | 61 Receiver(Type::Receiver(), isolate), |
64 Object(Type::Object(), isolate), | 62 Object(Type::Object(), isolate), |
65 Array(Type::Array(), isolate), | 63 Array(Type::Array(), isolate), |
66 Function(Type::Function(), isolate), | 64 Function(Type::Function(), isolate), |
67 Proxy(Type::Proxy(), isolate), | 65 Proxy(Type::Proxy(), isolate), |
68 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), | 66 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), |
69 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), | 67 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), |
70 isolate_(isolate) { | 68 isolate_(isolate) { |
| 69 smi = handle(Smi::FromInt(666), isolate); |
71 object1 = isolate->factory()->NewJSObjectFromMap(object_map); | 70 object1 = isolate->factory()->NewJSObjectFromMap(object_map); |
72 object2 = isolate->factory()->NewJSObjectFromMap(object_map); | 71 object2 = isolate->factory()->NewJSObjectFromMap(object_map); |
73 array = isolate->factory()->NewJSArray(20); | 72 array = isolate->factory()->NewJSArray(20); |
74 ObjectClass = handle(Type::Class(object_map), isolate); | 73 ObjectClass = handle(Type::Class(object_map), isolate); |
75 ArrayClass = handle(Type::Class(array_map), isolate); | 74 ArrayClass = handle(Type::Class(array_map), isolate); |
| 75 SmiConstant = handle(Type::Constant(smi, isolate), isolate); |
76 ObjectConstant1 = handle(Type::Constant(object1), isolate); | 76 ObjectConstant1 = handle(Type::Constant(object1), isolate); |
77 ObjectConstant2 = handle(Type::Constant(object2), isolate); | 77 ObjectConstant2 = handle(Type::Constant(object2), isolate); |
78 ArrayConstant = handle(Type::Constant(array), isolate); | 78 ArrayConstant = handle(Type::Constant(array), isolate); |
79 } | 79 } |
80 | 80 |
81 Handle<Type> None; | 81 Handle<Type> None; |
82 Handle<Type> Any; | 82 Handle<Type> Any; |
83 Handle<Type> Oddball; | 83 Handle<Type> Oddball; |
84 Handle<Type> Boolean; | 84 Handle<Type> Boolean; |
85 Handle<Type> Null; | 85 Handle<Type> Null; |
86 Handle<Type> Undefined; | 86 Handle<Type> Undefined; |
87 Handle<Type> Number; | 87 Handle<Type> Number; |
88 Handle<Type> Smi; | 88 Handle<Type> Smi; |
89 Handle<Type> Double; | 89 Handle<Type> Double; |
90 Handle<Type> Name; | 90 Handle<Type> Name; |
91 Handle<Type> UniqueName; | 91 Handle<Type> UniqueName; |
92 Handle<Type> String; | 92 Handle<Type> String; |
93 Handle<Type> InternalizedString; | 93 Handle<Type> InternalizedString; |
94 Handle<Type> Symbol; | 94 Handle<Type> Symbol; |
95 Handle<Type> Receiver; | 95 Handle<Type> Receiver; |
96 Handle<Type> Object; | 96 Handle<Type> Object; |
97 Handle<Type> Array; | 97 Handle<Type> Array; |
98 Handle<Type> Function; | 98 Handle<Type> Function; |
99 Handle<Type> Proxy; | 99 Handle<Type> Proxy; |
100 | 100 |
101 Handle<Type> ObjectClass; | 101 Handle<Type> ObjectClass; |
102 Handle<Type> ArrayClass; | 102 Handle<Type> ArrayClass; |
| 103 |
| 104 Handle<Type> SmiConstant; |
103 Handle<Type> ObjectConstant1; | 105 Handle<Type> ObjectConstant1; |
104 Handle<Type> ObjectConstant2; | 106 Handle<Type> ObjectConstant2; |
105 Handle<Type> ArrayConstant; | 107 Handle<Type> ArrayConstant; |
106 | 108 |
107 Handle<Map> object_map; | 109 Handle<Map> object_map; |
108 Handle<Map> array_map; | 110 Handle<Map> array_map; |
109 | 111 |
| 112 Handle<v8::internal::Smi> smi; |
110 Handle<JSObject> object1; | 113 Handle<JSObject> object1; |
111 Handle<JSObject> object2; | 114 Handle<JSObject> object2; |
112 Handle<JSArray> array; | 115 Handle<JSArray> array; |
113 | 116 |
114 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) { | 117 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) { |
115 return handle(Type::Union(type1, type2), isolate_); | 118 return handle(Type::Union(type1, type2), isolate_); |
116 } | 119 } |
117 | 120 |
118 private: | 121 private: |
119 Isolate* isolate_; | 122 Isolate* isolate_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 CHECK(*T.array_map == AsClass(*T.ArrayClass)); | 161 CHECK(*T.array_map == AsClass(*T.ArrayClass)); |
159 } | 162 } |
160 | 163 |
161 | 164 |
162 TEST(Constant) { | 165 TEST(Constant) { |
163 CcTest::InitializeVM(); | 166 CcTest::InitializeVM(); |
164 Isolate* isolate = Isolate::Current(); | 167 Isolate* isolate = Isolate::Current(); |
165 HandleScope scope(isolate); | 168 HandleScope scope(isolate); |
166 HandlifiedTypes T(isolate); | 169 HandlifiedTypes T(isolate); |
167 | 170 |
| 171 CHECK(IsConstant(*T.SmiConstant)); |
168 CHECK(IsConstant(*T.ObjectConstant1)); | 172 CHECK(IsConstant(*T.ObjectConstant1)); |
169 CHECK(IsConstant(*T.ObjectConstant2)); | 173 CHECK(IsConstant(*T.ObjectConstant2)); |
170 CHECK(IsConstant(*T.ArrayConstant)); | 174 CHECK(IsConstant(*T.ArrayConstant)); |
171 | 175 |
| 176 CHECK(*T.smi == AsConstant(*T.SmiConstant)); |
172 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); | 177 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); |
173 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); | 178 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); |
174 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); | 179 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); |
175 CHECK(*T.array == AsConstant(*T.ArrayConstant)); | 180 CHECK(*T.array == AsConstant(*T.ArrayConstant)); |
176 } | 181 } |
177 | 182 |
178 | 183 |
179 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { | 184 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { |
180 CHECK(type1->Is(type2)); | 185 CHECK(type1->Is(type2)); |
181 CHECK(!type2->Is(type1)); | 186 CHECK(!type2->Is(type1)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 CheckSub(T.Function, T.Object); | 248 CheckSub(T.Function, T.Object); |
244 CheckSub(T.Proxy, T.Receiver); | 249 CheckSub(T.Proxy, T.Receiver); |
245 CheckUnordered(T.Object, T.Proxy); | 250 CheckUnordered(T.Object, T.Proxy); |
246 CheckUnordered(T.Array, T.Function); | 251 CheckUnordered(T.Array, T.Function); |
247 | 252 |
248 // Structured subtyping | 253 // Structured subtyping |
249 CheckSub(T.ObjectClass, T.Object); | 254 CheckSub(T.ObjectClass, T.Object); |
250 CheckSub(T.ArrayClass, T.Object); | 255 CheckSub(T.ArrayClass, T.Object); |
251 CheckUnordered(T.ObjectClass, T.ArrayClass); | 256 CheckUnordered(T.ObjectClass, T.ArrayClass); |
252 | 257 |
| 258 CheckSub(T.SmiConstant, T.Smi); |
| 259 CheckSub(T.SmiConstant, T.Number); |
253 CheckSub(T.ObjectConstant1, T.Object); | 260 CheckSub(T.ObjectConstant1, T.Object); |
254 CheckSub(T.ObjectConstant2, T.Object); | 261 CheckSub(T.ObjectConstant2, T.Object); |
255 CheckSub(T.ArrayConstant, T.Object); | 262 CheckSub(T.ArrayConstant, T.Object); |
256 CheckSub(T.ArrayConstant, T.Array); | 263 CheckSub(T.ArrayConstant, T.Array); |
257 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); | 264 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); |
258 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); | 265 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); |
259 | 266 |
260 CheckUnordered(T.ObjectConstant1, T.ObjectClass); | 267 CheckUnordered(T.ObjectConstant1, T.ObjectClass); |
261 CheckUnordered(T.ObjectConstant2, T.ObjectClass); | 268 CheckUnordered(T.ObjectConstant2, T.ObjectClass); |
262 CheckUnordered(T.ObjectConstant1, T.ArrayClass); | 269 CheckUnordered(T.ObjectConstant1, T.ArrayClass); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 CheckOverlap(T.Proxy, T.Receiver); | 333 CheckOverlap(T.Proxy, T.Receiver); |
327 CheckDisjoint(T.Object, T.Proxy); | 334 CheckDisjoint(T.Object, T.Proxy); |
328 CheckDisjoint(T.Array, T.Function); | 335 CheckDisjoint(T.Array, T.Function); |
329 | 336 |
330 CheckOverlap(T.ObjectClass, T.Object); | 337 CheckOverlap(T.ObjectClass, T.Object); |
331 CheckOverlap(T.ArrayClass, T.Object); | 338 CheckOverlap(T.ArrayClass, T.Object); |
332 CheckOverlap(T.ObjectClass, T.ObjectClass); | 339 CheckOverlap(T.ObjectClass, T.ObjectClass); |
333 CheckOverlap(T.ArrayClass, T.ArrayClass); | 340 CheckOverlap(T.ArrayClass, T.ArrayClass); |
334 CheckDisjoint(T.ObjectClass, T.ArrayClass); | 341 CheckDisjoint(T.ObjectClass, T.ArrayClass); |
335 | 342 |
| 343 CheckOverlap(T.SmiConstant, T.Smi); |
| 344 CheckOverlap(T.SmiConstant, T.Number); |
| 345 CheckDisjoint(T.SmiConstant, T.Double); |
336 CheckOverlap(T.ObjectConstant1, T.Object); | 346 CheckOverlap(T.ObjectConstant1, T.Object); |
337 CheckOverlap(T.ObjectConstant2, T.Object); | 347 CheckOverlap(T.ObjectConstant2, T.Object); |
338 CheckOverlap(T.ArrayConstant, T.Object); | 348 CheckOverlap(T.ArrayConstant, T.Object); |
339 CheckOverlap(T.ArrayConstant, T.Array); | 349 CheckOverlap(T.ArrayConstant, T.Array); |
340 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); | 350 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); |
341 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); | 351 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); |
342 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant); | 352 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant); |
343 | 353 |
344 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); | 354 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); |
345 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); | 355 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 425 |
416 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); | 426 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); |
417 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); | 427 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); |
418 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); | 428 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); |
419 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); | 429 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); |
420 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); | 430 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); |
421 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); | 431 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); |
422 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); | 432 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); |
423 | 433 |
424 // Bitset-constant | 434 // Bitset-constant |
| 435 CHECK(IsBitset(Type::Union(T.SmiConstant, T.Number))); |
425 CHECK(IsBitset(Type::Union(T.ObjectConstant1, T.Object))); | 436 CHECK(IsBitset(Type::Union(T.ObjectConstant1, T.Object))); |
426 CHECK(IsUnion(Type::Union(T.ObjectConstant2, T.Number))); | 437 CHECK(IsUnion(Type::Union(T.ObjectConstant2, T.Number))); |
427 | 438 |
| 439 CheckEqual(T.Union(T.SmiConstant, T.Number), T.Number); |
428 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); | 440 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); |
429 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); | 441 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); |
430 CheckSub(T.Union(T.ObjectConstant1, T.Smi), T.Union(T.Object, T.Number)); | 442 CheckSub(T.Union(T.ObjectConstant1, T.Smi), T.Union(T.Object, T.Number)); |
431 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); | 443 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); |
432 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); | 444 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); |
433 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); | 445 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); |
434 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); | 446 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); |
435 | 447 |
436 // Class-constant | 448 // Class-constant |
437 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); | 449 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 524 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
513 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 525 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
514 CheckEqual( | 526 CheckEqual( |
515 T.Union(T.Union(T.ObjectConstant2, T.ArrayConstant), | 527 T.Union(T.Union(T.ObjectConstant2, T.ArrayConstant), |
516 T.Union(T.ObjectConstant1, T.ArrayConstant)), | 528 T.Union(T.ObjectConstant1, T.ArrayConstant)), |
517 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant)); | 529 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant)); |
518 CheckEqual( | 530 CheckEqual( |
519 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), | 531 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), |
520 T.Union(T.Number, T.Array)); | 532 T.Union(T.Number, T.Array)); |
521 } | 533 } |
OLD | NEW |