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

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

Issue 877643002: Reland of "Steps towards unification of number bitset and range types." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Avoid (some of the) uninhabited type normalization based on representation. Created 5 years, 10 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "src/hydrogen-types.h" 7 #include "src/hydrogen-types.h"
8 #include "src/isolate-inl.h" 8 #include "src/isolate-inl.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 #include "test/cctest/cctest.h" 10 #include "test/cctest/cctest.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 void CheckSub(TypeHandle type1, TypeHandle type2) { 130 void CheckSub(TypeHandle type1, TypeHandle type2) {
131 CHECK(type1->Is(type2)); 131 CHECK(type1->Is(type2));
132 CHECK(!type2->Is(type1)); 132 CHECK(!type2->Is(type1));
133 if (this->IsBitset(type1) && this->IsBitset(type2)) { 133 if (this->IsBitset(type1) && this->IsBitset(type2)) {
134 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); 134 CHECK(this->AsBitset(type1) != this->AsBitset(type2));
135 } 135 }
136 } 136 }
137 137
138 void CheckSubOrEqual(TypeHandle type1, TypeHandle type2) {
139 CHECK(type1->Is(type2));
140 if (this->IsBitset(type1) && this->IsBitset(type2)) {
141 CHECK((this->AsBitset(type1) | this->AsBitset(type2))
142 == this->AsBitset(type2));
143 }
144 }
145
138 void CheckUnordered(TypeHandle type1, TypeHandle type2) { 146 void CheckUnordered(TypeHandle type1, TypeHandle type2) {
139 CHECK(!type1->Is(type2)); 147 CHECK(!type1->Is(type2));
140 CHECK(!type2->Is(type1)); 148 CHECK(!type2->Is(type1));
141 if (this->IsBitset(type1) && this->IsBitset(type2)) { 149 if (this->IsBitset(type1) && this->IsBitset(type2)) {
142 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); 150 CHECK(this->AsBitset(type1) != this->AsBitset(type2));
143 } 151 }
144 } 152 }
145 153
146 void CheckOverlap(TypeHandle type1, TypeHandle type2) { 154 void CheckOverlap(TypeHandle type1, TypeHandle type2) {
147 CHECK(type1->Maybe(type2)); 155 CHECK(type1->Maybe(type2));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 TypeHandle type2 = T.Constant(value2); 294 TypeHandle type2 = T.Constant(value2);
287 CHECK(Equal(type1, type2) == (*value1 == *value2)); 295 CHECK(Equal(type1, type2) == (*value1 == *value2));
288 } 296 }
289 } 297 }
290 298
291 // Typing of numbers 299 // Typing of numbers
292 Factory* fac = isolate->factory(); 300 Factory* fac = isolate->factory();
293 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); 301 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall));
294 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); 302 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall));
295 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); 303 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall));
296 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.NegativeSignedSmall)); 304 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31));
297 CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.NegativeSignedSmall)); 305 CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31));
298 CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.NegativeSignedSmall)); 306 CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.Negative31));
307 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned31));
308 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned30));
309 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31));
310 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30));
311 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative32));
312 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative31));
313 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32));
314 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31));
299 if (SmiValuesAre31Bits()) { 315 if (SmiValuesAre31Bits()) {
300 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32));
301 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); 316 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
302 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32));
303 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); 317 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
304 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32)); 318 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
305 CHECK( 319 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
306 !T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
307 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
308 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))
309 ->Is(T.NegativeSignedSmall));
310 } else { 320 } else {
311 CHECK(SmiValuesAre32Bits()); 321 CHECK(SmiValuesAre32Bits());
312 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); 322 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
313 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); 323 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
314 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32)); 324 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
315 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32)); 325 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
316 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
317 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSignedSmall));
318 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))
319 ->Is(T.NegativeSignedSmall));
320 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32));
321 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
322 CHECK(
323 T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.NegativeSigned32));
324 } 326 }
325 CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); 327 CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32));
326 CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.NonNegativeSigned32)); 328 CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31));
327 CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); 329 CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32));
328 CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.NonNegativeSigned32)); 330 CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31));
329 CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); 331 CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber));
330 CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); 332 CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32));
331 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); 333 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber));
332 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32)); 334 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32));
333 CHECK(T.Constant(fac->NewNumber(0.1))->Is(T.PlainNumber)); 335 CHECK(T.Constant(fac->NewNumber(0.1))->Is(T.PlainNumber));
334 CHECK(!T.Constant(fac->NewNumber(0.1))->Is(T.Integral32)); 336 CHECK(!T.Constant(fac->NewNumber(0.1))->Is(T.Integral32));
335 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.PlainNumber)); 337 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.PlainNumber));
336 CHECK(!T.Constant(fac->NewNumber(-10.1))->Is(T.Integral32)); 338 CHECK(!T.Constant(fac->NewNumber(-10.1))->Is(T.Integral32));
337 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber)); 339 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber));
338 CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32)); 340 CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32));
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // (In-)Compatibilities. 790 // (In-)Compatibilities.
789 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { 791 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) {
790 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { 792 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) {
791 TypeHandle type1 = *i; 793 TypeHandle type1 = *i;
792 TypeHandle type2 = *j; 794 TypeHandle type2 = *j;
793 CHECK(!type1->Is(type2) || this->IsBitset(type2) || 795 CHECK(!type1->Is(type2) || this->IsBitset(type2) ||
794 this->IsUnion(type2) || this->IsUnion(type1) || 796 this->IsUnion(type2) || this->IsUnion(type1) ||
795 (type1->IsClass() && type2->IsClass()) || 797 (type1->IsClass() && type2->IsClass()) ||
796 (type1->IsConstant() && type2->IsConstant()) || 798 (type1->IsConstant() && type2->IsConstant()) ||
797 (type1->IsConstant() && type2->IsRange()) || 799 (type1->IsConstant() && type2->IsRange()) ||
800 (this->IsBitset(type1) && type2->IsRange()) ||
798 (type1->IsRange() && type2->IsRange()) || 801 (type1->IsRange() && type2->IsRange()) ||
799 (type1->IsContext() && type2->IsContext()) || 802 (type1->IsContext() && type2->IsContext()) ||
800 (type1->IsArray() && type2->IsArray()) || 803 (type1->IsArray() && type2->IsArray()) ||
801 (type1->IsFunction() && type2->IsFunction()) || 804 (type1->IsFunction() && type2->IsFunction()) ||
802 type1->Equals(T.None)); 805 type1->Equals(T.None));
803 } 806 }
804 } 807 }
805 } 808 }
806 809
807 void Is2() { 810 void Is2() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 929
927 930
928 // Subtyping between concrete basic types 931 // Subtyping between concrete basic types
929 932
930 CheckUnordered(T.Boolean, T.Null); 933 CheckUnordered(T.Boolean, T.Null);
931 CheckUnordered(T.Undefined, T.Null); 934 CheckUnordered(T.Undefined, T.Null);
932 CheckUnordered(T.Boolean, T.Undefined); 935 CheckUnordered(T.Boolean, T.Undefined);
933 936
934 CheckSub(T.SignedSmall, T.Number); 937 CheckSub(T.SignedSmall, T.Number);
935 CheckSub(T.Signed32, T.Number); 938 CheckSub(T.Signed32, T.Number);
936 CheckSub(T.SignedSmall, T.Signed32); 939 CheckSubOrEqual(T.SignedSmall, T.Signed32);
937 CheckUnordered(T.SignedSmall, T.MinusZero); 940 CheckUnordered(T.SignedSmall, T.MinusZero);
938 CheckUnordered(T.Signed32, T.Unsigned32); 941 CheckUnordered(T.Signed32, T.Unsigned32);
939 942
940 CheckSub(T.UniqueName, T.Name); 943 CheckSub(T.UniqueName, T.Name);
941 CheckSub(T.String, T.Name); 944 CheckSub(T.String, T.Name);
942 CheckSub(T.InternalizedString, T.String); 945 CheckSub(T.InternalizedString, T.String);
943 CheckSub(T.InternalizedString, T.UniqueName); 946 CheckSub(T.InternalizedString, T.UniqueName);
944 CheckSub(T.InternalizedString, T.Name); 947 CheckSub(T.InternalizedString, T.Name);
945 CheckSub(T.Symbol, T.UniqueName); 948 CheckSub(T.Symbol, T.UniqueName);
946 CheckSub(T.Symbol, T.Name); 949 CheckSub(T.Symbol, T.Name);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 // Bitset-function 1473 // Bitset-function
1471 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Object))); 1474 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Object)));
1472 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number))); 1475 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number)));
1473 1476
1474 CheckEqual(T.Union(T.MethodFunction, T.Object), T.Object); 1477 CheckEqual(T.Union(T.MethodFunction, T.Object), T.Object);
1475 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Object); 1478 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Object);
1476 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object); 1479 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object);
1477 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number); 1480 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number);
1478 1481
1479 // Bitset-class 1482 // Bitset-class
1480 CheckSub( 1483 CheckSub(T.Union(T.ObjectClass, T.SignedSmall),
1481 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); 1484 T.Union(T.Object, T.Number));
1482 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); 1485 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object);
1483 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); 1486 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array);
1484 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); 1487 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object);
1485 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); 1488 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number);
1486 1489
1487 // Bitset-constant 1490 // Bitset-constant
1488 CheckSub( 1491 CheckSub(
1489 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); 1492 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number));
1490 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); 1493 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object);
1491 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); 1494 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 T.Union(T.NumberFunction1, T.NumberFunction2), 1544 T.Union(T.NumberFunction1, T.NumberFunction2),
1542 T.Union(T.NumberFunction2, T.NumberFunction1)); 1545 T.Union(T.NumberFunction2, T.NumberFunction1));
1543 CheckSub(T.Union(T.SignedFunction1, T.MethodFunction), T.Object); 1546 CheckSub(T.Union(T.SignedFunction1, T.MethodFunction), T.Object);
1544 1547
1545 // Union-union 1548 // Union-union
1546 CheckEqual( 1549 CheckEqual(
1547 T.Union( 1550 T.Union(
1548 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1551 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1549 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1552 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1550 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1553 T.Union(T.ObjectConstant2, T.ObjectConstant1));
1551 CheckEqual( 1554 CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass),
1552 T.Union( 1555 T.Union(T.SignedSmall, T.Array)),
1553 T.Union(T.Number, T.ArrayClass), 1556 T.Union(T.Number, T.Array));
1554 T.Union(T.SignedSmall, T.Array)),
1555 T.Union(T.Number, T.Array));
1556 } 1557 }
1557 1558
1558 void Intersect() { 1559 void Intersect() {
1559 // Identity: Intersect(T, Any) = T 1560 // Identity: Intersect(T, Any) = T
1560 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1561 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1561 TypeHandle type = *it; 1562 TypeHandle type = *it;
1562 TypeHandle intersect_type = T.Intersect(type, T.Any); 1563 TypeHandle intersect_type = T.Intersect(type, T.Any);
1563 CheckEqual(intersect_type, type); 1564 CheckEqual(intersect_type, type);
1564 } 1565 }
1565 1566
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 T.ObjectConstant1); 1760 T.ObjectConstant1);
1760 CheckEqual( 1761 CheckEqual(
1761 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), 1762 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
1762 T.SmiConstant); 1763 T.SmiConstant);
1763 CHECK( 1764 CHECK(
1764 T.Intersect( 1765 T.Intersect(
1765 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1) 1766 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1)
1766 ->IsInhabited()); // !!! 1767 ->IsInhabited()); // !!!
1767 1768
1768 // Union-union 1769 // Union-union
1769 CheckEqual( 1770 CheckEqual(T.Intersect(T.Union(T.Number, T.ArrayClass),
1770 T.Intersect( 1771 T.Union(T.SignedSmall, T.Array)),
1771 T.Union(T.Number, T.ArrayClass), 1772 T.Union(T.SignedSmall, T.ArrayClass));
1772 T.Union(T.SignedSmall, T.Array)),
1773 T.Union(T.SignedSmall, T.ArrayClass));
1774 CheckEqual( 1773 CheckEqual(
1775 T.Intersect( 1774 T.Intersect(
1776 T.Union(T.Number, T.ObjectClass), 1775 T.Union(T.Number, T.ObjectClass),
1777 T.Union(T.Signed32, T.Array)), 1776 T.Union(T.Signed32, T.Array)),
1778 T.Signed32); 1777 T.Signed32);
1779 CheckEqual( 1778 CheckEqual(
1780 T.Intersect( 1779 T.Intersect(
1781 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1780 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1782 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1781 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1783 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1782 T.Union(T.ObjectConstant2, T.ObjectConstant1));
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 2079 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
2081 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 2080 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
2082 } 2081 }
2083 2082
2084 2083
2085 TEST(HTypeFromType) { 2084 TEST(HTypeFromType) {
2086 CcTest::InitializeVM(); 2085 CcTest::InitializeVM();
2087 ZoneTests().HTypeFromType(); 2086 ZoneTests().HTypeFromType();
2088 HeapTests().HTypeFromType(); 2087 HeapTests().HTypeFromType();
2089 } 2088 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698