Global tweaks to handle having no sem::Type

Soon, we'll start migrating the AST from using sem::Types to ast::Types.
This change fixes up a bunch of places that makes the assumption that the semantic type is always expected.

Bug: tint:724
Change-Id: I96096bdf7177751ca6c6240e1739244cbeb82761
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49348
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-04-28 14:31:23 +00:00 committed by Commit Bot service account
parent 2ac55febf5
commit f5f311e264
8 changed files with 46 additions and 35 deletions

View File

@ -26,7 +26,7 @@ BitcastExpression::BitcastExpression(ProgramID program_id,
typ::Type type, typ::Type type,
Expression* expr) Expression* expr)
: Base(program_id, source), type_(type), expr_(expr) { : Base(program_id, source), type_(type), expr_(expr) {
TINT_ASSERT(type_.sem); TINT_ASSERT(type_.ast || type_.sem);
TINT_ASSERT(expr_); TINT_ASSERT(expr_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(expr, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(expr, program_id);
} }
@ -46,8 +46,9 @@ void BitcastExpression::to_str(const sem::Info& sem,
std::ostream& out, std::ostream& out,
size_t indent) const { size_t indent) const {
make_indent(out, indent); make_indent(out, indent);
out << "Bitcast[" << result_type_str(sem) << "]<" << type_->type_name() out << "Bitcast[" << result_type_str(sem) << "]<"
<< ">{" << std::endl; << (type_.ast ? type_.ast->type_name() : type_.sem->type_name()) << ">{"
<< std::endl;
expr_->to_str(sem, out, indent + 2); expr_->to_str(sem, out, indent + 2);
make_indent(out, indent); make_indent(out, indent);
out << "}" << std::endl; out << "}" << std::endl;

View File

@ -45,7 +45,7 @@ Function::Function(ProgramID program_id,
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(param, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(param, program_id);
} }
TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT(return_type_.sem); TINT_ASSERT(return_type_.ast || return_type_.sem);
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(deco, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(deco, program_id);
} }
@ -92,7 +92,9 @@ void Function::to_str(const sem::Info& sem,
std::ostream& out, std::ostream& out,
size_t indent) const { size_t indent) const {
make_indent(out, indent); make_indent(out, indent);
out << "Function " << symbol_.to_str() << " -> " << return_type_->type_name() out << "Function " << symbol_.to_str() << " -> "
<< (return_type_.ast ? return_type_.ast->type_name()
: return_type_.sem->type_name())
<< std::endl; << std::endl;
for (auto* deco : decorations()) { for (auto* deco : decorations()) {

View File

@ -30,7 +30,7 @@ StructMember::StructMember(ProgramID program_id,
symbol_(sym), symbol_(sym),
type_(type), type_(type),
decorations_(std::move(decorations)) { decorations_(std::move(decorations)) {
TINT_ASSERT(type.sem); TINT_ASSERT(type.ast || type.sem);
TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
@ -76,7 +76,9 @@ void StructMember::to_str(const sem::Info& sem,
out << "]] "; out << "]] ";
} }
out << symbol_.to_str() << ": " << type_->type_name() << "}" << std::endl; out << symbol_.to_str() << ": "
<< (type_.ast ? type_.ast->type_name() : type_.sem->type_name()) << "}"
<< std::endl;
} }
} // namespace ast } // namespace ast

View File

@ -26,7 +26,7 @@ TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id,
typ::Type type, typ::Type type,
ExpressionList values) ExpressionList values)
: Base(program_id, source), type_(type), values_(std::move(values)) { : Base(program_id, source), type_(type), values_(std::move(values)) {
TINT_ASSERT(type_.sem); TINT_ASSERT(type_.ast || type_.sem);
for (auto* val : values_) { for (auto* val : values_) {
TINT_ASSERT(val); TINT_ASSERT(val);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(val, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(val, program_id);
@ -53,7 +53,8 @@ void TypeConstructorExpression::to_str(const sem::Info& sem,
make_indent(out, indent); make_indent(out, indent);
out << "TypeConstructor[" << result_type_str(sem) << "]{" << std::endl; out << "TypeConstructor[" << result_type_str(sem) << "]{" << std::endl;
make_indent(out, indent + 2); make_indent(out, indent + 2);
out << type_->type_name() << std::endl; out << (type_.ast ? type_.ast->type_name() : type_.sem->type_name())
<< std::endl;
for (auto* val : values_) { for (auto* val : values_) {
val->to_str(sem, out, indent + 2); val->to_str(sem, out, indent + 2);

View File

@ -41,7 +41,7 @@ Variable::Variable(ProgramID program_id,
TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
// no type means we must have a constructor to infer it // no type means we must have a constructor to infer it
TINT_ASSERT(type_.sem || constructor); TINT_ASSERT(type_.ast || type_.sem || constructor);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id);
} }
@ -90,9 +90,8 @@ void Variable::info_to_str(const sem::Info& sem,
out << (var_sem ? var_sem->StorageClass() : declared_storage_class()) out << (var_sem ? var_sem->StorageClass() : declared_storage_class())
<< std::endl; << std::endl;
make_indent(out, indent); make_indent(out, indent);
if (type_.sem) { out << (type_.sem ? type_.sem->type_name() : type_.ast->type_name())
out << type_->type_name() << std::endl; << std::endl;
}
} }
void Variable::constructor_to_str(const sem::Info& sem, void Variable::constructor_to_str(const sem::Info& sem,

View File

@ -173,7 +173,8 @@ class InspectorHelper : public ProgramBuilder {
/// @param type type of member /// @param type type of member
/// @returns a string for the member /// @returns a string for the member
std::string StructMemberName(size_t idx, typ::Type type) { std::string StructMemberName(size_t idx, typ::Type type) {
return std::to_string(idx) + type->type_name(); return std::to_string(idx) +
(type.sem ? type.sem->type_name() : type.ast->type_name());
} }
/// Generates a struct type /// Generates a struct type

View File

@ -861,6 +861,9 @@ class ProgramBuilder {
/// @return either type or a pointer to a new ast::TypeName /// @return either type or a pointer to a new ast::TypeName
typ::Type MaybeCreateTypename(typ::Type type) const; typ::Type MaybeCreateTypename(typ::Type type) const;
/// The ProgramBuilder
ProgramBuilder* const builder;
private: private:
/// CToAST<T> is specialized for various `T` types and each specialization /// CToAST<T> is specialized for various `T` types and each specialization
/// contains a single static `get()` method for obtaining the corresponding /// contains a single static `get()` method for obtaining the corresponding
@ -869,8 +872,6 @@ class ProgramBuilder {
/// `static typ::Type get(Types* t)` /// `static typ::Type get(Types* t)`
template <typename T> template <typename T>
struct CToAST {}; struct CToAST {};
ProgramBuilder* const builder;
}; };
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -26,63 +26,63 @@ namespace {
using ::testing::HasSubstr; using ::testing::HasSubstr;
using create_type_func_ptr = using create_type_func_ptr =
sem::Type* (*)(const ProgramBuilder::TypesBuilder& ty); typ::Type (*)(const ProgramBuilder::TypesBuilder& ty);
inline sem::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_i32(const ProgramBuilder::TypesBuilder& ty) {
return ty.i32(); return ty.i32();
} }
inline sem::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_u32(const ProgramBuilder::TypesBuilder& ty) {
return ty.u32(); return ty.u32();
} }
inline sem::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_f32(const ProgramBuilder::TypesBuilder& ty) {
return ty.f32(); return ty.f32();
} }
template <typename T> template <typename T>
inline sem::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_vec2(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec2<T>(); return ty.vec2<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_vec3(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec3<T>(); return ty.vec3<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_vec4(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec4<T>(); return ty.vec4<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat2x2<T>(); return ty.mat2x2<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat2x3<T>(); return ty.mat2x3<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat2x4<T>(); return ty.mat2x4<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat3x2<T>(); return ty.mat3x2<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat3x3<T>(); return ty.mat3x3<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat3x4<T>(); return ty.mat3x4<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat4x2<T>(); return ty.mat4x2<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat4x3<T>(); return ty.mat4x3<T>();
} }
template <typename T> template <typename T>
inline sem::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { inline typ::Type ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat4x4<T>(); return ty.mat4x4<T>();
} }
@ -155,8 +155,12 @@ struct TypeCase {
}; };
inline std::ostream& operator<<(std::ostream& out, TypeCase c) { inline std::ostream& operator<<(std::ostream& out, TypeCase c) {
ProgramBuilder b; ProgramBuilder b;
auto* ty = c.member_type(b.ty); auto ty = c.member_type(b.ty);
out << ty->FriendlyName(b.Symbols()); if (ty.sem) {
out << ty.sem->FriendlyName(b.Symbols());
} else {
out << ty.ast->FriendlyName(b.Symbols());
}
return out; return out;
} }
@ -246,7 +250,7 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) {
auto p = GetParam(); auto p = GetParam();
auto* type = p.member_type(ty); auto type = p.member_type(ty);
SetupStorageBuffer({ SetupStorageBuffer({
Member("a", ty.i32()), Member("a", ty.i32()),