From 055900549456dc9e88486011108a8fc23383d75b Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 19 Apr 2023 16:52:46 +0000 Subject: [PATCH] Move traits into utils. This CL moves the tint/traits file into tint/utils/traits. Traits is one of the few items not in utils which is referred to by utils. Change-Id: Ie955398f24e949b7618fdc868dbcb903fe20b3f1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127400 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Dan Sinclair --- src/tint/BUILD.gn | 4 +- src/tint/CMakeLists.txt | 4 +- src/tint/ast/module.h | 2 +- src/tint/ast/test_helper.h | 2 +- src/tint/ast/traverse_expressions.h | 5 +- src/tint/castable.h | 16 ++-- src/tint/clone_context.h | 15 ++-- src/tint/ir/builder.h | 3 +- src/tint/number.h | 26 +++--- src/tint/program_builder.h | 103 ++++++++++++----------- src/tint/reflection.h | 3 +- src/tint/resolver/const_eval.cc | 3 +- src/tint/resolver/resolver_test_helper.h | 8 +- src/tint/sem/info.h | 2 +- src/tint/switch.h | 7 +- src/tint/type/manager.h | 6 +- src/tint/utils/slice.h | 6 +- src/tint/{ => utils}/traits.h | 10 +-- src/tint/{ => utils}/traits_test.cc | 6 +- src/tint/utils/transform.h | 2 +- 20 files changed, 128 insertions(+), 105 deletions(-) rename src/tint/{ => utils}/traits.h (97%) rename src/tint/{ => utils}/traits_test.cc (99%) diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 5240dd2ebc..f20948d61a 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -218,7 +218,6 @@ libtint_source_set("libtint_base_src") { "symbol.h", "symbol_table.cc", "symbol_table.h", - "traits.h", "utils/bitcast.h", "utils/bitset.h", "utils/block_allocator.h", @@ -243,6 +242,7 @@ libtint_source_set("libtint_base_src") { "utils/string.h", "utils/string_stream.cc", "utils/string_stream.h", + "utils/traits.h", "utils/unique_allocator.h", "utils/unique_vector.h", "utils/vector.h", @@ -1606,6 +1606,7 @@ if (tint_build_unittests) { "utils/slice_test.cc", "utils/string_stream_test.cc", "utils/string_test.cc", + "utils/traits_test.cc", "utils/transform_test.cc", "utils/unique_allocator_test.cc", "utils/unique_vector_test.cc", @@ -1990,7 +1991,6 @@ if (tint_build_unittests) { "switch_test.cc", "symbol_table_test.cc", "symbol_test.cc", - "traits_test.cc", ] deps = [ ":libtint_base_src" ] } diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 7b595fdf3f..820366a7f0 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -348,7 +348,6 @@ list(APPEND TINT_LIB_SRCS symbol.cc symbol.h tint.cc - traits.h transform/add_empty_entry_point.cc transform/add_empty_entry_point.h transform/add_block_attribute.cc @@ -535,6 +534,7 @@ list(APPEND TINT_LIB_SRCS utils/string.h utils/string_stream.cc utils/string_stream.h + utils/traits.h utils/unique_allocator.h utils/unique_vector.h utils/vector.h @@ -969,7 +969,6 @@ if(TINT_BUILD_TESTS) symbol_test.cc test_main.cc text/unicode_test.cc - traits_test.cc transform/transform_test.cc type/array_test.cc type/atomic_test.cc @@ -1013,6 +1012,7 @@ if(TINT_BUILD_TESTS) utils/slice_test.cc utils/string_stream_test.cc utils/string_test.cc + utils/traits_test.cc utils/transform_test.cc utils/unique_allocator_test.cc utils/unique_vector_test.cc diff --git a/src/tint/ast/module.h b/src/tint/ast/module.h index 948f894e69..0125fb3fae 100644 --- a/src/tint/ast/module.h +++ b/src/tint/ast/module.h @@ -80,7 +80,7 @@ class Module final : public Castable { auto& GlobalVariables() { return global_variables_; } /// @returns the global variable declarations of kind 'T' for the module - template > + template > auto Globals() const { utils::Vector out; out.Reserve(global_variables_.Length()); diff --git a/src/tint/ast/test_helper.h b/src/tint/ast/test_helper.h index e26c10a76a..6ef328db1a 100644 --- a/src/tint/ast/test_helper.h +++ b/src/tint/ast/test_helper.h @@ -96,7 +96,7 @@ void CheckIdentifier(const Identifier* ident, const TemplatedIdentifierMatcherarguments[arg_idx++]; using T = std::decay_t; - if constexpr (traits::IsStringLike) { + if constexpr (utils::traits::IsStringLike) { ASSERT_TRUE(got_arg->Is()); CheckIdentifier(got_arg->As()->identifier, expected_arg); } else if constexpr (IsTemplatedIdentifierMatcher::value) { diff --git a/src/tint/ast/traverse_expressions.h b/src/tint/ast/traverse_expressions.h index 84a10c3ebc..780de1a419 100644 --- a/src/tint/ast/traverse_expressions.h +++ b/src/tint/ast/traverse_expressions.h @@ -62,8 +62,9 @@ enum class TraverseOrder { /// @return true on success, false on error template bool TraverseExpressions(const Expression* root, diag::List& diags, CALLBACK&& callback) { - using EXPR_TYPE = std::remove_pointer_t>; - constexpr static bool kHasDepthArg = traits::SignatureOfT::parameter_count == 2; + using EXPR_TYPE = std::remove_pointer_t>; + constexpr static bool kHasDepthArg = + utils::traits::SignatureOfT::parameter_count == 2; struct Pending { const Expression* expr; diff --git a/src/tint/castable.h b/src/tint/castable.h index 71e3ab86fc..33d6139679 100644 --- a/src/tint/castable.h +++ b/src/tint/castable.h @@ -20,8 +20,8 @@ #include #include -#include "src/tint/traits.h" #include "src/tint/utils/crc32.h" +#include "src/tint/utils/traits.h" #if defined(__clang__) /// Temporarily disable certain warnings when using Castable API @@ -60,7 +60,7 @@ namespace tint { /// True if all template types that are not Ignore derive from CastableBase template static constexpr bool IsCastable = - ((traits::IsTypeOrDerived || std::is_same_v)&&...) && + ((utils::traits::IsTypeOrDerived || std::is_same_v)&&...) && !(std::is_same_v && ...); /// Helper macro to instantiate the TypeInfo template for `CLASS`. @@ -220,8 +220,8 @@ struct TypeInfo { return HashCodeOf>>(); } else { constexpr auto kMid = kCount / 2; - return CombinedHashCodeOfTuple>() | - CombinedHashCodeOfTuple>(); + return CombinedHashCodeOfTuple>() | + CombinedHashCodeOfTuple>(); } } @@ -245,8 +245,8 @@ struct TypeInfo { // Possibly one of the types in `TUPLE`. // Split the search in two, and scan each block. static constexpr auto kMid = kCount / 2; - return IsAnyOfTuple>() || - IsAnyOfTuple>(); + return IsAnyOfTuple>() || + IsAnyOfTuple>(); } return false; } @@ -442,7 +442,7 @@ class Castable : public BASE { /// object is of, or derives from the class `TO`. template inline bool Is(Pred&& pred) const { - using TO = typename std::remove_pointer>::type; + using TO = typename std::remove_pointer>::type; return tint::Is(static_cast(this), std::forward(pred)); } @@ -512,7 +512,7 @@ struct CastableCommonBaseImpl { template struct CastableCommonBaseImpl { /// The common base class for A, B and OTHERS - using type = std::conditional_t, + using type = std::conditional_t, B, // A derives from B CastableCommonBase>; }; diff --git a/src/tint/clone_context.h b/src/tint/clone_context.h index 8e0e2ff297..901298218a 100644 --- a/src/tint/clone_context.h +++ b/src/tint/clone_context.h @@ -25,10 +25,10 @@ #include "src/tint/debug.h" #include "src/tint/program_id.h" #include "src/tint/symbol.h" -#include "src/tint/traits.h" #include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/hashmap.h" #include "src/tint/utils/hashset.h" +#include "src/tint/utils/traits.h" #include "src/tint/utils/vector.h" // Forward declarations @@ -74,8 +74,8 @@ class CloneContext { /// ParamTypeIsPtrOf is true iff the first parameter of /// F is a pointer of (or derives from) type T. template - static constexpr bool ParamTypeIsPtrOf = - traits::IsTypeOrDerived>::type, T>; + static constexpr bool ParamTypeIsPtrOf = utils::traits:: + IsTypeOrDerived>::type, T>; public: /// SymbolTransform is a function that takes a symbol and returns a new @@ -303,8 +303,9 @@ class CloneContext { /// `T* (T*)`, where `T` derives from Cloneable /// @returns this CloneContext so calls can be chained template - traits::EnableIf, CloneContext>& ReplaceAll(F&& replacer) { - using TPtr = traits::ParameterType; + utils::traits::EnableIf, CloneContext>& ReplaceAll( + F&& replacer) { + using TPtr = utils::traits::ParameterType; using T = typename std::remove_pointer::type; for (auto& transform : transforms_) { bool already_registered = transform.typeinfo->Is(&TypeInfo::Of()) || @@ -355,7 +356,9 @@ class CloneContext { /// references of the original object. A type mismatch will result in an /// assertion in debug builds, and undefined behavior in release builds. /// @returns this CloneContext so calls can be chained - template > + template > CloneContext& Replace(const WHAT* what, const WITH* with) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Clone, src, what); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Clone, dst, with); diff --git a/src/tint/ir/builder.h b/src/tint/ir/builder.h index 5a39dbb6af..b090bdf1d4 100644 --- a/src/tint/ir/builder.h +++ b/src/tint/ir/builder.h @@ -90,7 +90,8 @@ class Builder { /// @param args the arguments /// @returns the new constant value template - traits::EnableIf, const T>* create(ARGS&&... args) { + utils::traits::EnableIf, const T>* create( + ARGS&&... args) { return ir.constants.Create(std::forward(args)...); } diff --git a/src/tint/number.h b/src/tint/number.h index 7bc1eead42..06ab7fd154 100644 --- a/src/tint/number.h +++ b/src/tint/number.h @@ -21,10 +21,10 @@ #include #include -#include "src/tint/traits.h" #include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/result.h" #include "src/tint/utils/string_stream.h" +#include "src/tint/utils/traits.h" // Forward declaration namespace tint { @@ -274,7 +274,7 @@ using f32 = Number; /// However since C++ don't have native binary16 type, the value is stored as float. using f16 = Number; -template >* = nullptr> +template >* = nullptr> inline const auto kPi = T(UnwrapNumber(3.14159265358979323846)); /// True iff T is an abstract number type @@ -282,7 +282,7 @@ template constexpr bool IsAbstract = std::is_same_v || std::is_same_v; /// @returns the friendly name of Number type T -template >* = nullptr> +template >* = nullptr> const char* FriendlyName() { if constexpr (std::is_same_v) { return "abstract-int"; @@ -302,7 +302,7 @@ const char* FriendlyName() { } /// @returns the friendly name of T when T is bool -template >* = nullptr> +template >* = nullptr> const char* FriendlyName() { return "bool"; } @@ -438,7 +438,8 @@ inline std::optional CheckedAdd(AInt a, AInt b) { } /// @returns a + b, or an empty optional if the resulting value overflowed the float value -template >> +template >> inline std::optional CheckedAdd(FloatingPointT a, FloatingPointT b) { auto result = FloatingPointT{a.value + b.value}; if (!std::isfinite(result.value)) { @@ -470,7 +471,8 @@ inline std::optional CheckedSub(AInt a, AInt b) { } /// @returns a + b, or an empty optional if the resulting value overflowed the float value -template >> +template >> inline std::optional CheckedSub(FloatingPointT a, FloatingPointT b) { auto result = FloatingPointT{a.value - b.value}; if (!std::isfinite(result.value)) { @@ -514,7 +516,8 @@ inline std::optional CheckedMul(AInt a, AInt b) { } /// @returns a * b, or an empty optional if the resulting value overflowed the float value -template >> +template >> inline std::optional CheckedMul(FloatingPointT a, FloatingPointT b) { auto result = FloatingPointT{a.value * b.value}; if (!std::isfinite(result.value)) { @@ -537,7 +540,8 @@ inline std::optional CheckedDiv(AInt a, AInt b) { } /// @returns a / b, or an empty optional if the resulting value overflowed the float value -template >> +template >> inline std::optional CheckedDiv(FloatingPointT a, FloatingPointT b) { if (b == FloatingPointT{0.0} || b == FloatingPointT{-0.0}) { return {}; @@ -577,7 +581,8 @@ inline std::optional CheckedMod(AInt a, AInt b) { /// @returns the remainder of a / b, or an empty optional if the resulting value overflowed the /// float value -template >> +template >> inline std::optional CheckedMod(FloatingPointT a, FloatingPointT b) { if (b == FloatingPointT{0.0} || b == FloatingPointT{-0.0}) { return {}; @@ -599,7 +604,8 @@ inline std::optional CheckedMadd(AInt a, AInt b, AInt c) { /// @returns the value of `base` raised to the power `exp`, or an empty optional if the operation /// cannot be performed. -template >> +template >> inline std::optional CheckedPow(FloatingPointT base, FloatingPointT exp) { static_assert(IsNumber); if ((base < 0) || (base == 0 && exp <= 0)) { diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 0c00452c6a..b7fda95bb6 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -170,53 +170,53 @@ class ProgramBuilder { /// Evaluates to true if T can be converted to an identifier. template - static constexpr const bool IsIdentifierLike = std::is_same_v || // Symbol - std::is_enum_v || // Enum - traits::IsStringLike; // String + static constexpr const bool IsIdentifierLike = std::is_same_v || // Symbol + std::is_enum_v || // Enum + utils::traits::IsStringLike; // String /// A helper used to disable overloads if the first type in `TYPES` is a Source. Used to avoid /// ambiguities in overloads that take a Source as the first parameter and those that /// perfectly-forward the first argument. template - using DisableIfSource = - traits::EnableIf>>>; + using DisableIfSource = utils::traits::EnableIf< + !IsSource>>>; /// A helper used to disable overloads if the first type in `TYPES` is a scalar type. Used to /// avoid ambiguities in overloads that take a scalar as the first parameter and those that /// perfectly-forward the first argument. template - using DisableIfScalar = - traits::EnableIf>>>; + using DisableIfScalar = utils::traits::EnableIf< + !IsScalar>>>; /// A helper used to enable overloads if the first type in `TYPES` is a scalar type. Used to /// avoid ambiguities in overloads that take a scalar as the first parameter and those that /// perfectly-forward the first argument. template - using EnableIfScalar = - traits::EnableIf>>>; + using EnableIfScalar = utils::traits::EnableIf< + IsScalar>>>; /// A helper used to disable overloads if the first type in `TYPES` is a utils::Vector, /// utils::VectorRef or utils::VectorRef. template - using DisableIfVectorLike = traits::EnableIf< - !detail::IsVectorLike>>::value>; + using DisableIfVectorLike = utils::traits::EnableIf>>::value>; /// A helper used to enable overloads if the first type in `TYPES` is identifier-like. template - using EnableIfIdentifierLike = - traits::EnableIf>>>; + using EnableIfIdentifierLike = utils::traits::EnableIf< + IsIdentifierLike>>>; /// A helper used to disable overloads if the first type in `TYPES` is Infer or an abstract /// numeric. template - using DisableIfInferOrAbstract = - traits::EnableIf>>>; + using DisableIfInferOrAbstract = utils::traits::EnableIf< + !IsInferOrAbstract>>>; /// A helper used to enable overloads if the first type in `TYPES` is Infer or an abstract /// numeric. template - using EnableIfInferOrAbstract = - traits::EnableIf>>>; + using EnableIfInferOrAbstract = utils::traits::EnableIf< + IsInferOrAbstract>>>; /// VarOptions is a helper for accepting an arbitrary number of order independent options for /// constructing an ast::Var. @@ -258,7 +258,8 @@ class ProgramBuilder { template explicit LetOptions(ARGS&&... args) { static constexpr bool has_init = - (traits::IsTypeOrDerived, ast::Expression> || ...); + (utils::traits::IsTypeOrDerived, ast::Expression> || + ...); static_assert(has_init, "Let() must be constructed with an initializer expression"); (Set(std::forward(args)), ...); } @@ -281,7 +282,8 @@ class ProgramBuilder { template explicit ConstOptions(ARGS&&... args) { static constexpr bool has_init = - (traits::IsTypeOrDerived, ast::Expression> || ...); + (utils::traits::IsTypeOrDerived, ast::Expression> || + ...); static_assert(has_init, "Const() must be constructed with an initializer expression"); (Set(std::forward(args)), ...); } @@ -476,7 +478,7 @@ class ProgramBuilder { /// @param args the arguments to pass to the constructor /// @returns the node pointer template - traits::EnableIfIsType* create(const Source& source, ARGS&&... args) { + utils::traits::EnableIfIsType* create(const Source& source, ARGS&&... args) { AssertNotMoved(); return ast_nodes_.Create(id_, AllocateNodeID(), source, std::forward(args)...); } @@ -488,7 +490,7 @@ class ProgramBuilder { /// destructed. /// @returns the node pointer template - traits::EnableIfIsType* create() { + utils::traits::EnableIfIsType* create() { AssertNotMoved(); return ast_nodes_.Create(id_, AllocateNodeID(), source_); } @@ -502,10 +504,10 @@ class ProgramBuilder { /// @param args the remaining arguments to pass to the constructor /// @returns the node pointer template - traits::EnableIf && - !traits::IsTypeOrDerived, - T>* + utils::traits::EnableIf && + !utils::traits::IsTypeOrDerived, + T>* create(ARG0&& arg0, ARGS&&... args) { AssertNotMoved(); return ast_nodes_.Create(id_, AllocateNodeID(), source_, std::forward(arg0), @@ -517,9 +519,9 @@ class ProgramBuilder { /// @param args the arguments to pass to the constructor /// @returns the node pointer template - traits::EnableIf && - !traits::IsTypeOrDerived, - T>* + utils::traits::EnableIf && + !utils::traits::IsTypeOrDerived, + T>* create(ARGS&&... args) { AssertNotMoved(); return sem_nodes_.Create(std::forward(args)...); @@ -530,10 +532,10 @@ class ProgramBuilder { /// @param args the arguments to pass to the constructor /// @returns the node pointer template - traits::EnableIf && - !traits::IsTypeOrDerived && - !traits::IsTypeOrDerived, - T>* + utils::traits::EnableIf && + !utils::traits::IsTypeOrDerived && + !utils::traits::IsTypeOrDerived, + T>* create(ARGS&&... args) { AssertNotMoved(); return constant_nodes_.Create(std::forward(args)...); @@ -547,9 +549,10 @@ class ProgramBuilder { /// @param type the composite type /// @param elements the composite elements /// @returns the node pointer - template || - traits::IsTypeOrDerived>> + template < + typename T, + typename = utils::traits::EnableIf || + utils::traits::IsTypeOrDerived>> const constant::Value* create(const type::Type* type, utils::VectorRef elements) { AssertNotMoved(); @@ -561,7 +564,9 @@ class ProgramBuilder { /// @param element the splat element /// @param n the number of elements /// @returns the node pointer - template >> + template < + typename T, + typename = utils::traits::EnableIf>> const constant::Splat* create(const type::Type* type, const constant::Value* element, size_t n) { @@ -576,7 +581,7 @@ class ProgramBuilder { /// @param args the arguments to pass to the constructor /// @returns the new, or existing node template - traits::EnableIfIsType* create(ARGS&&... args) { + utils::traits::EnableIfIsType* create(ARGS&&... args) { AssertNotMoved(); return types_.Get(std::forward(args)...); } @@ -615,7 +620,8 @@ class ProgramBuilder { typename = DisableIfSource, typename = std::enable_if_t, ast::Type>>> ast::Type operator()(NAME&& name, ARGS&&... args) const { - if constexpr (traits::IsTypeOrDerived, ast::Expression>) { + if constexpr (utils::traits::IsTypeOrDerived, + ast::Expression>) { static_assert(sizeof...(ARGS) == 0); return {name}; } else { @@ -1479,7 +1485,8 @@ class ProgramBuilder { /// @return an ast::Identifier with the given symbol template const ast::Identifier* Ident(IDENTIFIER&& identifier) { - if constexpr (traits::IsTypeOrDerived, ast::Identifier>) { + if constexpr (utils::traits::IsTypeOrDerived, + ast::Identifier>) { return identifier; // Passthrough } else { return Ident(source_, std::forward(identifier)); @@ -1518,7 +1525,7 @@ class ProgramBuilder { /// @param expr the expression /// @return expr (passthrough) - template > + template > const T* Expr(const T* expr) { return expr; } @@ -2734,8 +2741,9 @@ class ProgramBuilder { const ast::MemberAccessorExpression* MemberAccessor(const Source& source, OBJECT&& object, MEMBER&& member) { - static_assert(!traits::IsType, ast::TemplatedIdentifier>, - "it is currently invalid for a structure to hold a templated member"); + static_assert( + !utils::traits::IsType, ast::TemplatedIdentifier>, + "it is currently invalid for a structure to hold a templated member"); return create(source, Expr(std::forward(object)), Ident(std::forward(member))); } @@ -2882,8 +2890,8 @@ class ProgramBuilder { utils::VectorRef attributes = utils::Empty, utils::VectorRef return_type_attributes = utils::Empty) { const ast::BlockStatement* block = nullptr; - using BODY_T = traits::PtrElTy; - if constexpr (traits::IsTypeOrDerived || + using BODY_T = utils::traits::PtrElTy; + if constexpr (utils::traits::IsTypeOrDerived || std::is_same_v) { block = body; } else { @@ -3753,8 +3761,9 @@ class ProgramBuilder { const ast::DiagnosticAttribute* DiagnosticAttribute(const Source& source, builtin::DiagnosticSeverity severity, NAME&& rule_name) { - static_assert(!traits::IsType, ast::TemplatedIdentifier>, - "it is invalid for a diagnostic rule name to be templated"); + static_assert( + !utils::traits::IsType, ast::TemplatedIdentifier>, + "it is invalid for a diagnostic rule name to be templated"); return create( source, ast::DiagnosticControl(severity, Ident(std::forward(rule_name)))); } @@ -3872,7 +3881,7 @@ class ProgramBuilder { /// @param args a mix of ast::Expression, ast::Statement, ast::Variables. /// @returns the function template ::value && ...)>> + typename = utils::traits::EnableIf<(CanWrapInStatement::value && ...)>> const ast::Function* WrapInFunction(ARGS&&... args) { utils::Vector stmts{ WrapInStatement(std::forward(args))..., diff --git a/src/tint/reflection.h b/src/tint/reflection.h index 05918381ba..d341f98233 100644 --- a/src/tint/reflection.h +++ b/src/tint/reflection.h @@ -15,7 +15,8 @@ #ifndef SRC_TINT_REFLECTION_H_ #define SRC_TINT_REFLECTION_H_ -#include "src/tint/traits.h" +#include + #include "src/tint/utils/concat.h" #include "src/tint/utils/foreach_macro.h" diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index b90ea00a92..2aa755a4d7 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -447,7 +447,8 @@ ConstEval::Result TransformElements(ProgramBuilder& builder, auto* ty = First(cs...)->Type(); auto* el_ty = type::Type::ElementOf(ty, &n); if (el_ty == ty) { - constexpr bool kHasIndexParam = traits::IsType>; + constexpr bool kHasIndexParam = + utils::traits::IsType>; if constexpr (kHasIndexParam) { return f(cs..., index); } else { diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h index ac1b9e7121..c4aec9049a 100644 --- a/src/tint/resolver/resolver_test_helper.h +++ b/src/tint/resolver/resolver_test_helper.h @@ -29,9 +29,9 @@ #include "src/tint/sem/statement.h" #include "src/tint/sem/value_expression.h" #include "src/tint/sem/variable.h" -#include "src/tint/traits.h" #include "src/tint/type/abstract_float.h" #include "src/tint/type/abstract_int.h" +#include "src/tint/utils/traits.h" #include "src/tint/utils/vector.h" namespace tint::resolver { @@ -587,7 +587,7 @@ struct DataType> { /// @param args the value nested elements will be initialized with /// @return a new AST expression of the alias type template - static inline traits::EnableIf Expr( + static inline utils::traits::EnableIf Expr( ProgramBuilder& b, utils::VectorRef args) { // Cast @@ -598,7 +598,7 @@ struct DataType> { /// @param args the value nested elements will be initialized with /// @return a new AST expression of the alias type template - static inline traits::EnableIf Expr( + static inline utils::traits::EnableIf Expr( ProgramBuilder& b, utils::VectorRef args) { // Construct @@ -819,7 +819,7 @@ constexpr bool IsValue = std::is_same_v; /// Creates a Value of DataType from a scalar `v` template Value Val(T v) { - static_assert(traits::IsTypeIn, "v must be a Number of bool"); + static_assert(utils::traits::IsTypeIn, "v must be a Number of bool"); return Value::Create(utils::Vector{v}); } diff --git a/src/tint/sem/info.h b/src/tint/sem/info.h index 29b3bc46b6..be5061833b 100644 --- a/src/tint/sem/info.h +++ b/src/tint/sem/info.h @@ -81,7 +81,7 @@ class Info { typename RESULT = GetResultType> const RESULT* Get(const AST* ast_node) const { static_assert(std::is_same_v || - !traits::IsTypeOrDerived, SEM>, + !utils::traits::IsTypeOrDerived, SEM>, "explicit template argument is unnecessary"); if (ast_node && ast_node->node_id.value < nodes_.size()) { return As(nodes_[ast_node->node_id.value]); diff --git a/src/tint/switch.h b/src/tint/switch.h index 41bb99a741..cd2ccc87d0 100644 --- a/src/tint/switch.h +++ b/src/tint/switch.h @@ -43,13 +43,14 @@ namespace tint::detail { /// @note does not handle the Default case /// @see Switch(). template -using SwitchCaseType = std::remove_pointer_t, 0>>; +using SwitchCaseType = + std::remove_pointer_t, 0>>; /// Evaluates to true if the function `FN` has the signature of a Default case in a Switch(). /// @see Switch(). template inline constexpr bool IsDefaultCase = - std::is_same_v, 0>, Default>; + std::is_same_v, 0>, Default>; /// Searches the list of Switch cases for a Default case, returning the index of the Default case. /// If the a Default case is not found in the tuple, then -1 is returned. @@ -163,7 +164,7 @@ namespace tint { /// consistent case type. template inline auto Switch(T* object, CASES&&... cases) { - using ReturnType = detail::SwitchReturnType...>; + using ReturnType = detail::SwitchReturnType...>; static constexpr int kDefaultIndex = detail::IndexOfDefaultCase>(); static constexpr bool kHasDefaultCase = kDefaultIndex >= 0; static constexpr bool kHasReturnType = !std::is_same_v; diff --git a/src/tint/type/manager.h b/src/tint/type/manager.h index 59a8cf5e1f..0650f1bb4a 100644 --- a/src/tint/type/manager.h +++ b/src/tint/type/manager.h @@ -65,9 +65,9 @@ class Manager final { /// constructed, then the same pointer is returned. template NODE* Get(ARGS&&... args) { - if constexpr (traits::IsTypeOrDerived) { + if constexpr (utils::traits::IsTypeOrDerived) { return types_.Get(std::forward(args)...); - } else if constexpr (traits::IsTypeOrDerived) { + } else if constexpr (utils::traits::IsTypeOrDerived) { return unique_nodes_.Get(std::forward(args)...); } else { return nodes_.Create(std::forward(args)...); @@ -78,7 +78,7 @@ class Manager final { /// @return a pointer to an instance of `T` with the provided arguments, or nullptr if the item /// was not found. template >, + typename _ = std::enable_if>, typename... ARGS> TYPE* Find(ARGS&&... args) const { return types_.Find(std::forward(args)...); diff --git a/src/tint/utils/slice.h b/src/tint/utils/slice.h index 325c470557..9737cad633 100644 --- a/src/tint/utils/slice.h +++ b/src/tint/utils/slice.h @@ -19,8 +19,8 @@ #include #include "src/tint/castable.h" -#include "src/tint/traits.h" #include "src/tint/utils/bitcast.h" +#include "src/tint/utils/traits.h" namespace tint::utils { @@ -73,8 +73,8 @@ struct CanReinterpretSlice { // or // derives from TO (std::is_same_v, std::remove_const_t> || - (IsCastable && - (MODE == ReinterpretMode::kUnsafe || traits::IsTypeOrDerived))))); + (IsCastable && (MODE == ReinterpretMode::kUnsafe || + utils::traits::IsTypeOrDerived))))); }; /// Specialization of 'CanReinterpretSlice' for when TO and FROM are equal types. diff --git a/src/tint/traits.h b/src/tint/utils/traits.h similarity index 97% rename from src/tint/traits.h rename to src/tint/utils/traits.h index 8d74bf75f2..525ed9b2bf 100644 --- a/src/tint/traits.h +++ b/src/tint/utils/traits.h @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_TINT_TRAITS_H_ -#define SRC_TINT_TRAITS_H_ +#ifndef SRC_TINT_UTILS_TRAITS_H_ +#define SRC_TINT_UTILS_TRAITS_H_ #include #include #include #include -namespace tint::traits { +namespace tint::utils::traits { /// Convience type definition for std::decay::type template @@ -183,6 +183,6 @@ static constexpr bool IsStringLike = std::is_same_v, std::string> || std::is_same_v, std::string_view> || std::is_same_v, const char*>; -} // namespace tint::traits +} // namespace tint::utils::traits -#endif // SRC_TINT_TRAITS_H_ +#endif // SRC_TINT_UTILS_TRAITS_H_ diff --git a/src/tint/traits_test.cc b/src/tint/utils/traits_test.cc similarity index 99% rename from src/tint/traits_test.cc rename to src/tint/utils/traits_test.cc index e86e389d69..578ed44b12 100644 --- a/src/tint/traits_test.cc +++ b/src/tint/utils/traits_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/tint/traits.h" +#include "src/tint/utils/traits.h" #include "gtest/gtest.h" -namespace tint::traits { +namespace tint::utils::traits { namespace { @@ -241,4 +241,4 @@ TEST(SliceTuple, MixedTupleSliceHighPart) { static_assert(std::is_same_v, float>); } -} // namespace tint::traits +} // namespace tint::utils::traits diff --git a/src/tint/utils/transform.h b/src/tint/utils/transform.h index d96a4bbb2d..9615471c5c 100644 --- a/src/tint/utils/transform.h +++ b/src/tint/utils/transform.h @@ -20,7 +20,7 @@ #include #include -#include "src/tint/traits.h" +#include "src/tint/utils/traits.h" #include "src/tint/utils/vector.h" namespace tint::utils {