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

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

Issue 795713003: Steps towards unification of number bitset and range types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing review comments. Created 5 years, 11 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 TypeHandle type2 = T.Constant(value2); 287 TypeHandle type2 = T.Constant(value2);
288 CHECK(Equal(type1, type2) == (*value1 == *value2)); 288 CHECK(Equal(type1, type2) == (*value1 == *value2));
289 } 289 }
290 } 290 }
291 291
292 // Typing of numbers 292 // Typing of numbers
293 Factory* fac = isolate->factory(); 293 Factory* fac = isolate->factory();
294 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); 294 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall));
295 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); 295 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall));
296 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); 296 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall));
297 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.NegativeSignedSmall)); 297 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31));
298 CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.NegativeSignedSmall)); 298 CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31));
299 CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.NegativeSignedSmall)); 299 CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.Negative31));
300 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned31));
301 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned30));
302 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31));
303 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30));
304 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative32));
305 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative31));
306 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32));
307 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31));
300 if (SmiValuesAre31Bits()) { 308 if (SmiValuesAre31Bits()) {
301 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32));
302 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); 309 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
303 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32));
304 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); 310 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
305 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32)); 311 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
306 CHECK( 312 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
307 !T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
308 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
309 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))
310 ->Is(T.NegativeSignedSmall));
311 } else { 313 } else {
312 CHECK(SmiValuesAre32Bits()); 314 CHECK(SmiValuesAre32Bits());
313 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); 315 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
314 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); 316 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
315 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32)); 317 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
316 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32)); 318 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
317 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
318 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSignedSmall));
319 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))
320 ->Is(T.NegativeSignedSmall));
321 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32));
322 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
323 CHECK(
324 T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.NegativeSigned32));
325 } 319 }
326 CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); 320 CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32));
327 CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.NonNegativeSigned32)); 321 CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31));
328 CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); 322 CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32));
329 CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.NonNegativeSigned32)); 323 CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31));
330 CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); 324 CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber));
331 CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); 325 CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32));
332 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); 326 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber));
333 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32)); 327 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32));
334 CHECK(T.Constant(fac->NewNumber(0.1))->Is(T.PlainNumber)); 328 CHECK(T.Constant(fac->NewNumber(0.1))->Is(T.PlainNumber));
335 CHECK(!T.Constant(fac->NewNumber(0.1))->Is(T.Integral32)); 329 CHECK(!T.Constant(fac->NewNumber(0.1))->Is(T.Integral32));
336 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.PlainNumber)); 330 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.PlainNumber));
337 CHECK(!T.Constant(fac->NewNumber(-10.1))->Is(T.Integral32)); 331 CHECK(!T.Constant(fac->NewNumber(-10.1))->Is(T.Integral32));
338 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber)); 332 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber));
339 CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32)); 333 CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32));
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // (In-)Compatibilities. 782 // (In-)Compatibilities.
789 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { 783 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) {
790 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { 784 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) {
791 TypeHandle type1 = *i; 785 TypeHandle type1 = *i;
792 TypeHandle type2 = *j; 786 TypeHandle type2 = *j;
793 CHECK(!type1->Is(type2) || this->IsBitset(type2) || 787 CHECK(!type1->Is(type2) || this->IsBitset(type2) ||
794 this->IsUnion(type2) || this->IsUnion(type1) || 788 this->IsUnion(type2) || this->IsUnion(type1) ||
795 (type1->IsClass() && type2->IsClass()) || 789 (type1->IsClass() && type2->IsClass()) ||
796 (type1->IsConstant() && type2->IsConstant()) || 790 (type1->IsConstant() && type2->IsConstant()) ||
797 (type1->IsConstant() && type2->IsRange()) || 791 (type1->IsConstant() && type2->IsRange()) ||
792 (this->IsBitset(type1) && type2->IsRange()) ||
798 (type1->IsRange() && type2->IsRange()) || 793 (type1->IsRange() && type2->IsRange()) ||
799 (type1->IsContext() && type2->IsContext()) || 794 (type1->IsContext() && type2->IsContext()) ||
800 (type1->IsArray() && type2->IsArray()) || 795 (type1->IsArray() && type2->IsArray()) ||
801 (type1->IsFunction() && type2->IsFunction()) || 796 (type1->IsFunction() && type2->IsFunction()) ||
802 type1->Equals(T.None)); 797 type1->Equals(T.None));
803 } 798 }
804 } 799 }
805 } 800 }
806 801
807 void Is2() { 802 void Is2() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 921
927 922
928 // Subtyping between concrete basic types 923 // Subtyping between concrete basic types
929 924
930 CheckUnordered(T.Boolean, T.Null); 925 CheckUnordered(T.Boolean, T.Null);
931 CheckUnordered(T.Undefined, T.Null); 926 CheckUnordered(T.Undefined, T.Null);
932 CheckUnordered(T.Boolean, T.Undefined); 927 CheckUnordered(T.Boolean, T.Undefined);
933 928
934 CheckSub(T.SignedSmall, T.Number); 929 CheckSub(T.SignedSmall, T.Number);
935 CheckSub(T.Signed32, T.Number); 930 CheckSub(T.Signed32, T.Number);
936 CheckSub(T.SignedSmall, T.Signed32); 931 CheckSub(T.Signed31, T.Signed32);
rossberg 2015/01/19 11:43:56 Nit: change this back as well. It's actually impor
937 CheckUnordered(T.SignedSmall, T.MinusZero); 932 CheckUnordered(T.SignedSmall, T.MinusZero);
938 CheckUnordered(T.Signed32, T.Unsigned32); 933 CheckUnordered(T.Signed32, T.Unsigned32);
939 934
940 CheckSub(T.UniqueName, T.Name); 935 CheckSub(T.UniqueName, T.Name);
941 CheckSub(T.String, T.Name); 936 CheckSub(T.String, T.Name);
942 CheckSub(T.InternalizedString, T.String); 937 CheckSub(T.InternalizedString, T.String);
943 CheckSub(T.InternalizedString, T.UniqueName); 938 CheckSub(T.InternalizedString, T.UniqueName);
944 CheckSub(T.InternalizedString, T.Name); 939 CheckSub(T.InternalizedString, T.Name);
945 CheckSub(T.Symbol, T.UniqueName); 940 CheckSub(T.Symbol, T.UniqueName);
946 CheckSub(T.Symbol, T.Name); 941 CheckSub(T.Symbol, T.Name);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 // Bitset-function 1465 // Bitset-function
1471 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Object))); 1466 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Object)));
1472 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number))); 1467 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number)));
1473 1468
1474 CheckEqual(T.Union(T.MethodFunction, T.Object), T.Object); 1469 CheckEqual(T.Union(T.MethodFunction, T.Object), T.Object);
1475 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Object); 1470 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Object);
1476 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object); 1471 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object);
1477 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number); 1472 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number);
1478 1473
1479 // Bitset-class 1474 // Bitset-class
1480 CheckSub( 1475 CheckSub(T.Union(T.ObjectClass, T.SignedSmall),
1481 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); 1476 T.Union(T.Object, T.Number));
1482 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); 1477 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object);
1483 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); 1478 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array);
1484 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); 1479 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object);
1485 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); 1480 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number);
1486 1481
1487 // Bitset-constant 1482 // Bitset-constant
1488 CheckSub( 1483 CheckSub(
1489 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); 1484 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number));
1490 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); 1485 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object);
1491 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); 1486 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), 1536 T.Union(T.NumberFunction1, T.NumberFunction2),
1542 T.Union(T.NumberFunction2, T.NumberFunction1)); 1537 T.Union(T.NumberFunction2, T.NumberFunction1));
1543 CheckSub(T.Union(T.SignedFunction1, T.MethodFunction), T.Object); 1538 CheckSub(T.Union(T.SignedFunction1, T.MethodFunction), T.Object);
1544 1539
1545 // Union-union 1540 // Union-union
1546 CheckEqual( 1541 CheckEqual(
1547 T.Union( 1542 T.Union(
1548 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1543 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1549 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1544 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1550 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1545 T.Union(T.ObjectConstant2, T.ObjectConstant1));
1551 CheckEqual( 1546 CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass),
1552 T.Union( 1547 T.Union(T.SignedSmall, T.Array)),
1553 T.Union(T.Number, T.ArrayClass), 1548 T.Union(T.Number, T.Array));
1554 T.Union(T.SignedSmall, T.Array)),
1555 T.Union(T.Number, T.Array));
1556 } 1549 }
1557 1550
1558 void Intersect() { 1551 void Intersect() {
1559 // Identity: Intersect(T, Any) = T 1552 // Identity: Intersect(T, Any) = T
1560 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1553 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1561 TypeHandle type = *it; 1554 TypeHandle type = *it;
1562 TypeHandle intersect_type = T.Intersect(type, T.Any); 1555 TypeHandle intersect_type = T.Intersect(type, T.Any);
1563 CheckEqual(intersect_type, type); 1556 CheckEqual(intersect_type, type);
1564 } 1557 }
1565 1558
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 T.ObjectConstant1); 1752 T.ObjectConstant1);
1760 CheckEqual( 1753 CheckEqual(
1761 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), 1754 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
1762 T.SmiConstant); 1755 T.SmiConstant);
1763 CHECK( 1756 CHECK(
1764 T.Intersect( 1757 T.Intersect(
1765 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1) 1758 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1)
1766 ->IsInhabited()); // !!! 1759 ->IsInhabited()); // !!!
1767 1760
1768 // Union-union 1761 // Union-union
1769 CheckEqual( 1762 CheckEqual(T.Intersect(T.Union(T.Number, T.ArrayClass),
1770 T.Intersect( 1763 T.Union(T.SignedSmall, T.Array)),
1771 T.Union(T.Number, T.ArrayClass), 1764 T.Union(T.SignedSmall, T.ArrayClass));
1772 T.Union(T.SignedSmall, T.Array)),
1773 T.Union(T.SignedSmall, T.ArrayClass));
1774 CheckEqual( 1765 CheckEqual(
1775 T.Intersect( 1766 T.Intersect(
1776 T.Union(T.Number, T.ObjectClass), 1767 T.Union(T.Number, T.ObjectClass),
1777 T.Union(T.Signed32, T.Array)), 1768 T.Union(T.Signed32, T.Array)),
1778 T.Signed32); 1769 T.Signed32);
1779 CheckEqual( 1770 CheckEqual(
1780 T.Intersect( 1771 T.Intersect(
1781 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1772 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1782 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1773 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1783 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1774 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>(); 2071 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
2081 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 2072 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
2082 } 2073 }
2083 2074
2084 2075
2085 TEST(HTypeFromType) { 2076 TEST(HTypeFromType) {
2086 CcTest::InitializeVM(); 2077 CcTest::InitializeVM();
2087 ZoneTests().HTypeFromType(); 2078 ZoneTests().HTypeFromType();
2088 HeapTests().HTypeFromType(); 2079 HeapTests().HTypeFromType();
2089 } 2080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698