Chromium Code Reviews| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <vector> | 28 #include <vector> |
| 29 | 29 |
| 30 #define private public /* To test private methods :) */ | |
|
Benedikt Meurer
2014/05/27 09:29:47
Urghs... how about friends?
rossberg1
2014/05/27 09:42:58
Because I don't want to pollute the code proper wi
| |
| 31 #define protected public | |
| 32 #include "types.h" | |
| 33 #undef private | |
| 34 #undef protected | |
| 35 | |
| 30 #include "cctest.h" | 36 #include "cctest.h" |
| 31 #include "types.h" | |
| 32 #include "utils/random-number-generator.h" | 37 #include "utils/random-number-generator.h" |
| 33 | 38 |
| 34 using namespace v8::internal; | 39 using namespace v8::internal; |
| 35 | 40 |
| 36 // Testing auxiliaries (breaking the Type abstraction). | 41 // Testing auxiliaries (breaking the Type abstraction). |
| 37 struct ZoneRep { | 42 struct ZoneRep { |
| 38 typedef void* Struct; | 43 typedef void* Struct; |
| 39 | 44 |
| 40 static bool IsStruct(Type* t, int tag) { | 45 static bool IsStruct(Type* t, int tag) { |
| 41 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; | 46 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 70 }; | 75 }; |
| 71 | 76 |
| 72 | 77 |
| 73 struct HeapRep { | 78 struct HeapRep { |
| 74 typedef FixedArray Struct; | 79 typedef FixedArray Struct; |
| 75 | 80 |
| 76 static bool IsStruct(Handle<HeapType> t, int tag) { | 81 static bool IsStruct(Handle<HeapType> t, int tag) { |
| 77 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; | 82 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; |
| 78 } | 83 } |
| 79 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } | 84 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } |
| 80 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } | 85 static bool IsClass(Handle<HeapType> t) { |
| 81 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } | 86 return t->IsMap() || IsStruct(t, 0); |
| 87 } | |
| 88 static bool IsConstant(Handle<HeapType> t) { return IsStruct(t, 1); } | |
| 82 static bool IsArray(Handle<HeapType> t) { return IsStruct(t, 2); } | 89 static bool IsArray(Handle<HeapType> t) { return IsStruct(t, 2); } |
| 83 static bool IsFunction(Handle<HeapType> t) { return IsStruct(t, 3); } | 90 static bool IsFunction(Handle<HeapType> t) { return IsStruct(t, 3); } |
| 84 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 4); } | 91 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 4); } |
| 85 | 92 |
| 86 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } | 93 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } |
| 87 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } | 94 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } |
| 88 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } | 95 static Map* AsClass(Handle<HeapType> t) { |
| 89 static Object* AsConstant(Handle<HeapType> t) { | 96 return t->IsMap() ? Map::cast(*t) : Map::cast(AsStruct(t)->get(2)); |
| 90 return Box::cast(*t)->value(); | |
| 91 } | 97 } |
| 98 static Object* AsConstant(Handle<HeapType> t) { return AsStruct(t)->get(2); } | |
| 92 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } | 99 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } |
| 93 static int Length(Struct* structured) { return structured->length() - 1; } | 100 static int Length(Struct* structured) { return structured->length() - 1; } |
| 94 | 101 |
| 95 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } | 102 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 | 105 |
| 99 template<class Type, class TypeHandle, class Region> | 106 template<class Type, class TypeHandle, class Region> |
| 100 class Types { | 107 class Types { |
| 101 public: | 108 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 152 |
| 146 FloatArray = Type::Array(Float, region); | 153 FloatArray = Type::Array(Float, region); |
| 147 StringArray = Type::Array(String, region); | 154 StringArray = Type::Array(String, region); |
| 148 AnyArray = Type::Array(Any, region); | 155 AnyArray = Type::Array(Any, region); |
| 149 | 156 |
| 150 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); | 157 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); |
| 151 NumberFunction1 = Type::Function(Number, Number, region); | 158 NumberFunction1 = Type::Function(Number, Number, region); |
| 152 NumberFunction2 = Type::Function(Number, Number, Number, region); | 159 NumberFunction2 = Type::Function(Number, Number, Number, region); |
| 153 MethodFunction = Type::Function(String, Object, 0, region); | 160 MethodFunction = Type::Function(String, Object, 0, region); |
| 154 | 161 |
| 155 for (int i = 0; i < 50; ++i) { | 162 for (int i = 0; i < 500; ++i) { |
| 156 types.push_back(Fuzz()); | 163 types.push_back(Fuzz()); |
| 157 } | 164 } |
| 158 } | 165 } |
| 159 | 166 |
| 160 Handle<i::Map> object_map; | 167 Handle<i::Map> object_map; |
| 161 Handle<i::Map> array_map; | 168 Handle<i::Map> array_map; |
| 162 Handle<i::Map> uninitialized_map; | 169 Handle<i::Map> uninitialized_map; |
| 163 | 170 |
| 164 Handle<i::Smi> smi; | 171 Handle<i::Smi> smi; |
| 165 Handle<i::HeapNumber> signed32; | 172 Handle<i::HeapNumber> signed32; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 for (int i = 0; i < n; ++i) { | 301 for (int i = 0; i < n; ++i) { |
| 295 TypeHandle operand = Fuzz(depth - 1); | 302 TypeHandle operand = Fuzz(depth - 1); |
| 296 type = Type::Union(type, operand, region_); | 303 type = Type::Union(type, operand, region_); |
| 297 } | 304 } |
| 298 return type; | 305 return type; |
| 299 } | 306 } |
| 300 } | 307 } |
| 301 UNREACHABLE(); | 308 UNREACHABLE(); |
| 302 } | 309 } |
| 303 | 310 |
| 311 Region* region() { return region_; } | |
| 312 | |
| 304 private: | 313 private: |
| 305 Region* region_; | 314 Region* region_; |
| 306 RandomNumberGenerator rng_; | 315 RandomNumberGenerator rng_; |
| 307 }; | 316 }; |
| 308 | 317 |
| 309 | 318 |
| 310 template<class Type, class TypeHandle, class Region, class Rep> | 319 template<class Type, class TypeHandle, class Region, class Rep> |
| 311 struct Tests : Rep { | 320 struct Tests : Rep { |
| 312 typedef Types<Type, TypeHandle, Region> TypesInstance; | 321 typedef Types<Type, TypeHandle, Region> TypesInstance; |
| 313 typedef typename TypesInstance::TypeVector::iterator TypeIterator; | 322 typedef typename TypesInstance::TypeVector::iterator TypeIterator; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 325 zone(isolate), | 334 zone(isolate), |
| 326 T(Rep::ToRegion(&zone, isolate), isolate) { | 335 T(Rep::ToRegion(&zone, isolate), isolate) { |
| 327 } | 336 } |
| 328 | 337 |
| 329 bool Equal(TypeHandle type1, TypeHandle type2) { | 338 bool Equal(TypeHandle type1, TypeHandle type2) { |
| 330 return | 339 return |
| 331 type1->Is(type2) && type2->Is(type1) && | 340 type1->Is(type2) && type2->Is(type1) && |
| 332 Rep::IsBitset(type1) == Rep::IsBitset(type2) && | 341 Rep::IsBitset(type1) == Rep::IsBitset(type2) && |
| 333 Rep::IsClass(type1) == Rep::IsClass(type2) && | 342 Rep::IsClass(type1) == Rep::IsClass(type2) && |
| 334 Rep::IsConstant(type1) == Rep::IsConstant(type2) && | 343 Rep::IsConstant(type1) == Rep::IsConstant(type2) && |
| 344 Rep::IsArray(type1) == Rep::IsArray(type2) && | |
| 345 Rep::IsFunction(type1) == Rep::IsFunction(type2) && | |
| 335 Rep::IsUnion(type1) == Rep::IsUnion(type2) && | 346 Rep::IsUnion(type1) == Rep::IsUnion(type2) && |
| 336 type1->NumClasses() == type2->NumClasses() && | 347 type1->NumClasses() == type2->NumClasses() && |
| 337 type1->NumConstants() == type2->NumConstants() && | 348 type1->NumConstants() == type2->NumConstants() && |
| 338 (!Rep::IsBitset(type1) || | 349 (!Rep::IsBitset(type1) || |
| 339 Rep::AsBitset(type1) == Rep::AsBitset(type2)) && | 350 Rep::AsBitset(type1) == Rep::AsBitset(type2)) && |
| 340 (!Rep::IsClass(type1) || | 351 (!Rep::IsClass(type1) || |
| 341 Rep::AsClass(type1) == Rep::AsClass(type2)) && | 352 Rep::AsClass(type1) == Rep::AsClass(type2)) && |
| 342 (!Rep::IsConstant(type1) || | 353 (!Rep::IsConstant(type1) || |
| 343 Rep::AsConstant(type1) == Rep::AsConstant(type2)) && | 354 Rep::AsConstant(type1) == Rep::AsConstant(type2)) && |
| 344 (!Rep::IsUnion(type1) || | 355 // TODO(rossberg): Check details of arrays, functions, bounds. |
| 356 (!Rep::IsUnion(type1) || | |
| 345 Rep::Length(Rep::AsUnion(type1)) == Rep::Length(Rep::AsUnion(type2))); | 357 Rep::Length(Rep::AsUnion(type1)) == Rep::Length(Rep::AsUnion(type2))); |
| 346 } | 358 } |
| 347 | 359 |
| 348 void CheckEqual(TypeHandle type1, TypeHandle type2) { | 360 void CheckEqual(TypeHandle type1, TypeHandle type2) { |
| 349 CHECK(Equal(type1, type2)); | 361 CHECK(Equal(type1, type2)); |
| 350 } | 362 } |
| 351 | 363 |
| 352 void CheckSub(TypeHandle type1, TypeHandle type2) { | 364 void CheckSub(TypeHandle type1, TypeHandle type2) { |
| 353 CHECK(type1->Is(type2)); | 365 CHECK(type1->Is(type2)); |
| 354 CHECK(!type2->Is(type1)); | 366 CHECK(!type2->Is(type1)); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 Handle<i::Object> value = *vt; | 674 Handle<i::Object> value = *vt; |
| 663 TypeHandle type = *it; | 675 TypeHandle type = *it; |
| 664 TypeHandle const_type = T.Constant(value); | 676 TypeHandle const_type = T.Constant(value); |
| 665 TypeHandle nowof_type = T.NowOf(value); | 677 TypeHandle nowof_type = T.NowOf(value); |
| 666 CHECK(!const_type->Is(type) || | 678 CHECK(!const_type->Is(type) || |
| 667 (nowof_type->Is(type) || type->Maybe(const_type))); | 679 (nowof_type->Is(type) || type->Maybe(const_type))); |
| 668 } | 680 } |
| 669 } | 681 } |
| 670 } | 682 } |
| 671 | 683 |
| 684 void Bounds() { | |
| 685 // Ordering: (T->BitsetGlb())->Is(T->BitsetLub()) | |
| 686 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | |
| 687 TypeHandle type = *it; | |
| 688 TypeHandle glb = Type::BitsetType::New(type->BitsetGlb(), T.region()); | |
| 689 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | |
| 690 CHECK(glb->Is(lub)); | |
| 691 } | |
| 692 | |
| 693 // Lower bound: (T->BitsetGlb())->Is(T) | |
| 694 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | |
| 695 TypeHandle type = *it; | |
| 696 TypeHandle glb = Type::BitsetType::New(type->BitsetGlb(), T.region()); | |
| 697 CHECK(glb->Is(type)); | |
| 698 } | |
| 699 | |
| 700 // Upper bound: T->Is(T->BitsetLub()) | |
| 701 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | |
| 702 TypeHandle type = *it; | |
| 703 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | |
| 704 CHECK(type->Is(lub)); | |
| 705 } | |
| 706 | |
| 707 // Inherent bound: (T->BitsetLub())->Is(T->InherentBitsetLub()) | |
| 708 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | |
| 709 TypeHandle type = *it; | |
| 710 TypeHandle lub = Type::BitsetType::New(type->BitsetLub(), T.region()); | |
| 711 TypeHandle inherent = | |
| 712 Type::BitsetType::New(type->InherentBitsetLub(), T.region()); | |
| 713 CHECK(lub->Is(inherent)); | |
| 714 } | |
| 715 } | |
| 716 | |
| 672 void Is() { | 717 void Is() { |
| 673 // Least Element (Bottom): None->Is(T) | 718 // Least Element (Bottom): None->Is(T) |
| 674 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 719 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 675 TypeHandle type = *it; | 720 TypeHandle type = *it; |
| 676 CHECK(T.None->Is(type)); | 721 CHECK(T.None->Is(type)); |
| 677 } | 722 } |
| 678 | 723 |
| 679 // Greatest Element (Top): T->Is(Any) | 724 // Greatest Element (Top): T->Is(Any) |
| 680 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 725 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 681 TypeHandle type = *it; | 726 TypeHandle type = *it; |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1528 CheckSub(T.Intersect(T.AnyArray, T.Function), T.Representation); | 1573 CheckSub(T.Intersect(T.AnyArray, T.Function), T.Representation); |
| 1529 | 1574 |
| 1530 // Bitset-function | 1575 // Bitset-function |
| 1531 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); | 1576 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); |
| 1532 CheckSub(T.Intersect(T.NumberFunction1, T.Array), T.Representation); | 1577 CheckSub(T.Intersect(T.NumberFunction1, T.Array), T.Representation); |
| 1533 | 1578 |
| 1534 // Bitset-union | 1579 // Bitset-union |
| 1535 CheckEqual( | 1580 CheckEqual( |
| 1536 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), | 1581 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 1537 T.Union(T.ObjectConstant1, T.ObjectClass)); | 1582 T.Union(T.ObjectConstant1, T.ObjectClass)); |
| 1538 CheckEqual( | 1583 CHECK( |
| 1539 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), | 1584 !T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number) |
| 1540 T.None); | 1585 ->IsInhabited()); |
| 1541 | 1586 |
| 1542 // Class-constant | 1587 // Class-constant |
| 1543 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); | 1588 TypeHandle NoneTaggedPtr = T.Intersect(T.TaggedPtr, T.Representation); |
| 1544 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); | 1589 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), NoneTaggedPtr); |
| 1590 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), NoneTaggedPtr); | |
| 1545 | 1591 |
| 1546 // Array-union | 1592 // Array-union |
| 1547 CheckEqual( | 1593 CheckEqual( |
| 1548 T.Intersect(T.FloatArray, T.Union(T.FloatArray, T.ArrayClass)), | 1594 T.Intersect(T.FloatArray, T.Union(T.FloatArray, T.ArrayClass)), |
| 1549 T.FloatArray); | 1595 T.FloatArray); |
| 1550 CheckEqual( | 1596 CheckEqual( |
| 1551 T.Intersect(T.AnyArray, T.Union(T.Object, T.SmiConstant)), | 1597 T.Intersect(T.AnyArray, T.Union(T.Object, T.SmiConstant)), |
| 1552 T.AnyArray); | 1598 T.AnyArray); |
| 1553 CheckEqual( | 1599 CHECK( |
| 1554 T.Intersect(T.Union(T.AnyArray, T.ArrayConstant), T.FloatArray), | 1600 !T.Intersect(T.Union(T.AnyArray, T.ArrayConstant), T.FloatArray) |
| 1555 T.None); | 1601 ->IsInhabited()); |
| 1556 | 1602 |
| 1557 // Function-union | 1603 // Function-union |
| 1558 CheckEqual( | 1604 CheckEqual( |
| 1559 T.Intersect(T.MethodFunction, T.Union(T.String, T.MethodFunction)), | 1605 T.Intersect(T.MethodFunction, T.Union(T.String, T.MethodFunction)), |
| 1560 T.MethodFunction); | 1606 T.MethodFunction); |
| 1561 CheckEqual( | 1607 CheckEqual( |
| 1562 T.Intersect(T.NumberFunction1, T.Union(T.Object, T.SmiConstant)), | 1608 T.Intersect(T.NumberFunction1, T.Union(T.Object, T.SmiConstant)), |
| 1563 T.NumberFunction1); | 1609 T.NumberFunction1); |
| 1564 CheckEqual( | 1610 CHECK( |
| 1565 T.Intersect(T.Union(T.MethodFunction, T.Name), T.NumberFunction2), | 1611 !T.Intersect(T.Union(T.MethodFunction, T.Name), T.NumberFunction2) |
| 1566 T.None); | 1612 ->IsInhabited()); |
| 1567 | 1613 |
| 1568 // Class-union | 1614 // Class-union |
| 1569 CheckEqual( | 1615 CheckEqual( |
| 1570 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), | 1616 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), |
| 1571 T.ArrayClass); | 1617 T.ArrayClass); |
| 1572 CheckEqual( | 1618 CheckEqual( |
| 1573 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), | 1619 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), |
| 1574 T.ArrayClass); | 1620 T.ArrayClass); |
| 1575 CheckEqual( | 1621 CHECK( |
| 1576 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass), | 1622 !T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass) |
| 1577 T.None); | 1623 ->IsInhabited()); |
| 1578 | 1624 |
| 1579 // Constant-union | 1625 // Constant-union |
| 1580 CheckEqual( | 1626 CheckEqual( |
| 1581 T.Intersect( | 1627 T.Intersect( |
| 1582 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 1628 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 1583 T.ObjectConstant1); | 1629 T.ObjectConstant1); |
| 1584 CheckEqual( | 1630 CheckEqual( |
| 1585 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), | 1631 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), |
| 1586 T.SmiConstant); | 1632 T.SmiConstant); |
| 1587 CheckEqual( | 1633 CHECK( |
| 1588 T.Intersect( | 1634 !T.Intersect( |
| 1589 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1), | 1635 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1) |
| 1590 T.None); | 1636 ->IsInhabited()); |
| 1591 | 1637 |
| 1592 // Union-union | 1638 // Union-union |
| 1593 CheckEqual( | 1639 CheckEqual( |
| 1594 T.Intersect( | 1640 T.Intersect( |
| 1595 T.Union(T.Number, T.ArrayClass), | 1641 T.Union(T.Number, T.ArrayClass), |
| 1596 T.Union(T.SignedSmall, T.Array)), | 1642 T.Union(T.SignedSmall, T.Array)), |
| 1597 T.Union(T.SignedSmall, T.ArrayClass)); | 1643 T.Union(T.SignedSmall, T.ArrayClass)); |
| 1598 CheckEqual( | 1644 CheckEqual( |
| 1599 T.Intersect( | 1645 T.Intersect( |
| 1600 T.Union(T.Number, T.ObjectClass), | 1646 T.Union(T.Number, T.ObjectClass), |
| 1601 T.Union(T.Signed32, T.Array)), | 1647 T.Union(T.Signed32, T.Array)), |
| 1602 T.Signed32); | 1648 T.Signed32); |
| 1603 CheckEqual( | 1649 CheckEqual( |
| 1604 T.Intersect( | 1650 T.Intersect( |
| 1605 T.Union(T.ObjectConstant2, T.ObjectConstant1), | 1651 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 1606 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 1652 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 1607 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 1653 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 1608 CheckEqual( | 1654 CheckEqual( |
| 1609 T.Intersect( | 1655 T.Intersect( |
| 1610 T.Union( | 1656 T.Union( |
| 1611 T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), | 1657 T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), |
| 1612 T.Union( | 1658 T.Union( |
| 1613 T.ObjectConstant1, | 1659 T.ObjectConstant1, |
| 1614 T.Union(T.ArrayConstant, T.ObjectConstant2))), | 1660 T.Union(T.ArrayConstant, T.ObjectConstant2))), |
| 1615 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 1661 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 1616 } | 1662 } |
| 1617 | 1663 |
| 1664 void Distributivity() { | |
| 1665 // Distributivity: | |
| 1666 // Union(T1, Intersect(T2, T3)) = Intersect(Union(T1, T2), Union(T1, T3)) | |
| 1667 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | |
| 1668 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | |
| 1669 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | |
| 1670 TypeHandle type1 = *it1; | |
| 1671 TypeHandle type2 = *it2; | |
| 1672 TypeHandle type3 = *it3; | |
| 1673 TypeHandle union12 = T.Union(type1, type2); | |
| 1674 TypeHandle union13 = T.Union(type1, type3); | |
| 1675 TypeHandle intersect23 = T.Intersect(type2, type3); | |
| 1676 TypeHandle union1_23 = T.Union(type1, intersect23); | |
| 1677 TypeHandle intersect12_13 = T.Intersect(union12, union13); | |
| 1678 CHECK(Equal(union1_23, intersect12_13)); | |
| 1679 } | |
| 1680 } | |
| 1681 } | |
| 1682 | |
| 1683 // Distributivity: | |
| 1684 // Intersect(T1, Union(T2, T3)) = Union(Intersect(T1, T2), Intersect(T1,T3)) | |
| 1685 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | |
| 1686 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | |
| 1687 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | |
| 1688 TypeHandle type1 = *it1; | |
| 1689 TypeHandle type2 = *it2; | |
| 1690 TypeHandle type3 = *it3; | |
| 1691 TypeHandle intersect12 = T.Intersect(type1, type2); | |
| 1692 TypeHandle intersect13 = T.Intersect(type1, type3); | |
| 1693 TypeHandle union23 = T.Union(type2, type3); | |
| 1694 TypeHandle intersect1_23 = T.Intersect(type1, union23); | |
| 1695 TypeHandle union12_13 = T.Union(intersect12, intersect13); | |
| 1696 CHECK(Equal(intersect1_23, union12_13)); | |
| 1697 } | |
| 1698 } | |
| 1699 } | |
| 1700 } | |
| 1701 | |
| 1618 template<class Type2, class TypeHandle2, class Region2, class Rep2> | 1702 template<class Type2, class TypeHandle2, class Region2, class Rep2> |
| 1619 void Convert() { | 1703 void Convert() { |
| 1620 Types<Type2, TypeHandle2, Region2> T2( | 1704 Types<Type2, TypeHandle2, Region2> T2( |
| 1621 Rep2::ToRegion(&zone, isolate), isolate); | 1705 Rep2::ToRegion(&zone, isolate), isolate); |
| 1622 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1706 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| 1623 TypeHandle type1 = *it; | 1707 TypeHandle type1 = *it; |
| 1624 TypeHandle2 type2 = T2.template Convert<Type>(type1); | 1708 TypeHandle2 type2 = T2.template Convert<Type>(type1); |
| 1625 TypeHandle type3 = T.template Convert<Type2>(type2); | 1709 TypeHandle type3 = T.template Convert<Type2>(type2); |
| 1626 CheckEqual(type1, type3); | 1710 CheckEqual(type1, type3); |
| 1627 } | 1711 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1674 } | 1758 } |
| 1675 | 1759 |
| 1676 | 1760 |
| 1677 TEST(NowOf) { | 1761 TEST(NowOf) { |
| 1678 CcTest::InitializeVM(); | 1762 CcTest::InitializeVM(); |
| 1679 ZoneTests().NowOf(); | 1763 ZoneTests().NowOf(); |
| 1680 HeapTests().NowOf(); | 1764 HeapTests().NowOf(); |
| 1681 } | 1765 } |
| 1682 | 1766 |
| 1683 | 1767 |
| 1768 TEST(Bounds) { | |
| 1769 CcTest::InitializeVM(); | |
| 1770 ZoneTests().Bounds(); | |
| 1771 HeapTests().Bounds(); | |
| 1772 } | |
| 1773 | |
| 1774 | |
| 1684 TEST(Is) { | 1775 TEST(Is) { |
| 1685 CcTest::InitializeVM(); | 1776 CcTest::InitializeVM(); |
| 1686 ZoneTests().Is(); | 1777 ZoneTests().Is(); |
| 1687 HeapTests().Is(); | 1778 HeapTests().Is(); |
| 1688 } | 1779 } |
| 1689 | 1780 |
| 1690 | 1781 |
| 1691 TEST(NowIs) { | 1782 TEST(NowIs) { |
| 1692 CcTest::InitializeVM(); | 1783 CcTest::InitializeVM(); |
| 1693 ZoneTests().NowIs(); | 1784 ZoneTests().NowIs(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1737 } | 1828 } |
| 1738 | 1829 |
| 1739 | 1830 |
| 1740 TEST(Intersect2) { | 1831 TEST(Intersect2) { |
| 1741 CcTest::InitializeVM(); | 1832 CcTest::InitializeVM(); |
| 1742 ZoneTests().Intersect2(); | 1833 ZoneTests().Intersect2(); |
| 1743 HeapTests().Intersect2(); | 1834 HeapTests().Intersect2(); |
| 1744 } | 1835 } |
| 1745 | 1836 |
| 1746 | 1837 |
| 1838 TEST(Distributivity) { | |
| 1839 CcTest::InitializeVM(); | |
| 1840 ZoneTests().Distributivity(); | |
| 1841 HeapTests().Distributivity(); | |
| 1842 } | |
| 1843 | |
| 1844 | |
| 1747 TEST(Convert) { | 1845 TEST(Convert) { |
| 1748 CcTest::InitializeVM(); | 1846 CcTest::InitializeVM(); |
| 1749 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1847 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
| 1750 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1848 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
| 1751 } | 1849 } |
| OLD | NEW |