Move tint::ast::type to tint::type

Despite `tint::ast::type::Type` being in the AST namespace, these classes are clearly not AST nodes:
* They don't derive from ast::Node
* They're deduplicated by the type manager
* None of the types have an Source - they have no lexical declaration point
* The fact we have `ast::Struct` and `ast::type::Struct` clearly demonstrates what is an AST node, and what is a type.
* We have code scattered in the codebase (TypeDeterminer, writers, etc) that create new types after parsing - so clearly not part of the original syntax tree.

Types in tint are closer to being semantic info, but due to the parse-time generation of types, and tight dependency of ast::Nodes to types, I'd be reluctant to class these as semantic info. Instead, put these into a separate root level `tint::type` namespace and `src/tint` directory.

The fact that types exist in the ast::Module has already caused bugs (https://dawn-review.googlesource.com/c/tint/+/37261). This is a first step in separating out types from the ast::Module.

Bug: tint:390
Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-01-21 15:42:10 +00:00
committed by Commit Bot service account
parent 587f387fd9
commit 207b5e2de1
227 changed files with 3647 additions and 3869 deletions

View File

@@ -39,15 +39,15 @@
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/switch_statement.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/unary_op_expression.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
#include "src/type/array_type.h"
#include "src/type/matrix_type.h"
#include "src/type/u32_type.h"
#include "src/type/vector_type.h"
namespace tint {
namespace transform {
@@ -71,8 +71,8 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
ast::CloneContext* ctx,
diag::List* diags) {
auto* ret_type = expr->array()->result_type()->UnwrapAll();
if (!ret_type->Is<ast::type::Array>() && !ret_type->Is<ast::type::Matrix>() &&
!ret_type->Is<ast::type::Vector>()) {
if (!ret_type->Is<type::Array>() && !ret_type->Is<type::Matrix>() &&
!ret_type->Is<type::Vector>()) {
return nullptr;
}
@@ -80,15 +80,15 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
using u32 = ast::Builder::u32;
uint32_t size = 0;
bool is_vec = ret_type->Is<ast::type::Vector>();
bool is_arr = ret_type->Is<ast::type::Array>();
bool is_vec = ret_type->Is<type::Vector>();
bool is_arr = ret_type->Is<type::Array>();
if (is_vec || is_arr) {
size = is_vec ? ret_type->As<ast::type::Vector>()->size()
: ret_type->As<ast::type::Array>()->size();
size = is_vec ? ret_type->As<type::Vector>()->size()
: ret_type->As<type::Array>()->size();
} else {
// The row accessor would have been an embedded array accessor and already
// handled, so we just need to do columns here.
size = ret_type->As<ast::type::Matrix>()->columns();
size = ret_type->As<type::Matrix>()->columns();
}
auto* const old_idx = expr->idx_expr();

View File

@@ -23,9 +23,9 @@
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type_manager.h"
#include "src/ast/variable.h"
#include "src/type/f32_type.h"
#include "src/type/type_manager.h"
namespace tint {
namespace transform {
@@ -47,7 +47,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
return out;
}
auto* f32 = out.module.create<ast::type::F32>();
auto* f32 = out.module.create<type::F32>();
// Declare the pointsize builtin output variable.
auto* pointsize_var = out.module.create<ast::Variable>(

View File

@@ -42,13 +42,13 @@
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/switch_statement.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/unary_op_expression.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h"
#include "src/type/struct_type.h"
#include "src/type/u32_type.h"
#include "src/type_determiner.h"
namespace tint {
@@ -196,7 +196,7 @@ uint32_t FirstIndexOffset::GetFirstInstanceOffset() {
}
ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
auto* u32_type = mod->create<ast::type::U32>();
auto* u32_type = mod->create<type::U32>();
ast::StructMemberList members;
uint32_t offset = 0;
if (has_vertex_index_) {
@@ -224,7 +224,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
ast::StructDecorationList decos;
decos.push_back(mod->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = mod->create<ast::type::Struct>(
auto* struct_type = mod->create<type::Struct>(
mod->RegisterSymbol(kStructName),
mod->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
@@ -268,9 +268,9 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
mod->create<ast::Variable>(Source{}, // source
mod->RegisterSymbol(original_name), // symbol
ast::StorageClass::kNone, // storage_class
mod->create<ast::type::U32>(), // type
true, // is_const
constructor, // constructor
mod->create<type::U32>(), // type
true, // is_const
constructor, // constructor
ast::VariableDecorationList{}); // decorations
return mod->create<ast::VariableDeclStatement>(Source{}, var);
}

View File

@@ -29,16 +29,16 @@
#include "src/ast/struct_decoration.h"
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
#include "src/type/array_type.h"
#include "src/type/f32_type.h"
#include "src/type/i32_type.h"
#include "src/type/struct_type.h"
#include "src/type/u32_type.h"
#include "src/type/vector_type.h"
namespace tint {
namespace transform {
@@ -261,7 +261,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
void VertexPulling::State::AddVertexStorageBuffers() {
// TODO(idanr): Make this readonly https://github.com/gpuweb/gpuweb/issues/935
// The array inside the struct definition
auto* internal_array_type = out->create<ast::type::Array>(
auto* internal_array_type = out->create<type::Array>(
GetU32Type(), 0,
ast::ArrayDecorationList{
out->create<ast::StrideDecoration>(Source{}, 4u),
@@ -280,7 +280,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
ast::StructDecorationList decos;
decos.push_back(out->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = out->create<ast::type::Struct>(
auto* struct_type = out->create<type::Struct>(
out->RegisterSymbol(kStructName),
out->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
@@ -463,7 +463,7 @@ ast::Expression* VertexPulling::State::AccessPrimitive(
ast::Expression* VertexPulling::State::AccessVec(uint32_t buffer,
uint32_t element_stride,
ast::type::Type* base_type,
type::Type* base_type,
VertexFormat base_format,
uint32_t count) const {
ast::ExpressionList expr_list;
@@ -476,20 +476,20 @@ ast::Expression* VertexPulling::State::AccessVec(uint32_t buffer,
}
return out->create<ast::TypeConstructorExpression>(
Source{}, out->create<ast::type::Vector>(base_type, count),
Source{}, out->create<type::Vector>(base_type, count),
std::move(expr_list));
}
ast::type::Type* VertexPulling::State::GetU32Type() const {
return out->create<ast::type::U32>();
type::Type* VertexPulling::State::GetU32Type() const {
return out->create<type::U32>();
}
ast::type::Type* VertexPulling::State::GetI32Type() const {
return out->create<ast::type::I32>();
type::Type* VertexPulling::State::GetI32Type() const {
return out->create<type::I32>();
}
ast::type::Type* VertexPulling::State::GetF32Type() const {
return out->create<ast::type::F32>();
type::Type* VertexPulling::State::GetF32Type() const {
return out->create<type::F32>();
}
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default;

View File

@@ -254,14 +254,14 @@ class VertexPulling : public Transform {
/// @param count how many elements the vector has
ast::Expression* AccessVec(uint32_t buffer,
uint32_t element_stride,
ast::type::Type* base_type,
type::Type* base_type,
VertexFormat base_format,
uint32_t count) const;
// Used to grab corresponding types from the type manager
ast::type::Type* GetU32Type() const;
ast::type::Type* GetI32Type() const;
ast::type::Type* GetF32Type() const;
type::Type* GetU32Type() const;
type::Type* GetI32Type() const;
type::Type* GetF32Type() const;
ast::Module* const in;
ast::Module* const out;