tint: Replace all remaining AST types with ast::Type
This CL removes the following AST nodes:
* ast::Array
* ast::Atomic
* ast::Matrix
* ast::MultisampledTexture
* ast::Pointer
* ast::SampledTexture
* ast::Texture
* ast::TypeName
* ast::Vector
ast::Type, which used to be the base class for all AST types, is now a
thin wrapper around ast::IdentifierExpression. All types are now
referred to using their type name.
The resolver now handles type resolution and validation of the types
listed above based on the TemplateIdentifier arguments.
Other changes:
* ProgramBuilder has undergone substantial refactoring.
* ProgramBuilder helpers for type inferencing is now more explicit.
Instead of passing 'nullptr', a new 'Infer' template argument is
passed.
* ast::CheckIdentifier() is used for more tests that check identifiers,
including types.
Bug: tint:1810
Change-Id: I8e739ef49435dc1c20a462f3ec5ba265661a7edb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118723
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h
index ee913f4..67d71b8 100644
--- a/src/tint/resolver/resolver_test_helper.h
+++ b/src/tint/resolver/resolver_test_helper.h
@@ -112,7 +112,7 @@
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be
/// declared in WGSL.
- std::string FriendlyName(const ast::Type* type) { return type->FriendlyName(Symbols()); }
+ std::string FriendlyName(ast::Type type) { return Symbols().NameFor(type->identifier->symbol); }
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be
@@ -199,7 +199,7 @@
return std::visit([](auto&& v) { return static_cast<T>(v); }, s);
}
-using ast_type_func_ptr = const ast::Type* (*)(ProgramBuilder& b);
+using ast_type_func_ptr = ast::Type (*)(ProgramBuilder& b);
using ast_expr_func_ptr = const ast::Expression* (*)(ProgramBuilder& b,
utils::VectorRef<Scalar> args);
using ast_expr_from_double_func_ptr = const ast::Expression* (*)(ProgramBuilder& b, double v);
@@ -222,7 +222,7 @@
using ElementType = void;
/// @return nullptr
- static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
+ static inline ast::Type AST(ProgramBuilder&) { return {}; }
/// @return nullptr
static inline const type::Type* Sem(ProgramBuilder&) { return nullptr; }
};
@@ -238,7 +238,7 @@
/// @param b the ProgramBuilder
/// @return a new AST bool type
- static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.bool_(); }
+ static inline ast::Type AST(ProgramBuilder& b) { return b.ty.bool_(); }
/// @param b the ProgramBuilder
/// @return the semantic bool type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::Bool>(); }
@@ -269,7 +269,7 @@
/// @param b the ProgramBuilder
/// @return a new AST i32 type
- static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.i32(); }
+ static inline ast::Type AST(ProgramBuilder& b) { return b.ty.i32(); }
/// @param b the ProgramBuilder
/// @return the semantic i32 type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::I32>(); }
@@ -300,7 +300,7 @@
/// @param b the ProgramBuilder
/// @return a new AST u32 type
- static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.u32(); }
+ static inline ast::Type AST(ProgramBuilder& b) { return b.ty.u32(); }
/// @param b the ProgramBuilder
/// @return the semantic u32 type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::U32>(); }
@@ -331,7 +331,7 @@
/// @param b the ProgramBuilder
/// @return a new AST f32 type
- static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f32(); }
+ static inline ast::Type AST(ProgramBuilder& b) { return b.ty.f32(); }
/// @param b the ProgramBuilder
/// @return the semantic f32 type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::F32>(); }
@@ -362,7 +362,7 @@
/// @param b the ProgramBuilder
/// @return a new AST f16 type
- static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f16(); }
+ static inline ast::Type AST(ProgramBuilder& b) { return b.ty.f16(); }
/// @param b the ProgramBuilder
/// @return the semantic f16 type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::F16>(); }
@@ -392,7 +392,7 @@
static constexpr bool is_composite = false;
/// @returns nullptr, as abstract floats are un-typeable
- static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
+ static inline ast::Type AST(ProgramBuilder&) { return {}; }
/// @param b the ProgramBuilder
/// @return the semantic abstract-float type
static inline const type::Type* Sem(ProgramBuilder& b) {
@@ -424,7 +424,7 @@
static constexpr bool is_composite = false;
/// @returns nullptr, as abstract integers are un-typeable
- static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
+ static inline ast::Type AST(ProgramBuilder&) { return {}; }
/// @param b the ProgramBuilder
/// @return the semantic abstract-int type
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<type::AbstractInt>(); }
@@ -455,8 +455,12 @@
/// @param b the ProgramBuilder
/// @return a new AST vector type
- static inline const ast::Type* AST(ProgramBuilder& b) {
- return b.ty.vec(DataType<T>::AST(b), N);
+ static inline ast::Type AST(ProgramBuilder& b) {
+ if (IsInferOrAbstract<T>) {
+ return b.ty.vec<Infer, N>();
+ } else {
+ return b.ty.vec(DataType<T>::AST(b), N);
+ }
}
/// @param b the ProgramBuilder
/// @return the semantic vector type
@@ -503,8 +507,12 @@
/// @param b the ProgramBuilder
/// @return a new AST matrix type
- static inline const ast::Type* AST(ProgramBuilder& b) {
- return b.ty.mat(DataType<T>::AST(b), N, M);
+ static inline ast::Type AST(ProgramBuilder& b) {
+ if (IsInferOrAbstract<T>) {
+ return b.ty.mat<Infer, N, M>();
+ } else {
+ return b.ty.mat(DataType<T>::AST(b), N, M);
+ }
}
/// @param b the ProgramBuilder
/// @return the semantic matrix type
@@ -562,14 +570,15 @@
/// @param b the ProgramBuilder
/// @return a new AST alias type
- static inline const ast::Type* AST(ProgramBuilder& b) {
+ static inline ast::Type AST(ProgramBuilder& b) {
auto name = b.Symbols().Register("alias_" + std::to_string(ID));
if (!b.AST().LookupType(name)) {
- auto* type = DataType<T>::AST(b);
+ auto type = DataType<T>::AST(b);
b.AST().AddTypeDecl(b.ty.alias(name, type));
}
return b.ty(name);
}
+
/// @param b the ProgramBuilder
/// @return the semantic aliased type
static inline const type::Type* Sem(ProgramBuilder& b) { return DataType<T>::Sem(b); }
@@ -618,9 +627,9 @@
/// @param b the ProgramBuilder
/// @return a new AST alias type
- static inline const ast::Type* AST(ProgramBuilder& b) {
- return b.create<ast::Pointer>(DataType<T>::AST(b), type::AddressSpace::kPrivate,
- type::Access::kUndefined);
+ static inline ast::Type AST(ProgramBuilder& b) {
+ return b.ty.pointer(DataType<T>::AST(b), type::AddressSpace::kPrivate,
+ type::Access::kUndefined);
}
/// @param b the ProgramBuilder
/// @return the semantic aliased type
@@ -660,11 +669,11 @@
/// @param b the ProgramBuilder
/// @return a new AST array type
- static inline const ast::Type* AST(ProgramBuilder& b) {
- if (auto* ast = DataType<T>::AST(b)) {
+ static inline ast::Type AST(ProgramBuilder& b) {
+ if (auto ast = DataType<T>::AST(b)) {
return b.ty.array(ast, u32(N));
}
- return b.ty.array(nullptr, nullptr);
+ return b.ty.array<Infer>();
}
/// @param b the ProgramBuilder
/// @return the semantic array type