Chromium Code Reviews

Unified Diff: test/cctest/compiler/test-typer.cc

Issue 653093002: Test monotonicity of expression typings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: test/cctest/compiler/test-typer.cc
diff --git a/test/cctest/compiler/test-typer.cc b/test/cctest/compiler/test-typer.cc
index 0c9438a9ddb831206a0fcdc7107cc6644a74a1e4..f3136288b305c07a7799f07711903e5a752edbb0 100644
--- a/test/cctest/compiler/test-typer.cc
+++ b/test/cctest/compiler/test-typer.cc
@@ -2,20 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
-// This tests the correctness of the typer.
-//
-// For simplicity, it currently only tests it on expression operators that have
-// a direct equivalent in C++. Also, testing is currently limited to ranges as
-// input types.
-
-
#include <functional>
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/typer.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/graph-builder-tester.h"
+#include "test/cctest/test-types.h"
using namespace v8::internal;
using namespace v8::internal::compiler;
@@ -26,6 +19,7 @@ class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
public:
TyperTester()
: GraphAndBuilders(main_zone()),
+ types_(main_zone(), isolate()),
typer_(main_zone()),
javascript_(main_zone()) {
Node* s = graph()->NewNode(common()->Start(3));
@@ -57,6 +51,7 @@ class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
}
}
+ Types<Type, Type*, Zone> types_;
Typer typer_;
JSOperatorBuilder javascript_;
Node* context_node_;
@@ -161,6 +156,26 @@ class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
CHECK(result_type->Is(expected_type));
}
}
+
+ Type* RandomSubtype(Type* type) {
+ Type* subtype;
+ do {
+ subtype = types_.Fuzz();
+ } while (!subtype->Is(type));
+ return subtype;
+ }
+
+ void TestBinaryMonotonicity(const Operator* op) {
+ for (int i = 0; i < 50; ++i) {
+ Type* type1 = types_.Fuzz();
+ Type* type2 = types_.Fuzz();
+ Type* type = TypeBinaryOp(op, type1, type2);
+ Type* subtype1 = RandomSubtype(type1);;
+ Type* subtype2 = RandomSubtype(type2);;
+ Type* subtype = TypeBinaryOp(op, subtype1, subtype2);
+ CHECK(subtype->Is(type));
+ }
+ }
};
@@ -171,6 +186,13 @@ static int32_t bit_and(int32_t x, int32_t y) { return x & y; }
static int32_t bit_xor(int32_t x, int32_t y) { return x ^ y; }
+//------------------------------------------------------------------------------
+// Soundness
+// For simplicity, we currently only test soundness on expression operators
+// that have a direct equivalent in C++. Also, testing is currently limited
+// to ranges as input types.
+
+
TEST(TypeJSAdd) {
TyperTester t;
t.TestBinaryArithOp(t.javascript_.Subtract(), std::plus<double>());
@@ -275,3 +297,16 @@ TEST(TypeJSStrictNotEqual) {
t.TestBinaryCompareOp(
t.javascript_.StrictNotEqual(), std::not_equal_to<double>());
}
+
+
+//------------------------------------------------------------------------------
+// Monotonicity
+
+
+TEST(Monotonicity) {
+ TyperTester t;
+ #define TEST_TYPE(name, x, y, z) \
+ t.TestBinaryMonotonicity(t.javascript_.name());
+ SHARED_SIMPLE_BINOP_LIST(TEST_TYPE)
+ #undef TEST_TYPE
+}

Powered by Google App Engine