| 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 25 matching lines...) Expand all Loading... |
| 36 // Testing auxiliaries (breaking the Type abstraction). | 36 // Testing auxiliaries (breaking the Type abstraction). |
| 37 struct ZoneRep { | 37 struct ZoneRep { |
| 38 typedef void* Struct; | 38 typedef void* Struct; |
| 39 | 39 |
| 40 static bool IsStruct(Type* t, int tag) { | 40 static bool IsStruct(Type* t, int tag) { |
| 41 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; | 41 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; |
| 42 } | 42 } |
| 43 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; } | 43 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; } |
| 44 static bool IsClass(Type* t) { return IsStruct(t, 0); } | 44 static bool IsClass(Type* t) { return IsStruct(t, 0); } |
| 45 static bool IsConstant(Type* t) { return IsStruct(t, 1); } | 45 static bool IsConstant(Type* t) { return IsStruct(t, 1); } |
| 46 static bool IsUnion(Type* t) { return IsStruct(t, 2); } | 46 static bool IsArray(Type* t) { return IsStruct(t, 2); } |
| 47 static bool IsFunction(Type* t) { return IsStruct(t, 3); } |
| 48 static bool IsUnion(Type* t) { return IsStruct(t, 4); } |
| 47 | 49 |
| 48 static Struct* AsStruct(Type* t) { | 50 static Struct* AsStruct(Type* t) { |
| 49 return reinterpret_cast<Struct*>(t); | 51 return reinterpret_cast<Struct*>(t); |
| 50 } | 52 } |
| 51 static int AsBitset(Type* t) { | 53 static int AsBitset(Type* t) { |
| 52 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); | 54 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); |
| 53 } | 55 } |
| 54 static Map* AsClass(Type* t) { | 56 static Map* AsClass(Type* t) { |
| 55 return *static_cast<Map**>(AsStruct(t)[3]); | 57 return *static_cast<Map**>(AsStruct(t)[3]); |
| 56 } | 58 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 | 72 |
| 71 struct HeapRep { | 73 struct HeapRep { |
| 72 typedef FixedArray Struct; | 74 typedef FixedArray Struct; |
| 73 | 75 |
| 74 static bool IsStruct(Handle<HeapType> t, int tag) { | 76 static bool IsStruct(Handle<HeapType> t, int tag) { |
| 75 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; | 77 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; |
| 76 } | 78 } |
| 77 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } | 79 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } |
| 78 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } | 80 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } |
| 79 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } | 81 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } |
| 80 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 2); } | 82 static bool IsArray(Handle<HeapType> t) { return IsStruct(t, 2); } |
| 83 static bool IsFunction(Handle<HeapType> t) { return IsStruct(t, 3); } |
| 84 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 4); } |
| 81 | 85 |
| 82 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } | 86 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } |
| 83 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } | 87 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } |
| 84 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } | 88 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } |
| 85 static Object* AsConstant(Handle<HeapType> t) { | 89 static Object* AsConstant(Handle<HeapType> t) { |
| 86 return Box::cast(*t)->value(); | 90 return Box::cast(*t)->value(); |
| 87 } | 91 } |
| 88 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } | 92 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } |
| 89 static int Length(Struct* structured) { return structured->length() - 1; } | 93 static int Length(Struct* structured) { return structured->length() - 1; } |
| 90 | 94 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 values.push_back(smi); | 136 values.push_back(smi); |
| 133 values.push_back(signed32); | 137 values.push_back(signed32); |
| 134 values.push_back(object1); | 138 values.push_back(object1); |
| 135 values.push_back(object2); | 139 values.push_back(object2); |
| 136 values.push_back(array); | 140 values.push_back(array); |
| 137 values.push_back(uninitialized); | 141 values.push_back(uninitialized); |
| 138 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) { | 142 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) { |
| 139 types.push_back(Type::Constant(*it, region)); | 143 types.push_back(Type::Constant(*it, region)); |
| 140 } | 144 } |
| 141 | 145 |
| 146 FloatArray = Type::Array(Float, region); |
| 147 StringArray = Type::Array(String, region); |
| 148 AnyArray = Type::Array(Any, region); |
| 149 |
| 150 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); |
| 151 NumberFunction1 = Type::Function(Number, Number, region); |
| 152 NumberFunction2 = Type::Function(Number, Number, Number, region); |
| 153 MethodFunction = Type::Function(String, Object, 0, region); |
| 154 |
| 142 for (int i = 0; i < 50; ++i) { | 155 for (int i = 0; i < 50; ++i) { |
| 143 types.push_back(Fuzz()); | 156 types.push_back(Fuzz()); |
| 144 } | 157 } |
| 145 } | 158 } |
| 146 | 159 |
| 160 Handle<i::Map> object_map; |
| 161 Handle<i::Map> array_map; |
| 162 Handle<i::Map> uninitialized_map; |
| 163 |
| 164 Handle<i::Smi> smi; |
| 165 Handle<i::HeapNumber> signed32; |
| 166 Handle<i::JSObject> object1; |
| 167 Handle<i::JSObject> object2; |
| 168 Handle<i::JSArray> array; |
| 169 Handle<i::Oddball> uninitialized; |
| 170 |
| 147 #define DECLARE_TYPE(name, value) TypeHandle name; | 171 #define DECLARE_TYPE(name, value) TypeHandle name; |
| 148 BITSET_TYPE_LIST(DECLARE_TYPE) | 172 BITSET_TYPE_LIST(DECLARE_TYPE) |
| 149 #undef DECLARE_TYPE | 173 #undef DECLARE_TYPE |
| 150 | 174 |
| 151 TypeHandle ObjectClass; | 175 TypeHandle ObjectClass; |
| 152 TypeHandle ArrayClass; | 176 TypeHandle ArrayClass; |
| 153 TypeHandle UninitializedClass; | 177 TypeHandle UninitializedClass; |
| 154 | 178 |
| 155 TypeHandle SmiConstant; | 179 TypeHandle SmiConstant; |
| 156 TypeHandle Signed32Constant; | 180 TypeHandle Signed32Constant; |
| 157 TypeHandle ObjectConstant1; | 181 TypeHandle ObjectConstant1; |
| 158 TypeHandle ObjectConstant2; | 182 TypeHandle ObjectConstant2; |
| 159 TypeHandle ArrayConstant; | 183 TypeHandle ArrayConstant; |
| 160 TypeHandle UninitializedConstant; | 184 TypeHandle UninitializedConstant; |
| 161 | 185 |
| 162 Handle<i::Map> object_map; | 186 TypeHandle FloatArray; |
| 163 Handle<i::Map> array_map; | 187 TypeHandle StringArray; |
| 164 Handle<i::Map> uninitialized_map; | 188 TypeHandle AnyArray; |
| 165 | 189 |
| 166 Handle<i::Smi> smi; | 190 TypeHandle SignedFunction1; |
| 167 Handle<i::HeapNumber> signed32; | 191 TypeHandle NumberFunction1; |
| 168 Handle<i::JSObject> object1; | 192 TypeHandle NumberFunction2; |
| 169 Handle<i::JSObject> object2; | 193 TypeHandle MethodFunction; |
| 170 Handle<i::JSArray> array; | |
| 171 Handle<i::Oddball> uninitialized; | |
| 172 | 194 |
| 173 typedef std::vector<TypeHandle> TypeVector; | 195 typedef std::vector<TypeHandle> TypeVector; |
| 174 typedef std::vector<Handle<i::Map> > MapVector; | 196 typedef std::vector<Handle<i::Map> > MapVector; |
| 175 typedef std::vector<Handle<i::Object> > ValueVector; | 197 typedef std::vector<Handle<i::Object> > ValueVector; |
| 176 TypeVector types; | 198 TypeVector types; |
| 177 MapVector maps; | 199 MapVector maps; |
| 178 ValueVector values; | 200 ValueVector values; |
| 179 | 201 |
| 180 TypeHandle Of(Handle<i::Object> value) { | 202 TypeHandle Of(Handle<i::Object> value) { |
| 181 return Type::Of(value, region_); | 203 return Type::Of(value, region_); |
| 182 } | 204 } |
| 183 | 205 |
| 184 TypeHandle NowOf(Handle<i::Object> value) { | 206 TypeHandle NowOf(Handle<i::Object> value) { |
| 185 return Type::NowOf(value, region_); | 207 return Type::NowOf(value, region_); |
| 186 } | 208 } |
| 187 | 209 |
| 188 TypeHandle Constant(Handle<i::Object> value) { | 210 TypeHandle Constant(Handle<i::Object> value) { |
| 189 return Type::Constant(value, region_); | 211 return Type::Constant(value, region_); |
| 190 } | 212 } |
| 191 | 213 |
| 192 TypeHandle Class(Handle<i::Map> map) { | 214 TypeHandle Class(Handle<i::Map> map) { |
| 193 return Type::Class(map, region_); | 215 return Type::Class(map, region_); |
| 194 } | 216 } |
| 195 | 217 |
| 218 TypeHandle Array1(TypeHandle element) { |
| 219 return Type::Array(element, region_); |
| 220 } |
| 221 |
| 222 TypeHandle Function0(TypeHandle result, TypeHandle receiver) { |
| 223 return Type::Function(result, receiver, 0, region_); |
| 224 } |
| 225 |
| 226 TypeHandle Function1(TypeHandle result, TypeHandle receiver, TypeHandle arg) { |
| 227 TypeHandle type = Type::Function(result, receiver, 1, region_); |
| 228 type->AsFunction()->InitParameter(0, arg); |
| 229 return type; |
| 230 } |
| 231 |
| 232 TypeHandle Function2(TypeHandle result, TypeHandle arg1, TypeHandle arg2) { |
| 233 return Type::Function(result, arg1, arg2, region_); |
| 234 } |
| 235 |
| 196 TypeHandle Union(TypeHandle t1, TypeHandle t2) { | 236 TypeHandle Union(TypeHandle t1, TypeHandle t2) { |
| 197 return Type::Union(t1, t2, region_); | 237 return Type::Union(t1, t2, region_); |
| 198 } | 238 } |
| 199 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) { | 239 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) { |
| 200 return Type::Intersect(t1, t2, region_); | 240 return Type::Intersect(t1, t2, region_); |
| 201 } | 241 } |
| 202 | 242 |
| 203 template<class Type2, class TypeHandle2> | 243 template<class Type2, class TypeHandle2> |
| 204 TypeHandle Convert(TypeHandle2 t) { | 244 TypeHandle Convert(TypeHandle2 t) { |
| 205 return Type::template Convert<Type2>(t, region_); | 245 return Type::template Convert<Type2>(t, region_); |
| 206 } | 246 } |
| 207 | 247 |
| 248 TypeHandle Random() { |
| 249 return types[rng_.NextInt(static_cast<int>(types.size()))]; |
| 250 } |
| 251 |
| 208 TypeHandle Fuzz(int depth = 5) { | 252 TypeHandle Fuzz(int depth = 5) { |
| 209 switch (rng_.NextInt(depth == 0 ? 3 : 20)) { | 253 switch (rng_.NextInt(depth == 0 ? 3 : 20)) { |
| 210 case 0: { // bitset | 254 case 0: { // bitset |
| 211 int n = 0 | 255 int n = 0 |
| 212 #define COUNT_BITSET_TYPES(type, value) + 1 | 256 #define COUNT_BITSET_TYPES(type, value) + 1 |
| 213 BITSET_TYPE_LIST(COUNT_BITSET_TYPES) | 257 BITSET_TYPE_LIST(COUNT_BITSET_TYPES) |
| 214 #undef COUNT_BITSET_TYPES | 258 #undef COUNT_BITSET_TYPES |
| 215 ; | 259 ; |
| 216 int i = rng_.NextInt(n); | 260 int i = rng_.NextInt(n); |
| 217 #define PICK_BITSET_TYPE(type, value) \ | 261 #define PICK_BITSET_TYPE(type, value) \ |
| 218 if (i-- == 0) return Type::type(region_); | 262 if (i-- == 0) return Type::type(region_); |
| 219 BITSET_TYPE_LIST(PICK_BITSET_TYPE) | 263 BITSET_TYPE_LIST(PICK_BITSET_TYPE) |
| 220 #undef PICK_BITSET_TYPE | 264 #undef PICK_BITSET_TYPE |
| 221 UNREACHABLE(); | 265 UNREACHABLE(); |
| 222 } | 266 } |
| 223 case 1: { // class | 267 case 1: { // class |
| 224 int i = rng_.NextInt(static_cast<int>(maps.size())); | 268 int i = rng_.NextInt(static_cast<int>(maps.size())); |
| 225 return Type::Class(maps[i], region_); | 269 return Type::Class(maps[i], region_); |
| 226 } | 270 } |
| 227 case 2: { // constant | 271 case 2: { // constant |
| 228 int i = rng_.NextInt(static_cast<int>(values.size())); | 272 int i = rng_.NextInt(static_cast<int>(values.size())); |
| 229 return Type::Constant(values[i], region_); | 273 return Type::Constant(values[i], region_); |
| 230 } | 274 } |
| 275 case 3: // array |
| 276 return Type::Array(Fuzz(depth / 2), region_); |
| 277 case 4: |
| 278 case 5: |
| 279 case 6: { // function |
| 280 TypeHandle type = Type::Function( |
| 281 Fuzz(depth / 2), Fuzz(depth / 2), rand() % 3, region_); |
| 282 for (int i = 0; i < type->AsFunction()->Arity(); ++i) { |
| 283 type->AsFunction()->InitParameter(i, Fuzz(depth - 1)); |
| 284 } |
| 285 } |
| 231 default: { // union | 286 default: { // union |
| 232 int n = rng_.NextInt(10); | 287 int n = rng_.NextInt(10); |
| 233 TypeHandle type = None; | 288 TypeHandle type = None; |
| 234 for (int i = 0; i < n; ++i) { | 289 for (int i = 0; i < n; ++i) { |
| 235 type = Type::Union(type, Fuzz(depth - 1), region_); | 290 type = Type::Union(type, Fuzz(depth - 1), region_); |
| 236 } | 291 } |
| 237 return type; | 292 return type; |
| 238 } | 293 } |
| 239 } | 294 } |
| 240 UNREACHABLE(); | 295 UNREACHABLE(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 454 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
| 400 Handle<i::Map> map = *mt; | 455 Handle<i::Map> map = *mt; |
| 401 TypeHandle type = T.Class(map); | 456 TypeHandle type = T.Class(map); |
| 402 CHECK(this->IsClass(type)); | 457 CHECK(this->IsClass(type)); |
| 403 } | 458 } |
| 404 | 459 |
| 405 // Map attribute | 460 // Map attribute |
| 406 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 461 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
| 407 Handle<i::Map> map = *mt; | 462 Handle<i::Map> map = *mt; |
| 408 TypeHandle type = T.Class(map); | 463 TypeHandle type = T.Class(map); |
| 409 CHECK(*map == *type->AsClass()); | 464 CHECK(*map == *type->AsClass()->Map()); |
| 410 } | 465 } |
| 411 | 466 |
| 412 // Functionality & Injectivity: Class(M1) = Class(M2) iff M1 = M2 | 467 // Functionality & Injectivity: Class(M1) = Class(M2) iff M1 = M2 |
| 413 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { | 468 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { |
| 414 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { | 469 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { |
| 415 Handle<i::Map> map1 = *mt1; | 470 Handle<i::Map> map1 = *mt1; |
| 416 Handle<i::Map> map2 = *mt2; | 471 Handle<i::Map> map2 = *mt2; |
| 417 TypeHandle type1 = T.Class(map1); | 472 TypeHandle type1 = T.Class(map1); |
| 418 TypeHandle type2 = T.Class(map2); | 473 TypeHandle type2 = T.Class(map2); |
| 419 CHECK(Equal(type1, type2) == (*map1 == *map2)); | 474 CHECK(Equal(type1, type2) == (*map1 == *map2)); |
| 420 } | 475 } |
| 421 } | 476 } |
| 422 } | 477 } |
| 423 | 478 |
| 424 void Constant() { | 479 void Constant() { |
| 425 // Constructor | 480 // Constructor |
| 426 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 481 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
| 427 Handle<i::Object> value = *vt; | 482 Handle<i::Object> value = *vt; |
| 428 TypeHandle type = T.Constant(value); | 483 TypeHandle type = T.Constant(value); |
| 429 CHECK(this->IsConstant(type)); | 484 CHECK(this->IsConstant(type)); |
| 430 } | 485 } |
| 431 | 486 |
| 432 // Value attribute | 487 // Value attribute |
| 433 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 488 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
| 434 Handle<i::Object> value = *vt; | 489 Handle<i::Object> value = *vt; |
| 435 TypeHandle type = T.Constant(value); | 490 TypeHandle type = T.Constant(value); |
| 436 CHECK(*value == *type->AsConstant()); | 491 CHECK(*value == *type->AsConstant()->Value()); |
| 437 } | 492 } |
| 438 | 493 |
| 439 // Functionality & Injectivity: Constant(V1) = Constant(v2) iff V1 = V2 | 494 // Functionality & Injectivity: Constant(V1) = Constant(V2) iff V1 = V2 |
| 440 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 495 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
| 441 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 496 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
| 442 Handle<i::Object> value1 = *vt1; | 497 Handle<i::Object> value1 = *vt1; |
| 443 Handle<i::Object> value2 = *vt2; | 498 Handle<i::Object> value2 = *vt2; |
| 444 TypeHandle type1 = T.Constant(value1); | 499 TypeHandle type1 = T.Constant(value1); |
| 445 TypeHandle type2 = T.Constant(value2); | 500 TypeHandle type2 = T.Constant(value2); |
| 446 CHECK(Equal(type1, type2) == (*value1 == *value2)); | 501 CHECK(Equal(type1, type2) == (*value1 == *value2)); |
| 447 } | 502 } |
| 448 } | 503 } |
| 449 } | 504 } |
| 450 | 505 |
| 506 void Array() { |
| 507 // Constructor |
| 508 for (int i = 0; i < 20; ++i) { |
| 509 TypeHandle type = T.Random(); |
| 510 TypeHandle array = T.Array1(type); |
| 511 CHECK(this->IsArray(array)); |
| 512 } |
| 513 |
| 514 // Attributes |
| 515 for (int i = 0; i < 20; ++i) { |
| 516 TypeHandle type = T.Random(); |
| 517 TypeHandle array = T.Array1(type); |
| 518 CheckEqual(type, array->AsArray()->Element()); |
| 519 } |
| 520 |
| 521 // Functionality & Injectivity: Array(T1) = Array(T2) iff T1 = T2 |
| 522 for (int i = 0; i < 20; ++i) { |
| 523 for (int j = 0; j < 20; ++j) { |
| 524 TypeHandle type1 = T.Random(); |
| 525 TypeHandle type2 = T.Random(); |
| 526 TypeHandle array1 = T.Array1(type1); |
| 527 TypeHandle array2 = T.Array1(type2); |
| 528 CHECK(Equal(array1, array2) == Equal(type1, type2)); |
| 529 } |
| 530 } |
| 531 } |
| 532 |
| 533 void Function() { |
| 534 // Constructors |
| 535 for (int i = 0; i < 20; ++i) { |
| 536 for (int j = 0; j < 20; ++j) { |
| 537 for (int k = 0; k < 20; ++k) { |
| 538 TypeHandle type1 = T.Random(); |
| 539 TypeHandle type2 = T.Random(); |
| 540 TypeHandle type3 = T.Random(); |
| 541 TypeHandle function0 = T.Function0(type1, type2); |
| 542 TypeHandle function1 = T.Function1(type1, type2, type3); |
| 543 TypeHandle function2 = T.Function2(type1, type2, type3); |
| 544 CHECK(function0->IsFunction()); |
| 545 CHECK(function1->IsFunction()); |
| 546 CHECK(function2->IsFunction()); |
| 547 } |
| 548 } |
| 549 } |
| 550 |
| 551 // Attributes |
| 552 for (int i = 0; i < 20; ++i) { |
| 553 for (int j = 0; j < 20; ++j) { |
| 554 for (int k = 0; k < 20; ++k) { |
| 555 TypeHandle type1 = T.Random(); |
| 556 TypeHandle type2 = T.Random(); |
| 557 TypeHandle type3 = T.Random(); |
| 558 TypeHandle function0 = T.Function0(type1, type2); |
| 559 TypeHandle function1 = T.Function1(type1, type2, type3); |
| 560 TypeHandle function2 = T.Function2(type1, type2, type3); |
| 561 CHECK_EQ(0, function0->AsFunction()->Arity()); |
| 562 CHECK_EQ(1, function1->AsFunction()->Arity()); |
| 563 CHECK_EQ(2, function2->AsFunction()->Arity()); |
| 564 CheckEqual(type1, function0->AsFunction()->Result()); |
| 565 CheckEqual(type1, function1->AsFunction()->Result()); |
| 566 CheckEqual(type1, function2->AsFunction()->Result()); |
| 567 CheckEqual(type2, function0->AsFunction()->Receiver()); |
| 568 CheckEqual(type2, function1->AsFunction()->Receiver()); |
| 569 CheckEqual(T.Any, function2->AsFunction()->Receiver()); |
| 570 CheckEqual(type3, function1->AsFunction()->Parameter(0)); |
| 571 CheckEqual(type2, function2->AsFunction()->Parameter(0)); |
| 572 CheckEqual(type3, function2->AsFunction()->Parameter(1)); |
| 573 } |
| 574 } |
| 575 } |
| 576 |
| 577 // Functionality & Injectivity: Function(Ts1) = Function(Ts2) iff Ts1 = Ts2 |
| 578 for (int i = 0; i < 20; ++i) { |
| 579 for (int j = 0; j < 20; ++j) { |
| 580 for (int k = 0; k < 20; ++k) { |
| 581 TypeHandle type1 = T.Random(); |
| 582 TypeHandle type2 = T.Random(); |
| 583 TypeHandle type3 = T.Random(); |
| 584 TypeHandle function01 = T.Function0(type1, type2); |
| 585 TypeHandle function02 = T.Function0(type1, type3); |
| 586 TypeHandle function03 = T.Function0(type3, type2); |
| 587 TypeHandle function11 = T.Function1(type1, type2, type2); |
| 588 TypeHandle function12 = T.Function1(type1, type2, type3); |
| 589 TypeHandle function21 = T.Function2(type1, type2, type2); |
| 590 TypeHandle function22 = T.Function2(type1, type2, type3); |
| 591 TypeHandle function23 = T.Function2(type1, type3, type2); |
| 592 CHECK(Equal(function01, function02) == Equal(type2, type3)); |
| 593 CHECK(Equal(function01, function03) == Equal(type1, type3)); |
| 594 CHECK(Equal(function11, function12) == Equal(type2, type3)); |
| 595 CHECK(Equal(function21, function22) == Equal(type2, type3)); |
| 596 CHECK(Equal(function21, function23) == Equal(type2, type3)); |
| 597 } |
| 598 } |
| 599 } |
| 600 } |
| 601 |
| 451 void Of() { | 602 void Of() { |
| 452 // Constant(V)->Is(Of(V)) | 603 // Constant(V)->Is(Of(V)) |
| 453 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 604 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
| 454 Handle<i::Object> value = *vt; | 605 Handle<i::Object> value = *vt; |
| 455 TypeHandle const_type = T.Constant(value); | 606 TypeHandle const_type = T.Constant(value); |
| 456 TypeHandle of_type = T.Of(value); | 607 TypeHandle of_type = T.Of(value); |
| 457 CHECK(const_type->Is(of_type)); | 608 CHECK(const_type->Is(of_type)); |
| 458 } | 609 } |
| 459 | 610 |
| 460 // Constant(V)->Is(T) iff Of(V)->Is(T) or T->Maybe(Constant(V)) | 611 // Constant(V)->Is(T) iff Of(V)->Is(T) or T->Maybe(Constant(V)) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 CheckSub(T.Object, T.Receiver); | 785 CheckSub(T.Object, T.Receiver); |
| 635 CheckSub(T.Array, T.Object); | 786 CheckSub(T.Array, T.Object); |
| 636 CheckSub(T.Function, T.Object); | 787 CheckSub(T.Function, T.Object); |
| 637 CheckSub(T.Proxy, T.Receiver); | 788 CheckSub(T.Proxy, T.Receiver); |
| 638 CheckUnordered(T.Object, T.Proxy); | 789 CheckUnordered(T.Object, T.Proxy); |
| 639 CheckUnordered(T.Array, T.Function); | 790 CheckUnordered(T.Array, T.Function); |
| 640 | 791 |
| 641 // Structural types | 792 // Structural types |
| 642 CheckSub(T.ObjectClass, T.Object); | 793 CheckSub(T.ObjectClass, T.Object); |
| 643 CheckSub(T.ArrayClass, T.Object); | 794 CheckSub(T.ArrayClass, T.Object); |
| 795 CheckSub(T.ArrayClass, T.Array); |
| 644 CheckSub(T.UninitializedClass, T.Internal); | 796 CheckSub(T.UninitializedClass, T.Internal); |
| 645 CheckUnordered(T.ObjectClass, T.ArrayClass); | 797 CheckUnordered(T.ObjectClass, T.ArrayClass); |
| 646 CheckUnordered(T.UninitializedClass, T.Null); | 798 CheckUnordered(T.UninitializedClass, T.Null); |
| 647 CheckUnordered(T.UninitializedClass, T.Undefined); | 799 CheckUnordered(T.UninitializedClass, T.Undefined); |
| 648 | 800 |
| 649 CheckSub(T.SmiConstant, T.SignedSmall); | 801 CheckSub(T.SmiConstant, T.SignedSmall); |
| 650 CheckSub(T.SmiConstant, T.Signed32); | 802 CheckSub(T.SmiConstant, T.Signed32); |
| 651 CheckSub(T.SmiConstant, T.Number); | 803 CheckSub(T.SmiConstant, T.Number); |
| 652 CheckSub(T.ObjectConstant1, T.Object); | 804 CheckSub(T.ObjectConstant1, T.Object); |
| 653 CheckSub(T.ObjectConstant2, T.Object); | 805 CheckSub(T.ObjectConstant2, T.Object); |
| 654 CheckSub(T.ArrayConstant, T.Object); | 806 CheckSub(T.ArrayConstant, T.Object); |
| 655 CheckSub(T.ArrayConstant, T.Array); | 807 CheckSub(T.ArrayConstant, T.Array); |
| 656 CheckSub(T.UninitializedConstant, T.Internal); | 808 CheckSub(T.UninitializedConstant, T.Internal); |
| 657 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); | 809 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); |
| 658 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); | 810 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); |
| 659 CheckUnordered(T.UninitializedConstant, T.Null); | 811 CheckUnordered(T.UninitializedConstant, T.Null); |
| 660 CheckUnordered(T.UninitializedConstant, T.Undefined); | 812 CheckUnordered(T.UninitializedConstant, T.Undefined); |
| 661 | 813 |
| 662 CheckUnordered(T.ObjectConstant1, T.ObjectClass); | 814 CheckUnordered(T.ObjectConstant1, T.ObjectClass); |
| 663 CheckUnordered(T.ObjectConstant2, T.ObjectClass); | 815 CheckUnordered(T.ObjectConstant2, T.ObjectClass); |
| 664 CheckUnordered(T.ObjectConstant1, T.ArrayClass); | 816 CheckUnordered(T.ObjectConstant1, T.ArrayClass); |
| 665 CheckUnordered(T.ObjectConstant2, T.ArrayClass); | 817 CheckUnordered(T.ObjectConstant2, T.ArrayClass); |
| 666 CheckUnordered(T.ArrayConstant, T.ObjectClass); | 818 CheckUnordered(T.ArrayConstant, T.ObjectClass); |
| 819 |
| 820 CheckSub(T.FloatArray, T.Array); |
| 821 CheckSub(T.FloatArray, T.Object); |
| 822 CheckUnordered(T.StringArray, T.AnyArray); |
| 823 |
| 824 CheckSub(T.MethodFunction, T.Function); |
| 825 CheckSub(T.NumberFunction1, T.Object); |
| 826 CheckUnordered(T.SignedFunction1, T.NumberFunction1); |
| 827 CheckUnordered(T.NumberFunction1, T.NumberFunction2); |
| 667 } | 828 } |
| 668 | 829 |
| 669 void NowIs() { | 830 void NowIs() { |
| 670 // Least Element (Bottom): None->NowIs(T) | 831 // Least Element (Bottom): None->NowIs(T) |
| 671 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 832 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 672 TypeHandle type = *it; | 833 TypeHandle type = *it; |
| 673 CHECK(T.None->NowIs(type)); | 834 CHECK(T.None->NowIs(type)); |
| 674 } | 835 } |
| 675 | 836 |
| 676 // Greatest Element (Top): T->NowIs(Any) | 837 // Greatest Element (Top): T->NowIs(Any) |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 CheckOverlap(T.ArrayConstant, T.Array, T.Semantic); | 1146 CheckOverlap(T.ArrayConstant, T.Array, T.Semantic); |
| 986 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1, T.Semantic); | 1147 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1, T.Semantic); |
| 987 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2, T.Semantic); | 1148 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2, T.Semantic); |
| 988 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant, T.Semantic); | 1149 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant, T.Semantic); |
| 989 | 1150 |
| 990 CheckDisjoint(T.ObjectConstant1, T.ObjectClass, T.Semantic); | 1151 CheckDisjoint(T.ObjectConstant1, T.ObjectClass, T.Semantic); |
| 991 CheckDisjoint(T.ObjectConstant2, T.ObjectClass, T.Semantic); | 1152 CheckDisjoint(T.ObjectConstant2, T.ObjectClass, T.Semantic); |
| 992 CheckDisjoint(T.ObjectConstant1, T.ArrayClass, T.Semantic); | 1153 CheckDisjoint(T.ObjectConstant1, T.ArrayClass, T.Semantic); |
| 993 CheckDisjoint(T.ObjectConstant2, T.ArrayClass, T.Semantic); | 1154 CheckDisjoint(T.ObjectConstant2, T.ArrayClass, T.Semantic); |
| 994 CheckDisjoint(T.ArrayConstant, T.ObjectClass, T.Semantic); | 1155 CheckDisjoint(T.ArrayConstant, T.ObjectClass, T.Semantic); |
| 1156 |
| 1157 CheckOverlap(T.FloatArray, T.Array, T.Semantic); |
| 1158 CheckDisjoint(T.FloatArray, T.AnyArray, T.Semantic); |
| 1159 CheckDisjoint(T.FloatArray, T.StringArray, T.Semantic); |
| 1160 |
| 1161 CheckOverlap(T.MethodFunction, T.Function, T.Semantic); |
| 1162 CheckDisjoint(T.SignedFunction1, T.NumberFunction1, T.Semantic); |
| 1163 CheckDisjoint(T.SignedFunction1, T.NumberFunction2, T.Semantic); |
| 1164 CheckDisjoint(T.NumberFunction1, T.NumberFunction2, T.Semantic); |
| 1165 CheckDisjoint(T.SignedFunction1, T.MethodFunction, T.Semantic); |
| 995 } | 1166 } |
| 996 | 1167 |
| 997 void Union() { | 1168 void Union1() { |
| 998 // Identity: Union(T, None) = T | 1169 // Identity: Union(T, None) = T |
| 999 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1170 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 1000 TypeHandle type = *it; | 1171 TypeHandle type = *it; |
| 1001 TypeHandle union_type = T.Union(type, T.None); | 1172 TypeHandle union_type = T.Union(type, T.None); |
| 1002 CheckEqual(union_type, type); | 1173 CheckEqual(union_type, type); |
| 1003 } | 1174 } |
| 1004 | 1175 |
| 1005 // Domination: Union(T, Any) = Any | 1176 // Domination: Union(T, Any) = Any |
| 1006 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1177 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 1007 TypeHandle type = *it; | 1178 TypeHandle type = *it; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 1227 |
| 1057 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2 | 1228 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2 |
| 1058 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1229 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
| 1059 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1230 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
| 1060 TypeHandle type1 = *it1; | 1231 TypeHandle type1 = *it1; |
| 1061 TypeHandle type2 = *it2; | 1232 TypeHandle type2 = *it2; |
| 1062 TypeHandle union12 = T.Union(type1, type2); | 1233 TypeHandle union12 = T.Union(type1, type2); |
| 1063 if (type1->Is(type2)) CheckEqual(union12, type2); | 1234 if (type1->Is(type2)) CheckEqual(union12, type2); |
| 1064 } | 1235 } |
| 1065 } | 1236 } |
| 1237 } |
| 1066 | 1238 |
| 1239 void Union2() { |
| 1067 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3)) | 1240 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3)) |
| 1068 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1241 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
| 1069 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1242 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
| 1070 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1243 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
| 1071 TypeHandle type1 = *it1; | 1244 TypeHandle type1 = *it1; |
| 1072 TypeHandle type2 = *it2; | 1245 TypeHandle type2 = *it2; |
| 1073 TypeHandle type3 = *it3; | 1246 TypeHandle type3 = *it3; |
| 1074 TypeHandle union13 = T.Union(type1, type3); | 1247 TypeHandle union13 = T.Union(type1, type3); |
| 1075 TypeHandle union23 = T.Union(type2, type3); | 1248 TypeHandle union23 = T.Union(type2, type3); |
| 1076 CHECK(!type1->Is(type2) || union13->Is(union23)); | 1249 CHECK(!type1->Is(type2) || union13->Is(union23)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); | 1288 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); |
| 1116 CheckUnordered( | 1289 CheckUnordered( |
| 1117 T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); | 1290 T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); |
| 1118 CheckOverlap( | 1291 CheckOverlap( |
| 1119 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array, T.Semantic); | 1292 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array, T.Semantic); |
| 1120 CheckDisjoint( | 1293 CheckDisjoint( |
| 1121 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number, T.Semantic); | 1294 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number, T.Semantic); |
| 1122 CheckDisjoint( | 1295 CheckDisjoint( |
| 1123 T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass, T.Semantic); | 1296 T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass, T.Semantic); |
| 1124 | 1297 |
| 1298 // Bitset-array |
| 1299 CHECK(this->IsBitset(T.Union(T.AnyArray, T.Array))); |
| 1300 CHECK(this->IsUnion(T.Union(T.FloatArray, T.Number))); |
| 1301 |
| 1302 CheckEqual(T.Union(T.AnyArray, T.Array), T.Array); |
| 1303 CheckSub(T.None, T.Union(T.FloatArray, T.Number)); |
| 1304 CheckSub(T.Union(T.FloatArray, T.Number), T.Any); |
| 1305 CheckUnordered(T.Union(T.AnyArray, T.String), T.Array); |
| 1306 CheckOverlap(T.Union(T.FloatArray, T.String), T.Object, T.Semantic); |
| 1307 CheckDisjoint(T.Union(T.FloatArray, T.String), T.Number, T.Semantic); |
| 1308 |
| 1309 // Bitset-function |
| 1310 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Function))); |
| 1311 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number))); |
| 1312 |
| 1313 CheckEqual(T.Union(T.MethodFunction, T.Function), T.Function); |
| 1314 CheckSub(T.None, T.Union(T.MethodFunction, T.Number)); |
| 1315 CheckSub(T.Union(T.MethodFunction, T.Number), T.Any); |
| 1316 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Function); |
| 1317 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object, T.Semantic); |
| 1318 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number, T.Semantic); |
| 1319 |
| 1125 // Bitset-class | 1320 // Bitset-class |
| 1126 CheckSub( | 1321 CheckSub( |
| 1127 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); | 1322 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); |
| 1128 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); | 1323 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); |
| 1129 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); | 1324 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); |
| 1130 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object, T.Semantic); | 1325 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object, T.Semantic); |
| 1131 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number, T.Semantic); | 1326 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number, T.Semantic); |
| 1132 | 1327 |
| 1133 // Bitset-constant | 1328 // Bitset-constant |
| 1134 CheckSub( | 1329 CheckSub( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 CheckEqual( | 1365 CheckEqual( |
| 1171 T.Union( | 1366 T.Union( |
| 1172 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 1367 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 1173 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 1368 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 1174 CheckEqual( | 1369 CheckEqual( |
| 1175 T.Union( | 1370 T.Union( |
| 1176 T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1), | 1371 T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1), |
| 1177 T.Union( | 1372 T.Union( |
| 1178 T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1))); | 1373 T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1))); |
| 1179 | 1374 |
| 1375 // Array-union |
| 1376 CheckEqual( |
| 1377 T.Union(T.AnyArray, T.Union(T.FloatArray, T.AnyArray)), |
| 1378 T.Union(T.AnyArray, T.FloatArray)); |
| 1379 CheckSub(T.Union(T.AnyArray, T.FloatArray), T.Array); |
| 1380 |
| 1381 // Function-union |
| 1382 CheckEqual( |
| 1383 T.Union(T.NumberFunction1, T.NumberFunction2), |
| 1384 T.Union(T.NumberFunction2, T.NumberFunction1)); |
| 1385 CheckSub(T.Union(T.SignedFunction1, T.MethodFunction), T.Function); |
| 1386 |
| 1180 // Union-union | 1387 // Union-union |
| 1181 CheckEqual( | 1388 CheckEqual( |
| 1182 T.Union( | 1389 T.Union( |
| 1183 T.Union(T.ObjectConstant2, T.ObjectConstant1), | 1390 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 1184 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 1391 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 1185 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 1392 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 1186 CheckEqual( | 1393 CheckEqual( |
| 1187 T.Union( | 1394 T.Union( |
| 1188 T.Union(T.Number, T.ArrayClass), | 1395 T.Union(T.Number, T.ArrayClass), |
| 1189 T.Union(T.SignedSmall, T.Array)), | 1396 T.Union(T.SignedSmall, T.Array)), |
| 1190 T.Union(T.Number, T.Array)); | 1397 T.Union(T.Number, T.Array)); |
| 1191 } | 1398 } |
| 1192 | 1399 |
| 1193 void Intersect() { | 1400 void Intersect1() { |
| 1194 // Identity: Intersect(T, Any) = T | 1401 // Identity: Intersect(T, Any) = T |
| 1195 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1402 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 1196 TypeHandle type = *it; | 1403 TypeHandle type = *it; |
| 1197 TypeHandle intersect_type = T.Intersect(type, T.Any); | 1404 TypeHandle intersect_type = T.Intersect(type, T.Any); |
| 1198 CheckEqual(intersect_type, type); | 1405 CheckEqual(intersect_type, type); |
| 1199 } | 1406 } |
| 1200 | 1407 |
| 1201 // Domination: Intersect(T, None) = None | 1408 // Domination: Intersect(T, None) = None |
| 1202 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1409 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 1203 TypeHandle type = *it; | 1410 TypeHandle type = *it; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1460 |
| 1254 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1 | 1461 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1 |
| 1255 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1462 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
| 1256 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1463 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
| 1257 TypeHandle type1 = *it1; | 1464 TypeHandle type1 = *it1; |
| 1258 TypeHandle type2 = *it2; | 1465 TypeHandle type2 = *it2; |
| 1259 TypeHandle intersect12 = T.Intersect(type1, type2); | 1466 TypeHandle intersect12 = T.Intersect(type1, type2); |
| 1260 if (type1->Is(type2)) CheckEqual(intersect12, type1); | 1467 if (type1->Is(type2)) CheckEqual(intersect12, type1); |
| 1261 } | 1468 } |
| 1262 } | 1469 } |
| 1470 } |
| 1263 | 1471 |
| 1472 void Intersect2() { |
| 1264 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3)) | 1473 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3)) |
| 1265 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1474 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
| 1266 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1475 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
| 1267 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1476 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
| 1268 TypeHandle type1 = *it1; | 1477 TypeHandle type1 = *it1; |
| 1269 TypeHandle type2 = *it2; | 1478 TypeHandle type2 = *it2; |
| 1270 TypeHandle type3 = *it3; | 1479 TypeHandle type3 = *it3; |
| 1271 TypeHandle intersect13 = T.Intersect(type1, type3); | 1480 TypeHandle intersect13 = T.Intersect(type1, type3); |
| 1272 TypeHandle intersect23 = T.Intersect(type2, type3); | 1481 TypeHandle intersect23 = T.Intersect(type2, type3); |
| 1273 CHECK(!type1->Is(type2) || intersect13->Is(intersect23)); | 1482 CHECK(!type1->Is(type2) || intersect13->Is(intersect23)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1301 type1->Is(intersect23)); | 1510 type1->Is(intersect23)); |
| 1302 } | 1511 } |
| 1303 } | 1512 } |
| 1304 } | 1513 } |
| 1305 | 1514 |
| 1306 // Bitset-class | 1515 // Bitset-class |
| 1307 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); | 1516 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); |
| 1308 CheckSub(T.Intersect(T.ObjectClass, T.Array), T.Representation); | 1517 CheckSub(T.Intersect(T.ObjectClass, T.Array), T.Representation); |
| 1309 CheckSub(T.Intersect(T.ObjectClass, T.Number), T.Representation); | 1518 CheckSub(T.Intersect(T.ObjectClass, T.Number), T.Representation); |
| 1310 | 1519 |
| 1311 // Class-constant | 1520 // Bitset-array |
| 1312 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); | 1521 CheckEqual(T.Intersect(T.FloatArray, T.Object), T.FloatArray); |
| 1313 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); | 1522 CheckSub(T.Intersect(T.AnyArray, T.Function), T.Representation); |
| 1523 |
| 1524 // Bitset-function |
| 1525 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); |
| 1526 CheckSub(T.Intersect(T.NumberFunction1, T.Array), T.Representation); |
| 1314 | 1527 |
| 1315 // Bitset-union | 1528 // Bitset-union |
| 1316 CheckEqual( | 1529 CheckEqual( |
| 1317 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), | 1530 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 1318 T.Union(T.ObjectConstant1, T.ObjectClass)); | 1531 T.Union(T.ObjectConstant1, T.ObjectClass)); |
| 1319 CheckEqual( | 1532 CheckEqual( |
| 1320 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), | 1533 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), |
| 1321 T.None); | 1534 T.None); |
| 1322 | 1535 |
| 1536 // Class-constant |
| 1537 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); |
| 1538 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); |
| 1539 |
| 1540 // Array-union |
| 1541 CheckEqual( |
| 1542 T.Intersect(T.FloatArray, T.Union(T.FloatArray, T.ArrayClass)), |
| 1543 T.FloatArray); |
| 1544 CheckEqual( |
| 1545 T.Intersect(T.AnyArray, T.Union(T.Object, T.SmiConstant)), |
| 1546 T.AnyArray); |
| 1547 CheckEqual( |
| 1548 T.Intersect(T.Union(T.AnyArray, T.ArrayConstant), T.FloatArray), |
| 1549 T.None); |
| 1550 |
| 1551 // Function-union |
| 1552 CheckEqual( |
| 1553 T.Intersect(T.MethodFunction, T.Union(T.String, T.MethodFunction)), |
| 1554 T.MethodFunction); |
| 1555 CheckEqual( |
| 1556 T.Intersect(T.NumberFunction1, T.Union(T.Object, T.SmiConstant)), |
| 1557 T.NumberFunction1); |
| 1558 CheckEqual( |
| 1559 T.Intersect(T.Union(T.MethodFunction, T.Name), T.NumberFunction2), |
| 1560 T.None); |
| 1561 |
| 1323 // Class-union | 1562 // Class-union |
| 1324 CheckEqual( | 1563 CheckEqual( |
| 1325 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), | 1564 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), |
| 1326 T.ArrayClass); | 1565 T.ArrayClass); |
| 1327 CheckEqual( | 1566 CheckEqual( |
| 1328 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), | 1567 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), |
| 1329 T.ArrayClass); | 1568 T.ArrayClass); |
| 1330 CheckEqual( | 1569 CheckEqual( |
| 1331 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass), | 1570 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass), |
| 1332 T.None); | 1571 T.None); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 TypeHandle type3 = T.template Convert<Type2>(type2); | 1619 TypeHandle type3 = T.template Convert<Type2>(type2); |
| 1381 CheckEqual(type1, type3); | 1620 CheckEqual(type1, type3); |
| 1382 } | 1621 } |
| 1383 } | 1622 } |
| 1384 }; | 1623 }; |
| 1385 | 1624 |
| 1386 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests; | 1625 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests; |
| 1387 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests; | 1626 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests; |
| 1388 | 1627 |
| 1389 | 1628 |
| 1390 TEST(Bitset) { | 1629 TEST(BitsetType) { |
| 1391 CcTest::InitializeVM(); | 1630 CcTest::InitializeVM(); |
| 1392 ZoneTests().Bitset(); | 1631 ZoneTests().Bitset(); |
| 1393 HeapTests().Bitset(); | 1632 HeapTests().Bitset(); |
| 1394 } | 1633 } |
| 1395 | 1634 |
| 1396 | 1635 |
| 1397 TEST(Class) { | 1636 TEST(ClassType) { |
| 1398 CcTest::InitializeVM(); | 1637 CcTest::InitializeVM(); |
| 1399 ZoneTests().Class(); | 1638 ZoneTests().Class(); |
| 1400 HeapTests().Class(); | 1639 HeapTests().Class(); |
| 1401 } | 1640 } |
| 1402 | 1641 |
| 1403 | 1642 |
| 1404 TEST(Constant) { | 1643 TEST(ConstantType) { |
| 1405 CcTest::InitializeVM(); | 1644 CcTest::InitializeVM(); |
| 1406 ZoneTests().Constant(); | 1645 ZoneTests().Constant(); |
| 1407 HeapTests().Constant(); | 1646 HeapTests().Constant(); |
| 1408 } | 1647 } |
| 1409 | 1648 |
| 1410 | 1649 |
| 1650 TEST(ArrayType) { |
| 1651 CcTest::InitializeVM(); |
| 1652 ZoneTests().Array(); |
| 1653 HeapTests().Array(); |
| 1654 } |
| 1655 |
| 1656 |
| 1657 TEST(FunctionType) { |
| 1658 CcTest::InitializeVM(); |
| 1659 ZoneTests().Function(); |
| 1660 HeapTests().Function(); |
| 1661 } |
| 1662 |
| 1663 |
| 1411 TEST(Of) { | 1664 TEST(Of) { |
| 1412 CcTest::InitializeVM(); | 1665 CcTest::InitializeVM(); |
| 1413 ZoneTests().Of(); | 1666 ZoneTests().Of(); |
| 1414 HeapTests().Of(); | 1667 HeapTests().Of(); |
| 1415 } | 1668 } |
| 1416 | 1669 |
| 1417 | 1670 |
| 1418 TEST(NowOf) { | 1671 TEST(NowOf) { |
| 1419 CcTest::InitializeVM(); | 1672 CcTest::InitializeVM(); |
| 1420 ZoneTests().NowOf(); | 1673 ZoneTests().NowOf(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1450 } | 1703 } |
| 1451 | 1704 |
| 1452 | 1705 |
| 1453 TEST(Maybe) { | 1706 TEST(Maybe) { |
| 1454 CcTest::InitializeVM(); | 1707 CcTest::InitializeVM(); |
| 1455 ZoneTests().Maybe(); | 1708 ZoneTests().Maybe(); |
| 1456 HeapTests().Maybe(); | 1709 HeapTests().Maybe(); |
| 1457 } | 1710 } |
| 1458 | 1711 |
| 1459 | 1712 |
| 1460 TEST(Union) { | 1713 TEST(Union1) { |
| 1461 CcTest::InitializeVM(); | 1714 CcTest::InitializeVM(); |
| 1462 ZoneTests().Union(); | 1715 ZoneTests().Union1(); |
| 1463 HeapTests().Union(); | 1716 HeapTests().Union1(); |
| 1464 } | 1717 } |
| 1465 | 1718 |
| 1466 | 1719 |
| 1467 TEST(Intersect) { | 1720 TEST(Union2) { |
| 1468 CcTest::InitializeVM(); | 1721 CcTest::InitializeVM(); |
| 1469 ZoneTests().Intersect(); | 1722 ZoneTests().Union2(); |
| 1470 HeapTests().Intersect(); | 1723 HeapTests().Union2(); |
| 1471 } | 1724 } |
| 1472 | 1725 |
| 1473 | 1726 |
| 1727 TEST(Intersect1) { |
| 1728 CcTest::InitializeVM(); |
| 1729 ZoneTests().Intersect1(); |
| 1730 HeapTests().Intersect1(); |
| 1731 } |
| 1732 |
| 1733 |
| 1734 TEST(Intersect2) { |
| 1735 CcTest::InitializeVM(); |
| 1736 ZoneTests().Intersect2(); |
| 1737 HeapTests().Intersect2(); |
| 1738 } |
| 1739 |
| 1740 |
| 1474 TEST(Convert) { | 1741 TEST(Convert) { |
| 1475 CcTest::InitializeVM(); | 1742 CcTest::InitializeVM(); |
| 1476 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1743 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
| 1477 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1744 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
| 1478 } | 1745 } |
| OLD | NEW |