diff --git a/src/program_builder.h b/src/program_builder.h index 6919904a8a..ce0f9cbcdd 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -43,6 +43,7 @@ #include "src/ast/variable_decl_statement.h" #include "src/program.h" #include "src/program_id.h" +#include "src/type/access_control_type.h" #include "src/type/alias_type.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" @@ -517,6 +518,7 @@ class ProgramBuilder { type::Array* array(uint32_t stride) const { return array(Of(), N, stride); } + /// Creates an alias type /// @param name the alias name /// @param type the alias type @@ -527,6 +529,15 @@ class ProgramBuilder { builder->Sym(std::forward(name)), type); } + /// Creates an access control qualifier type + /// @param access the access control + /// @param type the inner type + /// @returns the access control qualifier type + type::AccessControl* access(ast::AccessControl access, + type::Type* type) const { + return builder->create(access, type); + } + /// @return the tint AST pointer to `type` with the given ast::StorageClass /// @param type the type of the pointer /// @param storage_class the storage class of the pointer diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 5bbc82093d..257c822a75 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -2279,9 +2279,10 @@ std::string Resolver::VectorPretty(uint32_t size, type::Type* element_type) { } type::Type* Resolver::Canonical(type::Type* type) { - using Type = type::Type; + using AccessControl = type::AccessControl; using Alias = type::Alias; using Matrix = type::Matrix; + using Type = type::Type; using Vector = type::Vector; std::function make_canonical; @@ -2299,6 +2300,10 @@ type::Type* Resolver::Canonical(type::Type* type) { return builder_->create(make_canonical(m->type()), m->rows(), m->columns()); } + if (auto* ac = ct->As()) { + return builder_->create(ac->access_control(), + make_canonical(ac->type())); + } return ct; }; diff --git a/src/resolver/resolver_test_helper.h b/src/resolver/resolver_test_helper.h index a3dfce1ad1..3ac82f7f08 100644 --- a/src/resolver/resolver_test_helper.h +++ b/src/resolver/resolver_test_helper.h @@ -194,6 +194,12 @@ type::Type* ty_alias(const ProgramBuilder::TypesBuilder& ty) { return ty.alias("alias_" + type->type_name(), type); } +template +type::Type* ty_access(const ProgramBuilder::TypesBuilder& ty) { + auto* type = create_type(ty); + return ty.access(ast::AccessControl::kReadOnly, type); +} + } // namespace resolver } // namespace tint diff --git a/src/resolver/type_validation_test.cc b/src/resolver/type_validation_test.cc index 973c7182a8..213099b823 100644 --- a/src/resolver/type_validation_test.cc +++ b/src/resolver/type_validation_test.cc @@ -490,6 +490,12 @@ static constexpr Params cases[] = { Params{ty_alias>>>, ty_mat3x3}, Params{ty_alias>>>>, ty_mat3x3}, + + Params{ty_alias>>, ty_access}, + Params{ty_alias>>>>, + ty_access>>}, + Params{ty_alias>>>>, + ty_access>>}, }; using CanonicalTest = ResolverTestWithParam;