From 0ce070474164e564898312608c147d4a9c6b361d Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 21 Oct 2020 19:15:20 +0000 Subject: [PATCH] Remove type alias struct variant. This CL removes the `type IDENT = struct` format in favour of the `struct IDENT` variant. Bug: tint:175 Change-Id: I4fde8012fd07f811cd0bd80445198f6bbc92b720 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30661 Commit-Queue: dan sinclair Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- src/reader/wgsl/parser_impl.cc | 38 ++++--------- src/reader/wgsl/parser_impl.h | 3 +- .../wgsl/parser_impl_global_decl_test.cc | 26 --------- .../wgsl/parser_impl_struct_decl_test.cc | 33 ++++-------- .../wgsl/parser_impl_type_alias_test.cc | 53 ------------------- src/writer/hlsl/generator_impl.cc | 29 +++++----- src/writer/hlsl/generator_impl.h | 5 +- .../hlsl/generator_impl_alias_type_test.cc | 6 +-- .../hlsl/generator_impl_function_test.cc | 6 +-- src/writer/hlsl/generator_impl_type_test.cc | 8 +-- src/writer/msl/generator_impl.cc | 16 ++---- .../msl/generator_impl_alias_type_test.cc | 29 ---------- src/writer/wgsl/generator_impl.cc | 18 ++----- .../wgsl/generator_impl_alias_type_test.cc | 13 ++--- 14 files changed, 61 insertions(+), 222 deletions(-) diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index f365cfb484..33a487fdf8 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -261,7 +261,7 @@ void ParserImpl::global_decl() { return; } - auto str = struct_decl(""); + auto str = struct_decl(); if (has_error()) { return; } @@ -1080,7 +1080,6 @@ ast::StorageClass ParserImpl::variable_storage_decoration() { // type_alias // : TYPE IDENT EQUAL type_decl -// | TYPE IDENT EQUAL struct_decl ast::type::Type* ParserImpl::type_alias() { auto t = peek(); if (!t.IsType()) @@ -1105,17 +1104,8 @@ ast::type::Type* ParserImpl::type_alias() { if (has_error()) return nullptr; if (type == nullptr) { - auto str = struct_decl(name); - if (has_error()) - return nullptr; - if (str == nullptr) { - set_error(peek(), "invalid type alias"); - return nullptr; - } - - type = ctx_.type_mgr().Get(std::move(str)); - register_constructed(name, type); - return type; + set_error(peek(), "invalid type alias"); + return nullptr; } if (type == nullptr) { set_error(peek(), "invalid type for alias"); @@ -1501,9 +1491,8 @@ ast::StorageClass ParserImpl::storage_class() { } // struct_decl -// : struct_decoration_decl* STRUCT struct_body_decl -std::unique_ptr ParserImpl::struct_decl( - const std::string& name) { +// : struct_decoration_decl* STRUCT IDENT struct_body_decl +std::unique_ptr ParserImpl::struct_decl() { auto t = peek(); auto source = t.source(); @@ -1527,17 +1516,12 @@ std::unique_ptr ParserImpl::struct_decl( } next(); // Consume the peek - // If there is no name this is a global struct call. This check will go - // away when the type_alias struct entry is removed. - std::string str_name = name; - if (name.empty()) { - t = next(); - if (!t.IsIdentifier()) { - set_error(t, "missing identifier for struct declaration"); - return nullptr; - } - str_name = t.to_str(); + t = next(); + if (!t.IsIdentifier()) { + set_error(t, "missing identifier for struct declaration"); + return nullptr; } + auto name = t.to_str(); auto body = struct_body_decl(); if (has_error()) { @@ -1545,7 +1529,7 @@ std::unique_ptr ParserImpl::struct_decl( } return std::make_unique( - str_name, + name, std::make_unique(source, std::move(decos), std::move(body))); } diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index fd8661a794..d50147ee50 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -156,9 +156,8 @@ class ParserImpl { /// @returns the storage class or StorageClass::kNone if none matched ast::StorageClass storage_class(); /// Parses a `struct_decl` grammar element - /// @param name the name of the struct /// @returns the struct type or nullptr on error - std::unique_ptr struct_decl(const std::string& name); + std::unique_ptr struct_decl(); /// Parses a `struct_decoration_decl` grammar element, appending newly /// parsed decorations to the end of |decos|. /// @param decos list to store the parsed decorations diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index a030ed4f30..cc93b06a6e 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -92,17 +92,6 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) { EXPECT_EQ(m.constructed_types()[0]->AsAlias()->name(), "A"); } -TEST_F(ParserImplTest, GlobalDecl_TypeAlias_Struct) { - auto* p = parser("type A = struct { a : f32; };"); - p->global_decl(); - ASSERT_FALSE(p->has_error()) << p->error(); - - auto m = p->module(); - ASSERT_EQ(m.constructed_types().size(), 1u); - ASSERT_TRUE(m.constructed_types()[0]->IsStruct()); - EXPECT_EQ(m.constructed_types()[0]->AsStruct()->name(), "A"); -} - TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { auto* p = parser(R"(struct A { a : f32; @@ -239,21 +228,6 @@ TEST_F(ParserImplTest, GlobalDecl_StructMissing_Semi) { EXPECT_EQ(p->error(), "1:22: missing ';' for struct declaration"); } -// This was failing due to not finding the missing ;. https://crbug.com/tint/218 -TEST_F(ParserImplTest, TypeDecl_Struct_Empty) { - auto* p = parser("type str = struct {};"); - p->global_decl(); - ASSERT_FALSE(p->has_error()) << p->error(); - - auto module = p->module(); - ASSERT_EQ(module.constructed_types().size(), 1u); - - ASSERT_TRUE(module.constructed_types()[0]->IsStruct()); - auto* str = module.constructed_types()[0]->AsStruct(); - EXPECT_EQ(str->name(), "str"); - EXPECT_EQ(str->impl()->members().size(), 0u); -} - } // namespace } // namespace wgsl } // namespace reader diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index 8a80237b1e..3222117dde 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -28,22 +28,7 @@ struct S { a : i32; [[offset(4)]] b : f32; })"); - auto s = p->struct_decl(""); - ASSERT_FALSE(p->has_error()); - ASSERT_NE(s, nullptr); - ASSERT_EQ(s->name(), "S"); - ASSERT_EQ(s->impl()->members().size(), 2u); - EXPECT_EQ(s->impl()->members()[0]->name(), "a"); - EXPECT_EQ(s->impl()->members()[1]->name(), "b"); -} - -TEST_F(ParserImplTest, StructDecl_Parses_WithoutName) { - auto* p = parser(R"( -struct { - a : i32; - [[offset(4)]] b : f32; -})"); - auto s = p->struct_decl("S"); + auto s = p->struct_decl(); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); ASSERT_EQ(s->name(), "S"); @@ -58,7 +43,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { a : f32; b : f32; })"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); ASSERT_EQ(s->name(), "B"); @@ -76,7 +61,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { a : f32; b : f32; })"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); ASSERT_EQ(s->name(), "S"); @@ -90,7 +75,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { TEST_F(ParserImplTest, StructDecl_EmptyMembers) { auto* p = parser("struct S {}"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_FALSE(p->has_error()); ASSERT_NE(s, nullptr); ASSERT_EQ(s->impl()->members().size(), 0u); @@ -98,7 +83,7 @@ TEST_F(ParserImplTest, StructDecl_EmptyMembers) { TEST_F(ParserImplTest, StructDecl_MissingIdent) { auto* p = parser("struct {}"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:8: missing identifier for struct declaration"); @@ -106,7 +91,7 @@ TEST_F(ParserImplTest, StructDecl_MissingIdent) { TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) { auto* p = parser("struct S }"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:10: missing { for struct declaration"); @@ -114,7 +99,7 @@ TEST_F(ParserImplTest, StructDecl_MissingBracketLeft) { TEST_F(ParserImplTest, StructDecl_InvalidStructBody) { auto* p = parser("struct S { a : B; }"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:16: unknown constructed type 'B'"); @@ -122,7 +107,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructBody) { TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { auto* p = parser("[[block struct S { a : i32; }"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:9: missing ]] for struct decoration"); @@ -130,7 +115,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructDecorationDecl) { TEST_F(ParserImplTest, StructDecl_MissingStruct) { auto* p = parser("[[block]] S {}"); - auto s = p->struct_decl(""); + auto s = p->struct_decl(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(s, nullptr); EXPECT_EQ(p->error(), "1:11: missing struct declaration"); diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index 4977b0b3e9..72d50126c5 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -89,59 +89,6 @@ TEST_F(ParserImplTest, TypeDecl_InvalidType) { EXPECT_EQ(p->error(), "1:10: unknown constructed type 'B'"); } -TEST_F(ParserImplTest, TypeDecl_ParsesStruct) { - auto* p = parser("type a = struct { b: i32; c: f32;}"); - auto* t = p->type_alias(); - ASSERT_FALSE(p->has_error()); - ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->IsStruct()); - auto* str = t->AsStruct(); - EXPECT_EQ(str->name(), "a"); - EXPECT_EQ(str->impl()->members().size(), 2u); -} - -TEST_F(ParserImplTest, TypeDecl_InvalidStruct) { - auto* p = parser("type a = [[block]] {}"); - auto* t = p->type_alias(); - ASSERT_TRUE(p->has_error()); - ASSERT_EQ(t, nullptr); - EXPECT_EQ(p->error(), "1:20: missing struct declaration"); -} - -TEST_F(ParserImplTest, TypeDecl_Struct_WithStride) { - auto* p = parser( - "type a = [[block]] struct { [[offset(0)]] data: [[stride(4)]] " - "array; " - "}"); - auto* t = p->type_alias(); - ASSERT_FALSE(p->has_error()); - ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->IsStruct()); - auto* str = t->AsStruct(); - EXPECT_EQ(str->name(), "a"); - EXPECT_EQ(str->impl()->members().size(), 1u); - - const auto* ty = str->impl()->members()[0]->type(); - ASSERT_TRUE(ty->IsArray()); - const auto* arr = ty->AsArray(); - EXPECT_TRUE(arr->has_array_stride()); - EXPECT_EQ(arr->array_stride(), 4u); -} - -TEST_F(ParserImplTest, TypeDecl_Struct_Empty) { - auto* p = parser("type str = struct {};"); - p->global_decl(); - ASSERT_FALSE(p->has_error()) << p->error(); - - auto module = p->module(); - ASSERT_EQ(module.constructed_types().size(), 1u); - - ASSERT_TRUE(module.constructed_types()[0]->IsStruct()); - auto* str = module.constructed_types()[0]->AsStruct(); - EXPECT_EQ(str->name(), "str"); - EXPECT_EQ(str->impl()->members().size(), 0u); -} - } // namespace } // namespace wgsl } // namespace reader diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 166f2f76c3..70a1cb4df1 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -202,22 +202,22 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, if (ty->IsAlias()) { auto* alias = ty->AsAlias(); - // This will go away once type_alias doesn't accept anonymous - // structs anymore - if (alias->type()->IsStruct() && - alias->type()->AsStruct()->name() == alias->name()) { - if (!EmitStructType(out, alias->type()->AsStruct())) { + // HLSL typedef is for intrinsic types only. For an alias'd struct, + // generate a secondary struct with the new name. + if (alias->type()->IsStruct()) { + if (!EmitStructType(out, alias->type()->AsStruct(), alias->name())) { return false; } - } else { - out << "typedef "; - if (!EmitType(out, alias->type(), "")) { - return false; - } - out << " " << namer_.NameFor(alias->name()) << ";" << std::endl; + return true; } + out << "typedef "; + if (!EmitType(out, alias->type(), "")) { + return false; + } + out << " " << namer_.NameFor(alias->name()) << ";" << std::endl; } else if (ty->IsStruct()) { - if (!EmitStructType(out, ty->AsStruct())) { + auto* str = ty->AsStruct(); + if (!EmitStructType(out, str, str->name())) { return false; } } else { @@ -1975,11 +1975,12 @@ bool GeneratorImpl::EmitType(std::ostream& out, } bool GeneratorImpl::EmitStructType(std::ostream& out, - const ast::type::StructType* str) { + const ast::type::StructType* str, + const std::string& name) { // TODO(dsinclair): Block decoration? // if (str->impl()->decoration() != ast::StructDecoration::kNone) { // } - out << "struct " << str->name() << " {" << std::endl; + out << "struct " << name << " {" << std::endl; increment_indent(); for (const auto& mem : str->impl()->members()) { diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 219a613c5d..9f3529a37b 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -264,8 +264,11 @@ class GeneratorImpl { /// Handles generating a structure declaration /// @param out the output stream /// @param ty the struct to generate + /// @param name the struct name /// @returns true if the struct is emitted - bool EmitStructType(std::ostream& out, const ast::type::StructType* ty); + bool EmitStructType(std::ostream& out, + const ast::type::StructType* ty, + const std::string& name); /// Handles a unary op expression /// @param pre the preamble for the expression stream /// @param out the output of the expression stream diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index aa4c4ad0f4..e878b44fe9 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -63,13 +63,13 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) { auto str = std::make_unique(); str->set_members(std::move(members)); - ast::type::StructType s("a", std::move(str)); - ast::type::AliasType alias("a", &s); + ast::type::StructType s("A", std::move(str)); + ast::type::AliasType alias("B", &s); ast::Module m; GeneratorImpl g(&m); ASSERT_TRUE(gen().EmitConstructedType(out(), &alias)) << gen().error(); - EXPECT_EQ(result(), R"(struct a { + EXPECT_EQ(result(), R"(struct B { float a; int b; }; diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 25589178f8..a5cae3e840 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -32,7 +32,6 @@ #include "src/ast/stage_decoration.h" #include "src/ast/struct.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/alias_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" @@ -310,13 +309,12 @@ TEST_F(HlslGeneratorImplTest_Function, str->set_members(std::move(members)); ast::type::StructType s("Uniforms", std::move(str)); - auto alias = std::make_unique("Uniforms", &s); auto coord_var = std::make_unique(std::make_unique( - "uniforms", ast::StorageClass::kUniform, alias.get())); + "uniforms", ast::StorageClass::kUniform, &s)); - mod()->AddConstructedType(alias.get()); + mod()->AddConstructedType(&s); ast::VariableDecorationList decos; decos.push_back(std::make_unique(0)); diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 716ed7c827..62c7bae718 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -181,7 +181,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) { ast::type::StructType s("S", std::move(str)); - ASSERT_TRUE(gen().EmitStructType(out(), &s)) << gen().error(); + ASSERT_TRUE(gen().EmitStructType(out(), &s, "S")) << gen().error(); EXPECT_EQ(result(), R"(struct S { int a; float b; @@ -263,7 +263,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { ast::type::StructType s("S", std::move(str)); - ASSERT_TRUE(gen().EmitStructType(out(), &s)) << gen().error(); + ASSERT_TRUE(gen().EmitStructType(out(), &s, "S")) << gen().error(); EXPECT_EQ(result(), R"(struct S { int double_tint_0; float float_tint_0; @@ -293,8 +293,8 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) { ast::type::StructType s("S", std::move(str)); - ASSERT_TRUE(gen().EmitStructType(out(), &s)) << gen().error(); - EXPECT_EQ(result(), R"(struct S { + ASSERT_TRUE(gen().EmitStructType(out(), &s, "B")) << gen().error(); + EXPECT_EQ(result(), R"(struct B { int a; float b; })"); diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 0771d41323..fd710de89c 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -245,19 +245,11 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { if (ty->IsAlias()) { auto* alias = ty->AsAlias(); - // This will go away once type_alias does not accept anonymous structs - if (alias->type()->IsStruct() && - alias->type()->AsStruct()->name() == alias->name()) { - if (!EmitStructType(alias->type()->AsStruct())) { - return false; - } - } else { - out_ << "typedef "; - if (!EmitType(alias->type(), "")) { - return false; - } - out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl; + out_ << "typedef "; + if (!EmitType(alias->type(), "")) { + return false; } + out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl; } else if (ty->IsStruct()) { if (!EmitStructType(ty->AsStruct())) { return false; diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index 0eec82f2a5..1003694a1a 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -80,35 +80,6 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) { )"); } -TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasMatchStruct) { - ast::type::I32Type i32; - ast::type::F32Type f32; - - ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &f32, ast::StructMemberDecorationList{})); - - ast::StructMemberDecorationList b_deco; - b_deco.push_back(std::make_unique(4)); - members.push_back( - std::make_unique("b", &i32, std::move(b_deco))); - - auto str = std::make_unique(); - str->set_members(std::move(members)); - - ast::type::StructType s("a", std::move(str)); - ast::type::AliasType alias("a", &s); - - ast::Module m; - GeneratorImpl g(&m); - ASSERT_TRUE(g.EmitConstructedType(&alias)) << g.error(); - EXPECT_EQ(g.result(), R"(struct a { - float a; - int b; -}; -)"); -} - TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) { ast::type::I32Type i32; ast::type::F32Type f32; diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index f820017e72..a732b00025 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -168,21 +168,11 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { make_indent(); if (ty->IsAlias()) { auto* alias = ty->AsAlias(); - // Emitting an alias to a struct where the names are the same means we can - // skip emitting the alias and just emit the struct. This will go away once - // the anonymous structs are removed from the type alias - if (alias->type()->IsStruct() && - alias->type()->AsStruct()->name() == alias->name()) { - if (!EmitStructType(alias->type()->AsStruct())) { - return false; - } - } else { - out_ << "type " << alias->name() << " = "; - if (!EmitType(alias->type())) { - return false; - } - out_ << ";" << std::endl; + out_ << "type " << alias->name() << " = "; + if (!EmitType(alias->type())) { + return false; } + out_ << ";" << std::endl; } else if (ty->IsStruct()) { if (!EmitStructType(ty->AsStruct())) { return false; diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index 4b0d69a7f6..c16d043c06 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -39,7 +39,7 @@ TEST_F(WgslGeneratorImplTest, EmitAliasType_F32) { )"); } -TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct_Ident) { +TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -70,8 +70,7 @@ type B = A; )"); } -// This should go away once type_alias'd anonymous structs are removed. -TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct) { +TEST_F(WgslGeneratorImplTest, EmitAliasType_ToStruct) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -88,15 +87,11 @@ TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct) { str->set_members(std::move(members)); ast::type::StructType s("A", std::move(str)); - ast::type::AliasType alias("A", &s); + ast::type::AliasType alias("B", &s); GeneratorImpl g; ASSERT_TRUE(g.EmitConstructedType(&alias)) << g.error(); - EXPECT_EQ(g.result(), R"(struct A { - a : f32; - [[offset(4)]] - b : i32; -}; + EXPECT_EQ(g.result(), R"(type B = A; )"); }