Commit ca70df51 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-types to unittests/compiler/types-unittest

Bug: v8:12781
Change-Id: I01416a638abbb0f2c590f806869c00356b0fcba5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3675732Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80802}
parent d1fbcecc
...@@ -239,7 +239,6 @@ v8_source_set("cctest_sources") { ...@@ -239,7 +239,6 @@ v8_source_set("cctest_sources") {
"test-transitions.cc", "test-transitions.cc",
"test-transitions.h", "test-transitions.h",
"test-typedarrays.cc", "test-typedarrays.cc",
"test-types.cc",
"test-unscopables-hidden-prototype.cc", "test-unscopables-hidden-prototype.cc",
"test-unwinder-code-pages.cc", "test-unwinder-code-pages.cc",
"test-usecounters.cc", "test-usecounters.cc",
......
...@@ -63,9 +63,6 @@ ...@@ -63,9 +63,6 @@
# are actually 13 * 38 * 5 * 128 = 316160 individual tests hidden here. # are actually 13 * 38 * 5 * 128 = 316160 individual tests hidden here.
'test-parsing/ParserSync': [PASS, NO_VARIANTS], 'test-parsing/ParserSync': [PASS, NO_VARIANTS],
# This tests only the type system, no point in running several variants.
'test-types/*': [PASS, NO_VARIANTS],
# This tests API threading, no point in running several variants. # This tests API threading, no point in running several variants.
'test-api/Threading*': [PASS, SLOW, NO_VARIANTS], 'test-api/Threading*': [PASS, SLOW, NO_VARIANTS],
......
...@@ -321,6 +321,7 @@ v8_source_set("unittests_sources") { ...@@ -321,6 +321,7 @@ v8_source_set("unittests_sources") {
"compiler/state-values-utils-unittest.cc", "compiler/state-values-utils-unittest.cc",
"compiler/typed-optimization-unittest.cc", "compiler/typed-optimization-unittest.cc",
"compiler/typer-unittest.cc", "compiler/typer-unittest.cc",
"compiler/types-unittest.cc",
"compiler/value-numbering-reducer-unittest.cc", "compiler/value-numbering-reducer-unittest.cc",
"compiler/zone-stats-unittest.cc", "compiler/zone-stats-unittest.cc",
"date/date-cache-unittest.cc", "date/date-cache-unittest.cc",
......
...@@ -2,16 +2,18 @@ ...@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/types.h"
#include <vector> #include <vector>
#include "src/base/strings.h" #include "src/base/strings.h"
#include "src/compiler/types.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/heap/factory-inl.h" #include "src/heap/factory-inl.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/objects/objects.h" #include "src/objects/objects.h"
#include "test/cctest/cctest.h"
#include "test/common/types-fuzz.h" #include "test/common/types-fuzz.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -21,29 +23,23 @@ namespace { ...@@ -21,29 +23,23 @@ namespace {
// Testing auxiliaries (breaking the Type abstraction). // Testing auxiliaries (breaking the Type abstraction).
static bool IsInteger(double x) { static bool IsInteger(double x) {
return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities.
} }
using bitset = Type::bitset; using bitset = Type::bitset;
struct Tests { class TypesTest : public TestWithNativeContextAndZone {
public:
using TypeIterator = Types::TypeVector::iterator; using TypeIterator = Types::TypeVector::iterator;
using ValueIterator = Types::ValueVector::iterator; using ValueIterator = Types::ValueVector::iterator;
Isolate* isolate;
HandleScope tests_scope;
CanonicalHandleScope canonical; CanonicalHandleScope canonical;
Zone zone;
Types T; Types T;
Tests() TypesTest()
: isolate(CcTest::InitIsolateOnce()), : TestWithNativeContextAndZone(),
tests_scope(isolate), canonical(isolate()),
canonical(isolate), T(zone(), isolate(), isolate()->random_number_generator()) {}
zone(isolate->allocator(), ZONE_NAME),
T(&zone, isolate, isolate->random_number_generator()) {}
bool IsBitset(Type type) { return type.IsBitset(); } bool IsBitset(Type type) { return type.IsBitset(); }
bool IsUnion(Type type) { return type.IsUnionForTesting(); } bool IsUnion(Type type) { return type.IsUnionForTesting(); }
...@@ -75,8 +71,8 @@ struct Tests { ...@@ -75,8 +71,8 @@ struct Tests {
void CheckSubOrEqual(Type type1, Type type2) { void CheckSubOrEqual(Type type1, Type type2) {
CHECK(type1.Is(type2)); CHECK(type1.Is(type2));
if (this->IsBitset(type1) && this->IsBitset(type2)) { if (this->IsBitset(type1) && this->IsBitset(type2)) {
CHECK((this->AsBitset(type1) | this->AsBitset(type2)) CHECK((this->AsBitset(type1) | this->AsBitset(type2)) ==
== this->AsBitset(type2)); this->AsBitset(type2));
} }
} }
...@@ -156,8 +152,7 @@ struct Tests { ...@@ -156,8 +152,7 @@ struct Tests {
Type type2 = *it2; Type type2 = *it2;
Type union12 = T.Union(type1, type2); Type union12 = T.Union(type1, type2);
if (this->IsBitset(type1) && this->IsBitset(type2)) { if (this->IsBitset(type1) && this->IsBitset(type2)) {
CHECK( CHECK((this->AsBitset(type1) | this->AsBitset(type2)) ==
(this->AsBitset(type1) | this->AsBitset(type2)) ==
this->AsBitset(union12)); this->AsBitset(union12));
} }
} }
...@@ -226,7 +221,7 @@ struct Tests { ...@@ -226,7 +221,7 @@ struct Tests {
} }
// Typing of numbers // Typing of numbers
Factory* fac = isolate->factory(); Factory* fac = isolate()->factory();
CHECK(T.Constant(fac->NewNumber(0)).Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0)).Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(1)).Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(1)).Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(42)).Equals(T.Range(42, 42))); CHECK(T.Constant(fac->NewNumber(42)).Equals(T.Range(42, 42)));
...@@ -319,14 +314,11 @@ struct Tests { ...@@ -319,14 +314,11 @@ struct Tests {
// Functionality & Injectivity: // Functionality & Injectivity:
// Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2
for (ValueIterator i1 = T.integers.begin(); for (ValueIterator i1 = T.integers.begin(); i1 != T.integers.end(); ++i1) {
i1 != T.integers.end(); ++i1) { for (ValueIterator j1 = i1; j1 != T.integers.end(); ++j1) {
for (ValueIterator j1 = i1; for (ValueIterator i2 = T.integers.begin(); i2 != T.integers.end();
j1 != T.integers.end(); ++j1) { ++i2) {
for (ValueIterator i2 = T.integers.begin(); for (ValueIterator j2 = i2; j2 != T.integers.end(); ++j2) {
i2 != T.integers.end(); ++i2) {
for (ValueIterator j2 = i2;
j2 != T.integers.end(); ++j2) {
double min1 = (*i1)->Number(); double min1 = (*i1)->Number();
double max1 = (*j1)->Number(); double max1 = (*j1)->Number();
double min2 = (*i2)->Number(); double min2 = (*i2)->Number();
...@@ -529,14 +521,11 @@ struct Tests { ...@@ -529,14 +521,11 @@ struct Tests {
void Is2() { void Is2() {
// Range(X1, Y1).Is(Range(X2, Y2)) iff X1 >= X2 /\ Y1 <= Y2 // Range(X1, Y1).Is(Range(X2, Y2)) iff X1 >= X2 /\ Y1 <= Y2
for (ValueIterator i1 = T.integers.begin(); for (ValueIterator i1 = T.integers.begin(); i1 != T.integers.end(); ++i1) {
i1 != T.integers.end(); ++i1) { for (ValueIterator j1 = i1; j1 != T.integers.end(); ++j1) {
for (ValueIterator j1 = i1; for (ValueIterator i2 = T.integers.begin(); i2 != T.integers.end();
j1 != T.integers.end(); ++j1) { ++i2) {
for (ValueIterator i2 = T.integers.begin(); for (ValueIterator j2 = i2; j2 != T.integers.end(); ++j2) {
i2 != T.integers.end(); ++i2) {
for (ValueIterator j2 = i2;
j2 != T.integers.end(); ++j2) {
double min1 = (*i1)->Number(); double min1 = (*i1)->Number();
double max1 = (*j1)->Number(); double max1 = (*j1)->Number();
double min2 = (*i2)->Number(); double min2 = (*i2)->Number();
...@@ -585,7 +574,6 @@ struct Tests { ...@@ -585,7 +574,6 @@ struct Tests {
} }
} }
// Subtyping between concrete basic types // Subtyping between concrete basic types
CheckUnordered(T.Boolean, T.Null); CheckUnordered(T.Boolean, T.Null);
...@@ -869,7 +857,7 @@ struct Tests { ...@@ -869,7 +857,7 @@ struct Tests {
void Union3() { void Union3() {
// Monotonicity: T1.Is(T2) or T1.Is(T3) implies T1.Is(Union(T2, T3)) // Monotonicity: T1.Is(T2) or T1.Is(T3) implies T1.Is(Union(T2, T3))
for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
HandleScope scope(isolate); HandleScope scope(isolate());
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) { for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) {
Type type1 = *it1; Type type1 = *it1;
...@@ -887,32 +875,27 @@ struct Tests { ...@@ -887,32 +875,27 @@ struct Tests {
CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object);
CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.OtherObject); CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.OtherObject);
CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.OtherObject); CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.OtherObject);
CheckDisjoint( CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number);
T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number);
// Bitset-constant // Bitset-constant
CheckSub( CheckSub(T.Union(T.ObjectConstant1, T.Signed32),
T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); T.Union(T.Object, T.Number));
CheckSub(T.Union(T.ObjectConstant1, T.OtherObject), T.Object); CheckSub(T.Union(T.ObjectConstant1, T.OtherObject), T.Object);
CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.OtherObject); CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.OtherObject);
CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object);
CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number);
// Constant-union // Constant-union
CheckEqual( CheckEqual(T.Union(T.ObjectConstant1,
T.Union( T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
CheckEqual( CheckEqual(
T.Union( T.Union(T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1),
T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1), T.Union(T.ObjectConstant2,
T.Union( T.Union(T.ArrayConstant, T.ObjectConstant1)));
T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1)));
// Union-union // Union-union
CheckEqual( CheckEqual(T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Union(
T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Union(T.ObjectConstant1, T.ObjectConstant2)), T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
} }
...@@ -962,7 +945,7 @@ struct Tests { ...@@ -962,7 +945,7 @@ struct Tests {
// Monotonicity: T1.Is(T2) and T1.Is(T3) implies T1.Is(Intersect(T2, T3)) // Monotonicity: T1.Is(T2) and T1.Is(T3) implies T1.Is(Intersect(T2, T3))
for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
HandleScope scope(isolate); HandleScope scope(isolate());
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
Type type1 = *it1; Type type1 = *it1;
...@@ -975,18 +958,14 @@ struct Tests { ...@@ -975,18 +958,14 @@ struct Tests {
} }
// Constant-union // Constant-union
CheckEqual( CheckEqual(T.Intersect(T.ObjectConstant1,
T.Intersect( T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.ObjectConstant1); T.ObjectConstant1);
CheckEqual( CheckEqual(T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
T.SmiConstant); T.SmiConstant);
// Union-union // Union-union
CheckEqual( CheckEqual(T.Intersect(T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Intersect(
T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Union(T.ObjectConstant1, T.ObjectConstant2)), T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
} }
...@@ -1055,23 +1034,23 @@ struct Tests { ...@@ -1055,23 +1034,23 @@ struct Tests {
} // namespace } // namespace
TEST(IsSomeType) { Tests().IsSomeType(); } TEST_F(TypesTest, IsSomeType) { IsSomeType(); }
TEST(BitsetType) { Tests().Bitset(); } TEST_F(TypesTest, BitsetType) { Bitset(); }
TEST(ConstantType) { Tests().Constant(); } TEST_F(TypesTest, ConstantType) { Constant(); }
TEST(RangeType) { Tests().Range(); } TEST_F(TypesTest, RangeType) { Range(); }
TEST(MinMax) { Tests().MinMax(); } TEST_F(TypesTest, MinMax) { MinMax(); }
TEST(BitsetGlb) { Tests().BitsetGlb(); } TEST_F(TypesTest, BitsetGlb) { BitsetGlb(); }
TEST(BitsetLub) { Tests().BitsetLub(); } TEST_F(TypesTest, BitsetLub) { BitsetLub(); }
TEST(Is1) { Tests().Is1(); } TEST_F(TypesTest, Is1) { Is1(); }
TEST(Is2) { Tests().Is2(); } TEST_F(TypesTest, Is2) { Is2(); }
TEST(Maybe) { Tests().Maybe(); } TEST_F(TypesTest, Maybe) { Maybe(); }
TEST(Union1) { Tests().Union1(); } TEST_F(TypesTest, Union1) { Union1(); }
TEST(Union2) { Tests().Union2(); } TEST_F(TypesTest, Union2) { Union2(); }
TEST(Union3) { Tests().Union3(); } TEST_F(TypesTest, Union3) { Union3(); }
TEST(Union4) { Tests().Union4(); } TEST_F(TypesTest, Union4) { Union4(); }
TEST(Intersect) { Tests().Intersect(); } TEST_F(TypesTest, Intersect) { Intersect(); }
TEST(Distributivity) { Tests().Distributivity(); } TEST_F(TypesTest, Distributivity) { Distributivity(); }
TEST(GetRange) { Tests().GetRange(); } TEST_F(TypesTest, GetRange) { GetRange(); }
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
[ALWAYS, { [ALWAYS, {
# BUG(5193). The cpu profiler tests are notoriously flaky. # BUG(5193). The cpu profiler tests are notoriously flaky.
'SamplerTest.LibSamplerCollectSample': [SKIP], 'SamplerTest.LibSamplerCollectSample': [SKIP],
# This tests only the type system, no point in running several variants.
'TypesTest.*': [PASS, NO_VARIANTS],
}], # ALWAYS }], # ALWAYS
############################################################################## ##############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment