chromium/third_party/dawn/src/tint/lang/core/constant/eval_binary_op_test.cc

// Copyright 2022 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/core/constant/eval_test.h"

#include "src/tint/lang/wgsl/builtin_fn.h"
#include "src/tint/utils/result/result.h"

#if TINT_BUILD_WGSL_READER
#include "src/tint/lang/wgsl/reader/reader.h"
#endif

usingnamespacetint::core::fluent_types;     // NOLINT
usingnamespacetint::core::number_suffixes;  // NOLINT
HasSubstr;

namespace tint::core::constant::test {
namespace {

struct Case {};

struct ErrorCase {};

/// Creates a Case with Values of any type
Case C(Value lhs, Value rhs, Value expected) {}

/// Convenience overload that creates a Case with just scalars
template <typename T, typename U, typename V, typename = std::enable_if_t<!IsValue<T>>>
Case C(T lhs, U rhs, V expected) {}

/// Creates an failure Case with Values of any type
Case E(Value lhs, Value rhs, std::string error) {}

/// Convenience overload that creates an error Case with just scalars
template <typename T, typename U, typename = std::enable_if_t<!IsValue<T>>>
Case E(T lhs, U rhs, std::string error) {}

/// Prints Case to ostream
static std::ostream& operator<<(std::ostream& o, const Case& c) {}

/// Prints ErrorCase to ostream
std::ostream& operator<<(std::ostream& o, const ErrorCase& c) {}

ConstEvalBinaryOpTest;
TEST_P(ConstEvalBinaryOpTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> OpAddIntCases() {}
template <typename T>
std::vector<Case> OpAddFloatCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> OpSubIntCases() {}
template <typename T>
std::vector<Case> OpSubFloatCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> OpMulScalarCases() {}

template <typename T>
std::vector<Case> OpMulVecCases() {}

template <typename T>
std::vector<Case> OpMulMatCases() {}

INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> OpDivIntCases() {}

template <typename T>
std::vector<Case> OpDivFloatCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> OpModCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T, bool equals>
std::vector<Case> OpEqualCases() {}
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

template <typename T, bool less_than>
std::vector<Case> OpLessThanCases() {}
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

template <typename T, bool greater_than>
std::vector<Case> OpGreaterThanCases() {}
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

// Test that we can compare the maximum and minimum AFloat values in vectors (crbug.com/tint/1999).
struct AbstractFloatVectorCompareCase {};
ConstEvalBinaryOpAbstractFloatVectorCompareTest;
TEST_P(ConstEvalBinaryOpAbstractFloatVectorCompareTest, Test) {}
INSTANTIATE_TEST_SUITE_P();

static std::vector<Case> OpLogicalAndCases() {}
INSTANTIATE_TEST_SUITE_P();

static std::vector<Case> OpLogicalOrCases() {}
INSTANTIATE_TEST_SUITE_P();

static std::vector<Case> OpAndBoolCases() {}
template <typename T>
std::vector<Case> OpAndIntCases() {}
INSTANTIATE_TEST_SUITE_P();

static std::vector<Case> OpOrBoolCases() {}
template <typename T>
std::vector<Case> OpOrIntCases() {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(ConstEvalTest, NotAndOrOfVecs) {}

template <typename T>
std::vector<Case> XorCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> ShiftLeftCases() {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(ConstEvalTest, BinaryAbstractAddOverflow_AInt) {}

TEST_F(ConstEvalTest, BinaryAbstractAddUnderflow_AInt) {}

TEST_F(ConstEvalTest, BinaryAbstractAddOverflow_AFloat) {}

TEST_F(ConstEvalTest, BinaryAbstractAddUnderflow_AFloat) {}

// Mixed AInt and AFloat args to test implicit conversion to AFloat
INSTANTIATE_TEST_SUITE_P();

// AInt left shift negative value -> error
TEST_F(ConstEvalTest, BinaryAbstractShiftLeftByNegativeValue_Error) {}

// AInt left shift by AInt or u32 always results in an AInt
TEST_F(ConstEvalTest, BinaryAbstractShiftLeftRemainsAbstract) {}

// i32/u32 left shift by >= 32 -> error
ConstEvalShiftLeftConcreteGeqBitWidthError;
TEST_P(ConstEvalShiftLeftConcreteGeqBitWidthError, Test) {}
INSTANTIATE_TEST_SUITE_P();

// AInt left shift results in sign change error
ConstEvalShiftLeftSignChangeError;
TEST_P(ConstEvalShiftLeftSignChangeError, Test) {}
template <typename T>
std::vector<ErrorCase> ShiftLeftSignChangeErrorCases() {}
INSTANTIATE_TEST_SUITE_P();

template <typename T>
std::vector<Case> ShiftRightCases() {}
INSTANTIATE_TEST_SUITE_P();

namespace LogicalShortCircuit {

/// Validates that `binary` is a short-circuiting logical and expression
static void ValidateAnd(const sem::Info& sem, const ast::BinaryExpression* binary) {}

/// Validates that `binary` is a short-circuiting logical or expression
static void ValidateOr(const sem::Info& sem, const ast::BinaryExpression* binary) {}

// Naming convention for tests below:
//
// [Non]ShortCircuit_[And|Or]_[Error|Invalid]_<Op>
//
// Where:
//  ShortCircuit: the rhs will not be const-evaluated
//  NonShortCircuitL the rhs will be const-evaluated
//
//  And/Or: type of binary expression
//
//  Error: a non-const evaluation error (e.g. parser or validation error)
//  Invalid: a const-evaluation error
//
// <Op> the type of operation on the rhs that may or may not be short-circuited.

////////////////////////////////////////////////
// Short-Circuit Unary
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid unary op as const eval of unary does not
// fail.

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Unary) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Unary) {}

////////////////////////////////////////////////
// Short-Circuit Binary
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_Invalid_Binary) {}

TEST_F(ConstEvalTest, NonShortCircuit_And_Invalid_Binary) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Binary) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Invalid_Binary) {}

TEST_F(ConstEvalTest, NonShortCircuit_Or_Invalid_Binary) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Binary) {}

////////////////////////////////////////////////
// Short-Circuit Materialize
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_Invalid_Materialize) {}

TEST_F(ConstEvalTest, NonShortCircuit_And_Invalid_Materialize) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Materialize) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Invalid_Materialize) {}

TEST_F(ConstEvalTest, NonShortCircuit_Or_Invalid_Materialize) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Materialize) {}

////////////////////////////////////////////////
// Short-Circuit Index
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_Invalid_Index) {}

TEST_F(ConstEvalTest, NonShortCircuit_And_Invalid_Index) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Index) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Invalid_Index) {}

TEST_F(ConstEvalTest, NonShortCircuit_Or_Invalid_Index) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Index) {}

////////////////////////////////////////////////
// Short-Circuit Bitcast
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_Invalid_Bitcast) {}

TEST_F(ConstEvalTest, NonShortCircuit_And_Invalid_Bitcast) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Bitcast) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Invalid_Bitcast) {}

TEST_F(ConstEvalTest, NonShortCircuit_Or_Invalid_Bitcast) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Bitcast) {}

////////////////////////////////////////////////
// Short-Circuit value construction / conversion
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid init/convert as const eval of init/convert
// always succeeds.

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Init) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Init) {}

////////////////////////////////////////////////
// Short-Circuit Array/Struct Init
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid array/struct init as const eval of
// array/struct init always succeeds.

TEST_F(ConstEvalTest, ShortCircuit_And_Error_StructInit) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_StructInit) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_ArrayInit) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_ArrayInit) {}

////////////////////////////////////////////////
// Short-Circuit Builtin Call
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_Invalid_BuiltinCall) {}

TEST_F(ConstEvalTest, NonShortCircuit_And_Invalid_BuiltinCall) {}

TEST_F(ConstEvalTest, ShortCircuit_And_Error_BuiltinCall) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Invalid_BuiltinCall) {}

TEST_F(ConstEvalTest, NonShortCircuit_Or_Invalid_BuiltinCall) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_BuiltinCall) {}

////////////////////////////////////////////////
// Short-Circuit Literal
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid literal as const eval of a literal does not
// fail.

#if TINT_BUILD_WGSL_READER
TEST_F(ConstEvalTest, ShortCircuit_And_Error_Literal) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Literal) {}
#endif  // TINT_BUILD_WGSL_READER

////////////////////////////////////////////////
// Short-Circuit Member Access
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid member access as const eval of member access
// always succeeds.

TEST_F(ConstEvalTest, ShortCircuit_And_Error_MemberAccess) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_MemberAccess) {}

////////////////////////////////////////////////
// Short-Circuit with RHS Variable Access
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_RHSConstDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_RHSConstDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_And_RHSLetDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_RHSLetDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_And_RHSVarDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_RHSVarDecl) {}

TEST_F(ConstEvalTest, ShortCircuit_And_RHSRuntimeBuiltin) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_RHSRuntimeBuiltin) {}

////////////////////////////////////////////////
// Short-Circuit Swizzle
////////////////////////////////////////////////

// NOTE: Cannot demonstrate short-circuiting an invalid swizzle as const eval of swizzle always
// succeeds.

TEST_F(ConstEvalTest, ShortCircuit_And_Error_Swizzle) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_Error_Swizzle) {}

////////////////////////////////////////////////
// Short-Circuit Mixed Constant and Runtime
////////////////////////////////////////////////

TEST_F(ConstEvalTest, ShortCircuit_And_MixedConstantAndRuntime) {}

TEST_F(ConstEvalTest, ShortCircuit_Or_MixedConstantAndRuntime) {}

////////////////////////////////////////////////
// Short-Circuit Nested
////////////////////////////////////////////////

#if TINT_BUILD_WGSL_READER
ConstEvalTestShortCircuit;
TEST_P(ConstEvalTestShortCircuit, Test) {}
INSTANTIATE_TEST_SUITE_P();
#endif  // TINT_BUILD_WGSL_READER

}  // namespace LogicalShortCircuit

}  // namespace
}  // namespace tint::core::constant::test