Remove `EnableIfIsType`.
Remove the`EnableIfIsType` helper and use a requires on
`IsTypeOrDerived` directly. Makes the return type clearer for the few
places which used the substitution.
Change-Id: Id94ca7e149a82fd7d7bcd3de1ea81e0fdc2c1b9b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/239134
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/ast/builder.h b/src/tint/lang/wgsl/ast/builder.h
index c18d84c..e830697 100644
--- a/src/tint/lang/wgsl/ast/builder.h
+++ b/src/tint/lang/wgsl/ast/builder.h
@@ -380,7 +380,8 @@
/// @param args the arguments to pass to the constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
- traits::EnableIfIsType<T, ast::Node>* create(const Source& source, ARGS&&... args) {
+ requires(traits::IsTypeOrDerived<T, ast::Node>)
+ T* create(const Source& source, ARGS&&... args) {
AssertNotMoved();
return ast_nodes_.Create<T>(id_, AllocateNodeID(), source, std::forward<ARGS>(args)...);
}
@@ -392,7 +393,8 @@
/// destructed.
/// @returns the node pointer
template <typename T>
- traits::EnableIfIsType<T, ast::Node>* create() {
+ requires(traits::IsTypeOrDerived<T, ast::Node>)
+ T* create() {
AssertNotMoved();
return ast_nodes_.Create<T>(id_, AllocateNodeID(), source_);
}
@@ -1407,7 +1409,8 @@
/// @param expr the expression
/// @return expr (passthrough)
- template <typename T, typename = traits::EnableIfIsType<T, ast::Expression>>
+ template <typename T>
+ requires(traits::IsTypeOrDerived<T, ast::Expression>)
const T* Expr(const T* expr) {
return expr;
}
diff --git a/src/tint/lang/wgsl/ast/clone_context.h b/src/tint/lang/wgsl/ast/clone_context.h
index ee1eef8..abe681c 100644
--- a/src/tint/lang/wgsl/ast/clone_context.h
+++ b/src/tint/lang/wgsl/ast/clone_context.h
@@ -334,7 +334,8 @@
/// 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 <typename WHAT, typename WITH, typename = traits::EnableIfIsType<WITH, ast::Node>>
+ template <typename WHAT, typename WITH>
+ requires(traits::IsTypeOrDerived<WITH, ast::Node>)
CloneContext& Replace(const WHAT* what, const WITH* with) {
TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(src_id, what);
TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(dst, with);
diff --git a/src/tint/lang/wgsl/ast/module.h b/src/tint/lang/wgsl/ast/module.h
index 8513348..6c82e0d 100644
--- a/src/tint/lang/wgsl/ast/module.h
+++ b/src/tint/lang/wgsl/ast/module.h
@@ -91,7 +91,8 @@
auto& GlobalVariables() { return global_variables_; }
/// @returns the global variable declarations of kind 'T' for the module
- template <typename T, typename = tint::traits::EnableIfIsType<T, Variable>>
+ template <typename T>
+ requires(traits::IsTypeOrDerived<T, Variable>)
auto Globals() const {
tint::Vector<const T*, 32> out;
out.Reserve(global_variables_.Length());
diff --git a/src/tint/lang/wgsl/program/clone_context.h b/src/tint/lang/wgsl/program/clone_context.h
index c6f50a6..a791ba8 100644
--- a/src/tint/lang/wgsl/program/clone_context.h
+++ b/src/tint/lang/wgsl/program/clone_context.h
@@ -79,7 +79,8 @@
}
/// @copydoc ast::CloneContext::Replace
- template <typename WHAT, typename WITH, typename = traits::EnableIfIsType<WITH, ast::Node>>
+ template <typename WHAT, typename WITH>
+ requires(traits::IsTypeOrDerived<WITH, ast::Node>)
CloneContext& Replace(const WHAT* what, const WITH* with) {
ctx_.Replace<WHAT, WITH>(what, with);
return *this;
diff --git a/src/tint/lang/wgsl/program/program_builder.h b/src/tint/lang/wgsl/program/program_builder.h
index c863920..483c718 100644
--- a/src/tint/lang/wgsl/program/program_builder.h
+++ b/src/tint/lang/wgsl/program/program_builder.h
@@ -170,7 +170,8 @@
/// @param args the arguments to pass to the constructor
/// @returns the new, or existing node
template <typename T, typename... ARGS>
- tint::traits::EnableIfIsType<T, core::type::Node>* create(ARGS&&... args) {
+ requires(traits::IsTypeOrDerived<T, core::type::Node>)
+ T* create(ARGS&&... args) {
AssertNotMoved();
return constants.types.Get<T>(std::forward<ARGS>(args)...);
}
diff --git a/src/tint/utils/rtti/traits.h b/src/tint/utils/rtti/traits.h
index 4c044e5..c82dc79 100644
--- a/src/tint/utils/rtti/traits.h
+++ b/src/tint/utils/rtti/traits.h
@@ -115,11 +115,6 @@
static constexpr bool IsTypeOrDerived =
std::is_base_of_v<BASE, std::decay_t<T>> || std::is_same_v<BASE, std::decay_t<T>>;
-/// If `T` is of type `BASE`, or derives from `BASE`, then EnableIfIsType
-/// resolves to type `T`, otherwise an invalid type.
-template <typename T, typename BASE>
-using EnableIfIsType = std::enable_if_t<IsTypeOrDerived<T, BASE>, T>;
-
/// @returns the std::index_sequence with all the indices shifted by OFFSET.
template <std::size_t OFFSET, std::size_t... INDICES>
constexpr auto Shift(std::index_sequence<INDICES...>) {