tint: Implement abstract-numeric overload resolution
Support overload resolution of abstract-numeric argument types,
allowing them to implicitly convert down to concrete parameter
types (and in the near future, abstract parameter types).
Major kudos to cwallez for the suggested algorithm which is a
minor adaption of what we had already.
Bug: tint:1504
Change-Id: I85fa8e70ab0b6aa643caec4c51433f15784af55f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90522
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h
index d54e57c..aca1b29 100644
--- a/src/tint/resolver/resolver_test_helper.h
+++ b/src/tint/resolver/resolver_test_helper.h
@@ -22,6 +22,8 @@
#include "gtest/gtest.h"
#include "src/tint/program_builder.h"
#include "src/tint/resolver/resolver.h"
+#include "src/tint/sem/abstract_float.h"
+#include "src/tint/sem/abstract_int.h"
#include "src/tint/sem/expression.h"
#include "src/tint/sem/statement.h"
#include "src/tint/sem/variable.h"
@@ -174,6 +176,15 @@
template <typename T>
struct DataType {};
+/// Helper that represents no-type. Returns nullptr for all static methods.
+template <>
+struct DataType<void> {
+ /// @return nullptr
+ static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
+ /// @return nullptr
+ static inline const sem::Type* Sem(ProgramBuilder&) { return nullptr; }
+};
+
/// Helper for building bool types and expressions
template <>
struct DataType<bool> {
@@ -254,6 +265,40 @@
}
};
+/// Helper for building abstract float types and expressions
+template <>
+struct DataType<AFloat> {
+ /// false as AFloat is not a composite type
+ static constexpr bool is_composite = false;
+
+ /// @param b the ProgramBuilder
+ /// @return the semantic abstract-float type
+ static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::AbstractFloat>(); }
+ /// @param b the ProgramBuilder
+ /// @param elem_value the abstract-float value
+ /// @return a new AST abstract-float literal value expression
+ static inline const ast::Expression* Expr(ProgramBuilder& b, AFloat elem_value) {
+ return b.Expr(elem_value);
+ }
+};
+
+/// Helper for building abstract integer types and expressions
+template <>
+struct DataType<AInt> {
+ /// false as AFloat is not a composite type
+ static constexpr bool is_composite = false;
+
+ /// @param b the ProgramBuilder
+ /// @return the semantic abstract-int type
+ static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::AbstractInt>(); }
+ /// @param b the ProgramBuilder
+ /// @param elem_value the abstract-int value
+ /// @return a new AST abstract-int literal value expression
+ static inline const ast::Expression* Expr(ProgramBuilder& b, AInt elem_value) {
+ return b.Expr(elem_value);
+ }
+};
+
/// Helper for building vector types and expressions
template <uint32_t N, typename T>
struct DataType<vec<N, T>> {