chromium/third_party/dawn/src/tint/lang/wgsl/resolver/materialize_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/wgsl/sem/materialize.h"

#include "src/tint/lang/core/type/helper_test.h"
#include "src/tint/lang/wgsl/resolver/resolver.h"
#include "src/tint/lang/wgsl/resolver/resolver_helper_test.h"
#include "src/tint/lang/wgsl/sem/array.h"
#include "src/tint/utils/rtti/switch.h"

#include "gmock/gmock.h"

namespace tint::resolver {
namespace {

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

AFloatV;
AFloatM;
AFloatA;
AIntV;
AIntA;
f32V;
f16V;
i32V;
u32V;
f32M;
f16M;
f32A;
f16A;
i32A;
u32A;

constexpr double kTooBigF32 =;
constexpr double kTooBigF16 =;
constexpr double kPiF64 =;
constexpr double kPiF32 =;  // kPiF64 quantized to f32
constexpr double kPiF16 =;            // kPiF64 quantized to f16

constexpr double kSubnormalF32 =;
constexpr double kSubnormalF16 =;

enum class Expectation {};

static std::ostream& operator<<(std::ostream& o, Expectation m) {}

template <typename CASE>
class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {};

////////////////////////////////////////////////////////////////////////////////////////////////////
// MaterializeAbstractNumericToConcreteType
// Tests that an abstract-numeric will materialize to the expected concrete type
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace materialize_abstract_numeric_to_concrete_type {
// How should the materialization occur?
enum class Method {};

static std::ostream& operator<<(std::ostream& o, Method m) {}

struct Data {};

template <typename TARGET_TYPE, typename ABSTRACT_TYPE, typename MATERIALIZED_TYPE>
Data Types(MATERIALIZED_TYPE materialized_value, double literal_value) {}

template <typename TARGET_TYPE, typename ABSTRACT_TYPE>
Data Types() {}

static std::ostream& operator<<(std::ostream& o, const Data& c) {}

MaterializeAbstractNumericToConcreteType;

TEST_P(MaterializeAbstractNumericToConcreteType, Test) {}

/// Methods that support scalar materialization
constexpr Method kScalarMethods[] =;

/// Methods that support vector materialization
constexpr Method kVectorMethods[] =;

/// Methods that support matrix materialization
constexpr Method kMatrixMethods[] =;

/// Methods that support array materialization
constexpr Method kArrayMethods[] =;

/// Methods that support materialization for switch cases
constexpr Method kSwitchMethods[] =;

/// Methods that do not materialize
constexpr Method kNoMaterializeMethods[] =;

/// Methods that do not materialize
constexpr Method kNoMaterializeScalarVectorMethods[] =;
INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

}  // namespace materialize_abstract_numeric_to_concrete_type

////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests that in the absence of a 'target type' an abstract-int will materialize to i32, and an
// abstract-float will materialize to f32.
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace materialize_abstract_numeric_to_default_type {

// How should the materialization occur?
enum class Method {};

static std::ostream& operator<<(std::ostream& o, Method m) {}

struct Data {};

template <typename EXPECTED_TYPE, typename ABSTRACT_TYPE, typename MATERIALIZED_TYPE>
Data Types(MATERIALIZED_TYPE materialized_value, double literal_value) {}

static std::ostream& operator<<(std::ostream& o, const Data& c) {}

MaterializeAbstractNumericToDefaultType;

TEST_P(MaterializeAbstractNumericToDefaultType, Test) {}

/// Methods that support scalar materialization
constexpr Method kScalarMethods[] =;

/// Methods that support vector materialization
constexpr Method kVectorMethods[] =;

/// Methods that support matrix materialization
constexpr Method kMatrixMethods[] =;

/// Methods that support array materialization
constexpr Method kArrayMethods[] =;

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

}  // namespace materialize_abstract_numeric_to_default_type

namespace materialize_abstract_numeric_to_unrelated_type {

MaterializeAbstractNumericToUnrelatedType;

TEST_F(MaterializeAbstractNumericToUnrelatedType, AIntToStructVarInit) {}

TEST_F(MaterializeAbstractNumericToUnrelatedType, AIntToStructLetInit) {}

}  // namespace materialize_abstract_numeric_to_unrelated_type

////////////////////////////////////////////////////////////////////////////////
// Materialization tests for builtin-returned abstract structures
// These are too bespoke to slot into the more general materialization tests above
////////////////////////////////////////////////////////////////////////////////
namespace materialize_abstract_structure {

MaterializeAbstractStructure;

TEST_F(MaterializeAbstractStructure, Modf_Scalar_DefaultType) {}

TEST_F(MaterializeAbstractStructure, Modf_Vector_DefaultType) {}

TEST_F(MaterializeAbstractStructure, Modf_Scalar_ExplicitType) {}

TEST_F(MaterializeAbstractStructure, Modf_Vector_ExplicitType) {}

TEST_F(MaterializeAbstractStructure, Frexp_Scalar_DefaultType) {}

TEST_F(MaterializeAbstractStructure, Frexp_Vector_DefaultType) {}

TEST_F(MaterializeAbstractStructure, Frexp_Scalar_ExplicitType) {}

TEST_F(MaterializeAbstractStructure, Frexp_Vector_ExplicitType) {}

}  // namespace materialize_abstract_structure

}  // namespace
}  // namespace tint::resolver