ast: Replace NamedType with TypeDecl

TypeDecls (alias, structure) are not a types - they declare types.
ast::TypeName is what's used for a ast::Type.

Previously we were trying to automatically convert these to TypeNames in the builder, but having these inherit from ast::Type was extremely error prone.

reader/spirv was actually constructing ast::Structs and using them as types, which is invalid.

Change-Id: I05773ad6d488626606019015b84217a5a55a8e8a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53802
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2021-06-09 14:32:14 +00:00
parent 6e7d24d36a
commit 8758f10a20
81 changed files with 539 additions and 522 deletions

View File

@@ -332,7 +332,7 @@ void InsertGlobal(CloneContext& ctx,
}
/// @returns the unwrapped, user-declared constructed type of ty.
const ast::NamedType* ConstructedTypeOf(const sem::Type* ty) {
const ast::TypeDecl* ConstructedTypeOf(const sem::Type* ty) {
while (true) {
if (auto* ref = ty->As<sem::Reference>()) {
ty = ref->StoreType();
@@ -414,7 +414,7 @@ struct DecomposeStorageAccess::State {
/// @param var_user the variable user
/// @return the name of the function that performs the load
Symbol LoadFunc(CloneContext& ctx,
const ast::NamedType* insert_after,
const ast::TypeDecl* insert_after,
const sem::Type* buf_ty,
const sem::Type* el_ty,
const sem::VariableUser* var_user) {
@@ -490,7 +490,7 @@ struct DecomposeStorageAccess::State {
/// @param var_user the variable user
/// @return the name of the function that performs the store
Symbol StoreFunc(CloneContext& ctx,
const ast::NamedType* insert_after,
const ast::TypeDecl* insert_after,
const sem::Type* buf_ty,
const sem::Type* el_ty,
const sem::VariableUser* var_user) {

View File

@@ -133,14 +133,14 @@ Output FirstIndexOffset::Run(const Program* in, const DataMap& data) {
instance_index_offset = offset;
offset += 4;
}
auto* struct_type =
auto* struct_ =
ctx.dst->Structure(ctx.dst->Sym(), std::move(members),
{ctx.dst->create<ast::StructBlockDecoration>()});
// Create a global to hold the uniform buffer
Symbol buffer_name = ctx.dst->Sym();
ctx.dst->Global(buffer_name, struct_type, ast::StorageClass::kUniform,
nullptr,
ctx.dst->Global(buffer_name, ctx.dst->ty.Of(struct_),
ast::StorageClass::kUniform, nullptr,
ast::DecorationList{
ctx.dst->create<ast::BindingDecoration>(ub_binding),
ctx.dst->create<ast::GroupDecoration>(ub_group),

View File

@@ -69,7 +69,7 @@ Output SingleEntryPoint::Run(const Program* in, const DataMap& data) {
// Clone any module-scope variables, types, and functions that are statically
// referenced by the target entry point.
for (auto* decl : in->AST().GlobalDeclarations()) {
if (auto* ty = decl->As<ast::NamedType>()) {
if (auto* ty = decl->As<ast::TypeDecl>()) {
// TODO(jrprice): Strip unused types.
out.AST().AddConstructedType(ctx.Clone(ty));
} else if (auto* var = decl->As<ast::Variable>()) {

View File

@@ -216,8 +216,8 @@ struct State {
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
// The decorated variable with struct type
ctx.dst->Global(
GetVertexBufferName(i), struct_type, ast::StorageClass::kStorage,
ast::Access::kRead,
GetVertexBufferName(i), ctx.dst->ty.Of(struct_type),
ast::StorageClass::kStorage, ast::Access::kRead,
ast::DecorationList{
ctx.dst->create<ast::BindingDecoration>(i),
ctx.dst->create<ast::GroupDecoration>(cfg.pulling_group),
@@ -485,7 +485,8 @@ struct State {
auto* new_struct = ctx.dst->Structure(ctx.dst->Sym(), new_members);
// Create a new function parameter with this struct.
auto* new_param = ctx.dst->Param(ctx.dst->Sym(), new_struct);
auto* new_param =
ctx.dst->Param(ctx.dst->Sym(), ctx.dst->ty.Of(new_struct));
new_function_parameters.push_back(new_param);
// Copy values from the new parameter to the function-scope variable.