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

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

Issue 232843002: Yet more type system tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Doc Created 6 years, 8 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
« src/types.h ('K') | « src/types.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #define DECLARE_TYPE(name, value) \ 43 #define DECLARE_TYPE(name, value) \
44 name = Type::name(region); \ 44 name = Type::name(region); \
45 types.push_back(name); 45 types.push_back(name);
46 BITSET_TYPE_LIST(DECLARE_TYPE) 46 BITSET_TYPE_LIST(DECLARE_TYPE)
47 #undef DECLARE_TYPE 47 #undef DECLARE_TYPE
48 48
49 object_map = isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize); 49 object_map = isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize);
50 array_map = isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize); 50 array_map = isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize);
51 ObjectClass = Type::Class(object_map, region); 51 ObjectClass = Type::Class(object_map, region);
52 ArrayClass = Type::Class(array_map, region); 52 ArrayClass = Type::Class(array_map, region);
53 types.push_back(ObjectClass); 53
54 types.push_back(ArrayClass); 54 maps.push_back(object_map);
55 maps.push_back(array_map);
56 for (MapVector::iterator it = maps.begin(); it != maps.end(); ++it) {
57 types.push_back(Type::Class(*it, region));
58 }
55 59
56 smi = handle(Smi::FromInt(666), isolate); 60 smi = handle(Smi::FromInt(666), isolate);
57 signed32 = isolate->factory()->NewHeapNumber(0x40000000); 61 signed32 = isolate->factory()->NewHeapNumber(0x40000000);
58 object1 = isolate->factory()->NewJSObjectFromMap(object_map); 62 object1 = isolate->factory()->NewJSObjectFromMap(object_map);
59 object2 = isolate->factory()->NewJSObjectFromMap(object_map); 63 object2 = isolate->factory()->NewJSObjectFromMap(object_map);
60 array = isolate->factory()->NewJSArray(20); 64 array = isolate->factory()->NewJSArray(20);
65 SmiConstant = Type::Constant(smi, region);
66 Signed32Constant = Type::Constant(signed32, region);
67 ObjectConstant1 = Type::Constant(object1, region);
68 ObjectConstant2 = Type::Constant(object2, region);
69 ArrayConstant = Type::Constant(array, region);
70
61 values.push_back(smi); 71 values.push_back(smi);
62 values.push_back(signed32); 72 values.push_back(signed32);
63 values.push_back(object1); 73 values.push_back(object1);
64 values.push_back(object2); 74 values.push_back(object2);
65 values.push_back(array); 75 values.push_back(array);
66 SmiConstant = Type::Constant(smi, region);
67 Signed32Constant = Type::Constant(signed32, region);
68 ObjectConstant1 = Type::Constant(object1, region);
69 ObjectConstant2 = Type::Constant(object2, region);
70 ArrayConstant = Type::Constant(array, region);
71 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) { 76 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) {
72 types.push_back(Type::Constant(*it, region)); 77 types.push_back(Type::Constant(*it, region));
73 } 78 }
74 79
75 while (types.size() < kMaxTypes) { 80 while (types.size() < kMaxTypes) {
76 size_t i = rng.NextInt(types.size()); 81 size_t i = rng.NextInt(types.size());
77 size_t j = rng.NextInt(types.size()); 82 size_t j = rng.NextInt(types.size());
78 if (i != j) types.push_back(Type::Union(types[i], types[j], region)); 83 if (i != j) types.push_back(Type::Union(types[i], types[j], region));
79 } 84 }
80 } 85 }
(...skipping 16 matching lines...) Expand all
97 Handle<i::Map> object_map; 102 Handle<i::Map> object_map;
98 Handle<i::Map> array_map; 103 Handle<i::Map> array_map;
99 104
100 Handle<i::Smi> smi; 105 Handle<i::Smi> smi;
101 Handle<i::HeapNumber> signed32; 106 Handle<i::HeapNumber> signed32;
102 Handle<i::JSObject> object1; 107 Handle<i::JSObject> object1;
103 Handle<i::JSObject> object2; 108 Handle<i::JSObject> object2;
104 Handle<i::JSArray> array; 109 Handle<i::JSArray> array;
105 110
106 typedef std::vector<TypeHandle> TypeVector; 111 typedef std::vector<TypeHandle> TypeVector;
112 typedef std::vector<Handle<i::Map> > MapVector;
113 typedef std::vector<Handle<i::Object> > ValueVector;
107 TypeVector types; 114 TypeVector types;
108 115 MapVector maps;
109 typedef std::vector<Handle<i::Object> > ValueVector;
110 ValueVector values; 116 ValueVector values;
111 117
112 TypeHandle Of(Handle<i::Object> obj) { 118 TypeHandle Of(Handle<i::Object> value) {
113 return Type::Of(obj, region_); 119 return Type::Of(value, region_);
114 } 120 }
115 121
116 TypeHandle NowOf(Handle<i::Object> obj) { 122 TypeHandle NowOf(Handle<i::Object> value) {
117 return Type::NowOf(obj, region_); 123 return Type::NowOf(value, region_);
118 } 124 }
119 125
120 TypeHandle Constant(Handle<i::Object> obj) { 126 TypeHandle Constant(Handle<i::Object> value) {
121 return Type::Constant(obj, region_); 127 return Type::Constant(value, region_);
128 }
129
130 TypeHandle Class(Handle<i::Map> map) {
131 return Type::Class(map, region_);
122 } 132 }
123 133
124 TypeHandle Union(TypeHandle t1, TypeHandle t2) { 134 TypeHandle Union(TypeHandle t1, TypeHandle t2) {
125 return Type::Union(t1, t2, region_); 135 return Type::Union(t1, t2, region_);
126 } 136 }
127 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) { 137 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) {
128 return Type::Intersect(t1, t2, region_); 138 return Type::Intersect(t1, t2, region_);
129 } 139 }
130 140
131 template<class Type2, class TypeHandle2> 141 template<class Type2, class TypeHandle2>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 static int Length(Struct* structured) { return structured->length() - 1; } 204 static int Length(Struct* structured) { return structured->length() - 1; }
195 205
196 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 206 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
197 }; 207 };
198 208
199 209
200 template<class Type, class TypeHandle, class Region, class Rep> 210 template<class Type, class TypeHandle, class Region, class Rep>
201 struct Tests : Rep { 211 struct Tests : Rep {
202 typedef Types<Type, TypeHandle, Region> TypesInstance; 212 typedef Types<Type, TypeHandle, Region> TypesInstance;
203 typedef typename TypesInstance::TypeVector::iterator TypeIterator; 213 typedef typename TypesInstance::TypeVector::iterator TypeIterator;
214 typedef typename TypesInstance::MapVector::iterator MapIterator;
204 typedef typename TypesInstance::ValueVector::iterator ValueIterator; 215 typedef typename TypesInstance::ValueVector::iterator ValueIterator;
205 216
206 Isolate* isolate; 217 Isolate* isolate;
207 HandleScope scope; 218 HandleScope scope;
208 Zone zone; 219 Zone zone;
209 TypesInstance T; 220 TypesInstance T;
210 221
211 Tests() : 222 Tests() :
212 isolate(CcTest::i_isolate()), 223 isolate(CcTest::i_isolate()),
213 scope(isolate), 224 scope(isolate),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 CHECK(!type2->Is(type1)); 277 CHECK(!type2->Is(type1));
267 CHECK(!type1->Maybe(type2)); 278 CHECK(!type1->Maybe(type2));
268 CHECK(!type2->Maybe(type1)); 279 CHECK(!type2->Maybe(type1));
269 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 280 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
270 CHECK_EQ(0, 281 CHECK_EQ(0,
271 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask)); 282 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask));
272 } 283 }
273 } 284 }
274 285
275 void Bitset() { 286 void Bitset() {
287 // None and Any are bitsets.
276 CHECK(this->IsBitset(T.None)); 288 CHECK(this->IsBitset(T.None));
277 CHECK(this->IsBitset(T.Any)); 289 CHECK(this->IsBitset(T.Any));
278 CHECK(this->IsBitset(T.String));
279 CHECK(this->IsBitset(T.Object));
280
281 CHECK(this->IsBitset(T.Union(T.String, T.Number)));
282 CHECK(this->IsBitset(T.Union(T.String, T.Receiver)));
283 290
284 CHECK_EQ(0, this->AsBitset(T.None)); 291 CHECK_EQ(0, this->AsBitset(T.None));
285 CHECK_EQ( 292 CHECK_EQ(-1, this->AsBitset(T.Any));
286 this->AsBitset(T.Number) | this->AsBitset(T.String), 293
287 this->AsBitset(T.Union(T.String, T.Number))); 294 // Union(T1, T2) is a bitset for all bitsets T1,T2
288 CHECK_EQ( 295 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
289 this->AsBitset(T.Receiver), 296 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
290 this->AsBitset(T.Union(T.Receiver, T.Object))); 297 TypeHandle type1 = *it1;
298 TypeHandle type2 = *it2;
299 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) ||
300 this->IsBitset(T.Union(type1, type2)));
301 }
302 }
303
304 // Union(T1, T2) is a bitset if T2 is a bitset and T1->Is(T2)
305 // (and vice versa).
306 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
307 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
308 TypeHandle type1 = *it1;
309 TypeHandle type2 = *it2;
310 CHECK(!(this->IsBitset(type2) && type1->Is(type2)) ||
311 this->IsBitset(T.Union(type1, type2)));
312 CHECK(!(this->IsBitset(type1) && type2->Is(type1)) ||
313 this->IsBitset(T.Union(type1, type2)));
314 }
315 }
316
317 // Union(T1, T2) is bitwise disjunction for all bitsets T1,T2
318 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
319 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
320 TypeHandle type1 = *it1;
321 TypeHandle type2 = *it2;
322 if (this->IsBitset(type1) && this->IsBitset(type2)) {
323 CHECK_EQ(
324 this->AsBitset(type1) | this->AsBitset(type2),
325 this->AsBitset(T.Union(type1, type2)));
326 }
327 }
328 }
329
330 // Intersect(T1, T2) is bitwise conjunction for all bitsets T1,T2
331 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
332 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
333 TypeHandle type1 = *it1;
334 TypeHandle type2 = *it2;
335 if (this->IsBitset(type1) && this->IsBitset(type2)) {
336 CHECK_EQ(
337 this->AsBitset(type1) & this->AsBitset(type2),
338 this->AsBitset(T.Intersect(type1, type2)));
339 }
340 }
341 }
291 } 342 }
292 343
293 void Class() { 344 void Class() {
294 CHECK(this->IsClass(T.ObjectClass)); 345 // Constructor
295 CHECK(this->IsClass(T.ArrayClass)); 346 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
347 Handle<i::Map> map = *mt;
348 CHECK(this->IsClass(T.Class(map)));
349 }
296 350
297 CHECK(*T.object_map == this->AsClass(T.ObjectClass)); 351 // Map attribute
298 CHECK(*T.array_map == this->AsClass(T.ArrayClass)); 352 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
353 Handle<i::Map> map = *mt;
354 CHECK(*map == *T.Class(map)->AsClass());
355 }
356
357 // Functionality & Injectivity
358 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
359 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
360 Handle<i::Map> map1 = *mt1;
361 Handle<i::Map> map2 = *mt2;
362 CHECK(T.Class(map1)->Is(T.Class(map2)) == (*map1 == *map2));
363 }
364 }
299 } 365 }
300 366
301 void Constant() { 367 void Constant() {
302 CHECK(this->IsConstant(T.SmiConstant)); 368 // Constructor
303 CHECK(this->IsConstant(T.ObjectConstant1)); 369 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
304 CHECK(this->IsConstant(T.ObjectConstant2)); 370 Handle<i::Object> value = *vt;
305 CHECK(this->IsConstant(T.ArrayConstant)); 371 CHECK(this->IsConstant(T.Constant(value)));
372 }
306 373
307 CHECK(*T.smi == this->AsConstant(T.SmiConstant)); 374 // Value attribute
308 CHECK(*T.object1 == this->AsConstant(T.ObjectConstant1)); 375 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
309 CHECK(*T.object2 == this->AsConstant(T.ObjectConstant2)); 376 Handle<i::Object> value = *vt;
310 CHECK(*T.object1 != this->AsConstant(T.ObjectConstant2)); 377 CHECK(*value == *T.Constant(value)->AsConstant());
311 CHECK(*T.array == this->AsConstant(T.ArrayConstant)); 378 }
379
380 // Functionality & Injectivity
381 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) {
382 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) {
383 Handle<i::Object> val1 = *vt1;
384 Handle<i::Object> val2 = *vt2;
385 CHECK(T.Constant(val1)->Is(T.Constant(val2)) == (*val1 == *val2));
386 }
387 }
312 } 388 }
313 389
314 void Of() { 390 void Of() {
315 CHECK(T.Of(T.smi)->Is(T.SignedSmall)); 391 // Constant(V)->Is(Of(V)) for all V
316 CHECK(T.Of(T.signed32)->Is(T.Signed32)); 392 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
317 CHECK(T.Of(T.object1)->Is(T.Object)); 393 Handle<i::Object> value = *vt;
318 CHECK(T.Of(T.object2)->Is(T.Object)); 394 CHECK(T.Constant(value)->Is(T.Of(value)));
319 CHECK(T.Of(T.array)->Is(T.Array)); 395 }
396
397 // Constant(V)->Is(T) implies Of(V)->Is(T) or T->Maybe(Constant(V))
398 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
399 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
400 Handle<i::Object> value = *vt;
401 TypeHandle type = *it;
402 CHECK(!T.Constant(value)->Is(type) ||
403 T.Of(value)->Is(type) || type->Maybe(T.Constant(value)));
404 }
405 }
320 } 406 }
321 407
322 void NowOf() { 408 void NowOf() {
409 // Constant(V)->NowIs(NowOf(V)) for all V
410 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
411 Handle<i::Object> value = *vt;
412 CHECK(T.Constant(value)->NowIs(T.NowOf(value)));
413 }
414
323 // NowOf(V)->Is(Of(V)) for all V 415 // NowOf(V)->Is(Of(V)) for all V
324 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 416 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
325 Handle<i::Object> val = *vt; 417 Handle<i::Object> value = *vt;
326 CHECK(T.NowOf(val)->Is(T.Of(val))); 418 CHECK(T.NowOf(value)->Is(T.Of(value)));
327 } 419 }
328 420
329 CHECK(T.NowOf(T.smi)->NowIs(T.SignedSmall)); 421 // Constant(V)->Is(T) implies NowOf(V)->Is(T) or T->Maybe(Constant(V))
330 CHECK(T.NowOf(T.signed32)->NowIs(T.Signed32)); 422 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
331 CHECK(T.NowOf(T.object1)->NowIs(T.ObjectClass)); 423 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
332 CHECK(T.NowOf(T.object2)->NowIs(T.ObjectClass)); 424 Handle<i::Object> value = *vt;
333 CHECK(T.NowOf(T.array)->NowIs(T.Array)); 425 TypeHandle type = *it;
426 CHECK(!T.Constant(value)->Is(type) ||
427 T.NowOf(value)->Is(type) || type->Maybe(T.Constant(value)));
428 }
429 }
430
431 // Constant(V)->NowIs(T) implies NowOf(V)->NowIs(T) or T->Maybe(Constant(V))
432 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
433 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
434 Handle<i::Object> value = *vt;
435 TypeHandle type = *it;
436 CHECK(!T.Constant(value)->NowIs(type) ||
437 T.NowOf(value)->NowIs(type) || type->Maybe(T.Constant(value)));
438 }
439 }
334 } 440 }
335 441
336 void Is() { 442 void Is() {
337 // T->Is(None) implies T = None for all T 443 // T->Is(None) implies T = None for all T
338 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 444 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
339 TypeHandle type = *it; 445 TypeHandle type = *it;
340 if (type->Is(T.None)) CheckEqual(type, T.None); 446 if (type->Is(T.None)) CheckEqual(type, T.None);
341 } 447 }
342 448
343 // None->Is(T) for all T 449 // None->Is(T) for all T
(...skipping 20 matching lines...) Expand all
364 CHECK(type->Is(type)); 470 CHECK(type->Is(type));
365 } 471 }
366 472
367 // Transitivity 473 // Transitivity
368 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 474 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
369 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 475 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
370 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 476 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
371 TypeHandle type1 = *it1; 477 TypeHandle type1 = *it1;
372 TypeHandle type2 = *it2; 478 TypeHandle type2 = *it2;
373 TypeHandle type3 = *it3; 479 TypeHandle type3 = *it3;
374 CHECK(!type1->Is(type2) || 480 CHECK(!(type1->Is(type2) && type2->Is(type3)) || type1->Is(type3));
375 !type2->Is(type3) ||
376 type1->Is(type3));
377 } 481 }
378 } 482 }
379 } 483 }
380 484
381 // Symmetry and Transitivity 485 // Constant(V1)->Is(Constant(V2)) iff V1 = V2
382 CheckSub(T.None, T.Number); 486 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) {
383 CheckSub(T.None, T.Any); 487 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) {
488 Handle<i::Object> val1 = *vt1;
489 Handle<i::Object> val2 = *vt2;
490 CHECK(T.Constant(val1)->Is(T.Constant(val2)) == (*val1 == *val2));
491 }
492 }
384 493
494 // Class(M1)->Is(Class(M2)) iff M1 = M2
495 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
496 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
497 Handle<i::Map> map1 = *mt1;
498 Handle<i::Map> map2 = *mt2;
499 CHECK(T.Class(map1)->Is(T.Class(map2)) == (*map1 == *map2));
500 }
501 }
502
503 // Constant(V)->Is(Class(M)) for no V,M
504 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
505 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
506 Handle<i::Map> map = *mt;
507 Handle<i::Object> value = *vt;
508 CHECK(!T.Constant(value)->Is(T.Class(map)));
509 }
510 }
511
512 // Class(M)->Is(Constant(V)) for no V,M
513 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
514 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
515 Handle<i::Map> map = *mt;
516 Handle<i::Object> value = *vt;
517 CHECK(!T.Class(map)->Is(T.Constant(value)));
518 }
519 }
520
521 // Basic types
385 CheckUnordered(T.Boolean, T.Null); 522 CheckUnordered(T.Boolean, T.Null);
386 CheckUnordered(T.Undefined, T.Null); 523 CheckUnordered(T.Undefined, T.Null);
387 CheckUnordered(T.Boolean, T.Undefined); 524 CheckUnordered(T.Boolean, T.Undefined);
388 525
389 CheckSub(T.Number, T.Any);
390 CheckSub(T.SignedSmall, T.Number); 526 CheckSub(T.SignedSmall, T.Number);
391 CheckSub(T.Signed32, T.Number); 527 CheckSub(T.Signed32, T.Number);
392 CheckSub(T.Float, T.Number); 528 CheckSub(T.Float, T.Number);
393 CheckSub(T.SignedSmall, T.Signed32); 529 CheckSub(T.SignedSmall, T.Signed32);
394 CheckUnordered(T.SignedSmall, T.Float); 530 CheckUnordered(T.SignedSmall, T.Float);
395 CheckUnordered(T.Signed32, T.Float); 531 CheckUnordered(T.Signed32, T.Float);
396 532
397 CheckSub(T.Name, T.Any);
398 CheckSub(T.UniqueName, T.Any);
399 CheckSub(T.UniqueName, T.Name); 533 CheckSub(T.UniqueName, T.Name);
400 CheckSub(T.String, T.Name); 534 CheckSub(T.String, T.Name);
401 CheckSub(T.InternalizedString, T.String); 535 CheckSub(T.InternalizedString, T.String);
402 CheckSub(T.InternalizedString, T.UniqueName); 536 CheckSub(T.InternalizedString, T.UniqueName);
403 CheckSub(T.InternalizedString, T.Name); 537 CheckSub(T.InternalizedString, T.Name);
404 CheckSub(T.Symbol, T.UniqueName); 538 CheckSub(T.Symbol, T.UniqueName);
405 CheckSub(T.Symbol, T.Name); 539 CheckSub(T.Symbol, T.Name);
406 CheckUnordered(T.String, T.UniqueName); 540 CheckUnordered(T.String, T.UniqueName);
407 CheckUnordered(T.String, T.Symbol); 541 CheckUnordered(T.String, T.Symbol);
408 CheckUnordered(T.InternalizedString, T.Symbol); 542 CheckUnordered(T.InternalizedString, T.Symbol);
409 543
410 CheckSub(T.Receiver, T.Any);
411 CheckSub(T.Object, T.Any);
412 CheckSub(T.Object, T.Receiver); 544 CheckSub(T.Object, T.Receiver);
413 CheckSub(T.Array, T.Object); 545 CheckSub(T.Array, T.Object);
414 CheckSub(T.Function, T.Object); 546 CheckSub(T.Function, T.Object);
415 CheckSub(T.Proxy, T.Receiver); 547 CheckSub(T.Proxy, T.Receiver);
416 CheckUnordered(T.Object, T.Proxy); 548 CheckUnordered(T.Object, T.Proxy);
417 CheckUnordered(T.Array, T.Function); 549 CheckUnordered(T.Array, T.Function);
418 550
419 // Structured subtyping 551 // Structural types
420 CheckSub(T.None, T.ObjectClass);
421 CheckSub(T.None, T.ObjectConstant1);
422 CheckSub(T.ObjectClass, T.Any);
423 CheckSub(T.ObjectConstant1, T.Any);
424
425 CheckSub(T.ObjectClass, T.Object); 552 CheckSub(T.ObjectClass, T.Object);
426 CheckSub(T.ArrayClass, T.Object); 553 CheckSub(T.ArrayClass, T.Object);
427 CheckUnordered(T.ObjectClass, T.ArrayClass); 554 CheckUnordered(T.ObjectClass, T.ArrayClass);
428 555
429 CheckSub(T.SmiConstant, T.SignedSmall); 556 CheckSub(T.SmiConstant, T.SignedSmall);
430 CheckSub(T.SmiConstant, T.Signed32); 557 CheckSub(T.SmiConstant, T.Signed32);
431 CheckSub(T.SmiConstant, T.Number); 558 CheckSub(T.SmiConstant, T.Number);
432 CheckSub(T.ObjectConstant1, T.Object); 559 CheckSub(T.ObjectConstant1, T.Object);
433 CheckSub(T.ObjectConstant2, T.Object); 560 CheckSub(T.ObjectConstant2, T.Object);
434 CheckSub(T.ArrayConstant, T.Object); 561 CheckSub(T.ArrayConstant, T.Object);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 617
491 // T1->Is(T2) implies T1->NowIs(T2) for all T1,T2 618 // T1->Is(T2) implies T1->NowIs(T2) for all T1,T2
492 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 619 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
493 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 620 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
494 TypeHandle type1 = *it1; 621 TypeHandle type1 = *it1;
495 TypeHandle type2 = *it2; 622 TypeHandle type2 = *it2;
496 CHECK(!type1->Is(type2) || type1->NowIs(type2)); 623 CHECK(!type1->Is(type2) || type1->NowIs(type2));
497 } 624 }
498 } 625 }
499 626
500 CHECK(T.ObjectConstant1->NowIs(T.ObjectClass)); 627 // Constant(V1)->NowIs(Constant(V2)) iff V1 = V2
501 CHECK(T.ObjectConstant2->NowIs(T.ObjectClass)); 628 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) {
629 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) {
630 Handle<i::Object> val1 = *vt1;
631 Handle<i::Object> val2 = *vt2;
632 CHECK(T.Constant(val1)->NowIs(T.Constant(val2)) == (*val1 == *val2));
633 }
634 }
635
636 // Class(M1)->NowIs(Class(M2)) iff M1 = M2
637 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
638 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
639 Handle<i::Map> map1 = *mt1;
640 Handle<i::Map> map2 = *mt2;
641 CHECK(T.Class(map1)->NowIs(T.Class(map2)) == (*map1 == *map2));
642 }
643 }
644
645 // Constant(V)->NowIs(Class(M)) iff V has map M
646 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
647 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
648 Handle<i::Map> map = *mt;
649 Handle<i::Object> value = *vt;
650 CHECK((value->IsHeapObject() &&
651 i::HeapObject::cast(*value)->map() == *map)
652 == T.Constant(value)->NowIs(T.Class(map)));
653 }
654 }
655
656 // Class(M)->NowIs(Constant(V)) for no V,M
657 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
658 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
659 Handle<i::Map> map = *mt;
660 Handle<i::Object> value = *vt;
661 CHECK(!T.Class(map)->NowIs(T.Constant(value)));
662 }
663 }
502 } 664 }
503 665
504 void Contains() { 666 void Contains() {
505 // T->Contains(V) iff Constant(V)->Is(T) for all T,V 667 // T->Contains(V) iff Constant(V)->Is(T) for all T,V
506 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 668 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
507 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 669 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
508 TypeHandle type = *it; 670 TypeHandle type = *it;
509 Handle<i::Object> val = *vt; 671 Handle<i::Object> value = *vt;
510 CHECK(type->Contains(val) == T.Constant(val)->Is(type)); 672 CHECK(type->Contains(value) == T.Constant(value)->Is(type));
511 } 673 }
512 } 674 }
513 675
514 // Of(V)->Is(T) implies T->Contains(V) for all T,V 676 // Of(V)->Is(T) implies T->Contains(V) for all T,V
515 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 677 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
516 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 678 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
517 TypeHandle type = *it; 679 TypeHandle type = *it;
518 Handle<i::Object> val = *vt; 680 Handle<i::Object> value = *vt;
519 CHECK(!T.Of(val)->Is(type) || type->Contains(val)); 681 CHECK(!T.Of(value)->Is(type) || type->Contains(value));
520 } 682 }
521 } 683 }
522 } 684 }
523 685
524 void NowContains() { 686 void NowContains() {
525 // T->NowContains(V) iff Constant(V)->NowIs(T) for all T,V 687 // T->NowContains(V) iff Constant(V)->NowIs(T) for all T,V
526 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 688 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
527 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 689 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
528 TypeHandle type = *it; 690 TypeHandle type = *it;
529 Handle<i::Object> val = *vt; 691 Handle<i::Object> value = *vt;
530 CHECK(type->NowContains(val) == T.Constant(val)->NowIs(type)); 692 CHECK(type->NowContains(value) == T.Constant(value)->NowIs(type));
693 }
694 }
695
696 // T->Contains(V) implies T->NowContains(V) for all T,V
697 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
698 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
699 TypeHandle type = *it;
700 Handle<i::Object> value = *vt;
701 CHECK(!type->Contains(value) || type->NowContains(value));
531 } 702 }
532 } 703 }
533 704
534 // NowOf(V)->Is(T) implies T->NowContains(V) for all T,V 705 // NowOf(V)->Is(T) implies T->NowContains(V) for all T,V
535 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 706 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
536 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 707 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
537 TypeHandle type = *it; 708 TypeHandle type = *it;
538 Handle<i::Object> value = *vt; 709 Handle<i::Object> value = *vt;
539 CHECK(!T.NowOf(value)->NowIs(type) || type->NowContains(value)); 710 CHECK(!T.NowOf(value)->NowIs(type) || type->NowContains(value));
540 } 711 }
541 } 712 }
542 713
543 // NowOf(V)->NowIs(T) implies T->NowContains(V) for all T,V 714 // NowOf(V)->NowIs(T) implies T->NowContains(V) for all T,V
544 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 715 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
545 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 716 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
546 TypeHandle type = *it; 717 TypeHandle type = *it;
547 Handle<i::Object> val = *vt; 718 Handle<i::Object> value = *vt;
548 CHECK(!T.NowOf(val)->NowIs(type) || type->NowContains(val)); 719 CHECK(!T.NowOf(value)->NowIs(type) || type->NowContains(value));
549 }
550 }
551
552 // T->Contains(V) implies T->NowContains(V) for all T,V
553 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
554 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
555 TypeHandle type = *it;
556 Handle<i::Object> val = *vt;
557 CHECK(!type->Contains(val) || type->NowContains(val));
558 } 720 }
559 } 721 }
560 } 722 }
561 723
562 void Maybe() { 724 void Maybe() {
563 // T->Maybe(T) for all inhabited T 725 // T->Maybe(T) iff T inhabited
564 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 726 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
565 TypeHandle type = *it; 727 TypeHandle type = *it;
566 CHECK(type->Maybe(type) || !type->IsInhabited()); 728 CHECK(type->Maybe(type) == type->IsInhabited());
729 }
730
731 // T->Maybe(Any) iff T inhabited
732 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
733 TypeHandle type = *it;
734 CHECK(type->Maybe(T.Any) == type->IsInhabited());
735 }
736
737 // T->Maybe(None) never
738 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
739 TypeHandle type = *it;
740 CHECK(!type->Maybe(T.None));
567 } 741 }
568 742
569 // Symmetry 743 // Symmetry
570 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 744 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
571 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 745 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
572 TypeHandle type1 = *it1; 746 TypeHandle type1 = *it1;
573 TypeHandle type2 = *it2; 747 TypeHandle type2 = *it2;
574 CHECK(type1->Maybe(type2) == type2->Maybe(type1)); 748 CHECK(type1->Maybe(type2) == type2->Maybe(type1));
575 } 749 }
576 } 750 }
577 751
578 // T1->Is(T2) implies T1->Maybe(T2) or T1 is uninhabited for all T1,T2 752 // T1->Maybe(T2) only if T1, T2 inhabited
579 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 753 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
580 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 754 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
581 TypeHandle type1 = *it1; 755 TypeHandle type1 = *it1;
582 TypeHandle type2 = *it2; 756 TypeHandle type2 = *it2;
583 CHECK(!type1->Is(type2) || 757 CHECK(!type1->Maybe(type2) ||
584 type1->Maybe(type2) || 758 (type1->IsInhabited() && type2->IsInhabited()));
585 !type1->IsInhabited());
586 } 759 }
587 } 760 }
588 761
589 CheckOverlap(T.Any, T.Any, T.Semantic); 762 // T1->Is(T2) and T1 inhabited implies T1->Maybe(T2) for all T1,T2
590 CheckOverlap(T.Object, T.Object, T.Semantic); 763 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
764 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
765 TypeHandle type1 = *it1;
766 TypeHandle type2 = *it2;
767 CHECK(!(type1->Is(type2) && type1->IsInhabited()) ||
768 type1->Maybe(type2));
769 }
770 }
591 771
772 // Constant(V1)->Maybe(Constant(V2)) iff V1 = V2
773 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) {
774 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) {
775 Handle<i::Object> val1 = *vt1;
776 Handle<i::Object> val2 = *vt2;
777 CHECK(T.Constant(val1)->Maybe(T.Constant(val2)) == (*val1 == *val2));
778 }
779 }
780
781 // Class(M1)->Maybe(Class(M2)) iff M1 = M2
782 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
783 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
784 Handle<i::Map> map1 = *mt1;
785 Handle<i::Map> map2 = *mt2;
786 CHECK(T.Class(map1)->Maybe(T.Class(map2)) == (*map1 == *map2));
787 }
788 }
789
790 // Constant(V)->Maybe(Class(M)) for no V,M
791 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
792 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
793 Handle<i::Map> map = *mt;
794 Handle<i::Object> value = *vt;
795 CHECK(!T.Constant(value)->Maybe(T.Class(map)));
796 }
797 }
798
799 // Class(M)->Maybe(Constant(V)) for no V,M
800 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
801 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
802 Handle<i::Map> map = *mt;
803 Handle<i::Object> value = *vt;
804 CHECK(!T.Class(map)->Maybe(T.Constant(value)));
805 }
806 }
807
808 // Basic types
592 CheckDisjoint(T.Boolean, T.Null, T.Semantic); 809 CheckDisjoint(T.Boolean, T.Null, T.Semantic);
593 CheckDisjoint(T.Undefined, T.Null, T.Semantic); 810 CheckDisjoint(T.Undefined, T.Null, T.Semantic);
594 CheckDisjoint(T.Boolean, T.Undefined, T.Semantic); 811 CheckDisjoint(T.Boolean, T.Undefined, T.Semantic);
595 812
596 CheckOverlap(T.Number, T.Any, T.Semantic);
597 CheckOverlap(T.SignedSmall, T.Number, T.Semantic); 813 CheckOverlap(T.SignedSmall, T.Number, T.Semantic);
598 CheckOverlap(T.Float, T.Number, T.Semantic); 814 CheckOverlap(T.Float, T.Number, T.Semantic);
599 CheckDisjoint(T.Signed32, T.Float, T.Semantic); 815 CheckDisjoint(T.Signed32, T.Float, T.Semantic);
600 816
601 CheckOverlap(T.Name, T.Any, T.Semantic);
602 CheckOverlap(T.UniqueName, T.Any, T.Semantic);
603 CheckOverlap(T.UniqueName, T.Name, T.Semantic); 817 CheckOverlap(T.UniqueName, T.Name, T.Semantic);
604 CheckOverlap(T.String, T.Name, T.Semantic); 818 CheckOverlap(T.String, T.Name, T.Semantic);
605 CheckOverlap(T.InternalizedString, T.String, T.Semantic); 819 CheckOverlap(T.InternalizedString, T.String, T.Semantic);
606 CheckOverlap(T.InternalizedString, T.UniqueName, T.Semantic); 820 CheckOverlap(T.InternalizedString, T.UniqueName, T.Semantic);
607 CheckOverlap(T.InternalizedString, T.Name, T.Semantic); 821 CheckOverlap(T.InternalizedString, T.Name, T.Semantic);
608 CheckOverlap(T.Symbol, T.UniqueName, T.Semantic); 822 CheckOverlap(T.Symbol, T.UniqueName, T.Semantic);
609 CheckOverlap(T.Symbol, T.Name, T.Semantic); 823 CheckOverlap(T.Symbol, T.Name, T.Semantic);
610 CheckOverlap(T.String, T.UniqueName, T.Semantic); 824 CheckOverlap(T.String, T.UniqueName, T.Semantic);
611 CheckDisjoint(T.String, T.Symbol, T.Semantic); 825 CheckDisjoint(T.String, T.Symbol, T.Semantic);
612 CheckDisjoint(T.InternalizedString, T.Symbol, T.Semantic); 826 CheckDisjoint(T.InternalizedString, T.Symbol, T.Semantic);
613 827
614 CheckOverlap(T.Receiver, T.Any, T.Semantic);
615 CheckOverlap(T.Object, T.Any, T.Semantic);
616 CheckOverlap(T.Object, T.Receiver, T.Semantic); 828 CheckOverlap(T.Object, T.Receiver, T.Semantic);
617 CheckOverlap(T.Array, T.Object, T.Semantic); 829 CheckOverlap(T.Array, T.Object, T.Semantic);
618 CheckOverlap(T.Function, T.Object, T.Semantic); 830 CheckOverlap(T.Function, T.Object, T.Semantic);
619 CheckOverlap(T.Proxy, T.Receiver, T.Semantic); 831 CheckOverlap(T.Proxy, T.Receiver, T.Semantic);
620 CheckDisjoint(T.Object, T.Proxy, T.Semantic); 832 CheckDisjoint(T.Object, T.Proxy, T.Semantic);
621 CheckDisjoint(T.Array, T.Function, T.Semantic); 833 CheckDisjoint(T.Array, T.Function, T.Semantic);
622 834
623 CheckOverlap(T.ObjectClass, T.Any, T.Semantic); 835 // Structural types
624 CheckOverlap(T.ObjectConstant1, T.Any, T.Semantic);
625
626 CheckOverlap(T.ObjectClass, T.Object, T.Semantic); 836 CheckOverlap(T.ObjectClass, T.Object, T.Semantic);
627 CheckOverlap(T.ArrayClass, T.Object, T.Semantic); 837 CheckOverlap(T.ArrayClass, T.Object, T.Semantic);
628 CheckOverlap(T.ObjectClass, T.ObjectClass, T.Semantic); 838 CheckOverlap(T.ObjectClass, T.ObjectClass, T.Semantic);
629 CheckOverlap(T.ArrayClass, T.ArrayClass, T.Semantic); 839 CheckOverlap(T.ArrayClass, T.ArrayClass, T.Semantic);
630 CheckDisjoint(T.ObjectClass, T.ArrayClass, T.Semantic); 840 CheckDisjoint(T.ObjectClass, T.ArrayClass, T.Semantic);
631 841
632 CheckOverlap(T.SmiConstant, T.SignedSmall, T.Semantic); 842 CheckOverlap(T.SmiConstant, T.SignedSmall, T.Semantic);
633 CheckOverlap(T.SmiConstant, T.Signed32, T.Semantic); 843 CheckOverlap(T.SmiConstant, T.Signed32, T.Semantic);
634 CheckOverlap(T.SmiConstant, T.Number, T.Semantic); 844 CheckOverlap(T.SmiConstant, T.Number, T.Semantic);
635 CheckDisjoint(T.SmiConstant, T.Float, T.Semantic); 845 CheckDisjoint(T.SmiConstant, T.Float, T.Semantic);
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 ZoneTests().Intersect(); 1276 ZoneTests().Intersect();
1067 HeapTests().Intersect(); 1277 HeapTests().Intersect();
1068 } 1278 }
1069 1279
1070 1280
1071 TEST(Convert) { 1281 TEST(Convert) {
1072 CcTest::InitializeVM(); 1282 CcTest::InitializeVM();
1073 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 1283 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
1074 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 1284 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
1075 } 1285 }
OLDNEW
« src/types.h ('K') | « src/types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698