Program: Remove deprecated constructed-type methods

Fixup all usages

Bug: tint:390
Change-Id: I739a7625cd385cb889369ab7c766462fbcd7cf12
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38546
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-26 16:57:10 +00:00
parent a86f4effe4
commit 1b3d6e460c
17 changed files with 55 additions and 67 deletions

View File

@ -118,18 +118,6 @@ class Program {
return types_.Get<T>(std::forward<ARGS>(args)...);
}
/// Adds a constructed type to the program.
/// The type must be an alias or a struct.
/// [DEPRECATED]: Use AST().AddConstructedType(type)
/// @param type the constructed type to add
void AddConstructedType(type::Type* type) { AST().AddConstructedType(type); }
/// @returns the constructed types in the program
/// [DEPRECATED]: Use AST().ConstructedTypes()
const std::vector<type::Type*>& constructed_types() const {
return AST().ConstructedTypes();
}
/// @returns the functions declared in the translation unit
/// [DEPRECATED]: Use AST().Functions()
const ast::FunctionList& Functions() const { return AST().Functions(); }

View File

@ -63,26 +63,26 @@ TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
TEST_F(ProgramTest, IsValid_Alias) {
auto* alias = ty.alias("alias", ty.f32);
mod->AddConstructedType(alias);
mod->AST().AddConstructedType(alias);
EXPECT_TRUE(mod->IsValid());
}
TEST_F(ProgramTest, IsValid_Null_Alias) {
mod->AddConstructedType(nullptr);
mod->AST().AddConstructedType(nullptr);
EXPECT_FALSE(mod->IsValid());
}
TEST_F(ProgramTest, IsValid_Struct) {
auto* st = ty.struct_("name", {});
auto* alias = ty.alias("name", st);
mod->AddConstructedType(alias);
mod->AST().AddConstructedType(alias);
EXPECT_TRUE(mod->IsValid());
}
TEST_F(ProgramTest, IsValid_Struct_EmptyName) {
auto* st = ty.struct_("", {});
auto* alias = ty.alias("name", st);
mod->AddConstructedType(alias);
mod->AST().AddConstructedType(alias);
EXPECT_FALSE(mod->IsValid());
}

View File

@ -969,7 +969,7 @@ type::Type* ParserImpl::ConvertType(
if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result);
}
program_.AddConstructedType(result);
program_.AST().AddConstructedType(result);
return result;
}
@ -1133,7 +1133,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
program_.RegisterSymbol(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type;
program_.AddConstructedType(ast_alias_type);
program_.AST().AddConstructedType(ast_alias_type);
}
bool ParserImpl::EmitModuleScopeVariables() {

View File

@ -347,7 +347,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("type alias", Token::Type::kSemicolon))
return Failure::kErrored;
program_.AddConstructedType(ta.value);
program_.AST().AddConstructedType(ta.value);
return true;
}
@ -362,7 +362,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
auto* type = str.value;
register_constructed(
program_.SymbolToName(type->As<type::Struct>()->symbol()), type);
program_.AddConstructedType(type);
program_.AST().AddConstructedType(type);
return true;
}

View File

@ -87,10 +87,10 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program();
ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_TRUE(m.constructed_types()[0]->Is<type::Alias>());
EXPECT_EQ(
m.SymbolToName(m.constructed_types()[0]->As<type::Alias>()->symbol()),
ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u);
ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Alias>());
EXPECT_EQ(m.SymbolToName(
m.AST().ConstructedTypes()[0]->As<type::Alias>()->symbol()),
"A");
}
@ -104,13 +104,13 @@ type B = A;)");
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program();
ASSERT_EQ(m.constructed_types().size(), 2u);
ASSERT_TRUE(m.constructed_types()[0]->Is<type::Struct>());
auto* str = m.constructed_types()[0]->As<type::Struct>();
ASSERT_EQ(m.AST().ConstructedTypes().size(), 2u);
ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Struct>());
auto* str = m.AST().ConstructedTypes()[0]->As<type::Struct>();
EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A"));
ASSERT_TRUE(m.constructed_types()[1]->Is<type::Alias>());
auto* alias = m.constructed_types()[1]->As<type::Alias>();
ASSERT_TRUE(m.AST().ConstructedTypes()[1]->Is<type::Alias>());
auto* alias = m.AST().ConstructedTypes()[1]->As<type::Alias>();
EXPECT_EQ(alias->symbol(), p->get_program().RegisterSymbol("B"));
EXPECT_EQ(alias->type(), str);
}
@ -162,9 +162,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program();
ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u);
auto* t = m.constructed_types()[0];
auto* t = m.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());
@ -181,9 +181,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program();
ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u);
auto* t = m.constructed_types()[0];
auto* t = m.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());
@ -205,9 +205,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program();
ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u);
auto* t = m.constructed_types()[0];
auto* t = m.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::Struct>());

View File

@ -242,7 +242,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) {
dst->AST().AddGlobalVariable(idx_var);
dst->AddConstructedType(struct_type);
dst->AST().AddConstructedType(struct_type);
return idx_var;
}

View File

@ -301,7 +301,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
});
out->AST().AddGlobalVariable(var);
}
out->AddConstructedType(struct_type);
out->AST().AddConstructedType(struct_type);
}
ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {

View File

@ -375,7 +375,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
mod->AddConstructedType(my_int);
mod->AST().AddConstructedType(my_int);
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();

View File

@ -68,7 +68,7 @@ bool ValidatorImpl::Validate() {
if (!ValidateGlobalVariables(program_->AST().GlobalVariables())) {
return false;
}
if (!ValidateConstructedTypes(program_->constructed_types())) {
if (!ValidateConstructedTypes(program_->AST().ConstructedTypes())) {
return false;
}
if (!ValidateFunctions(program_->Functions())) {

View File

@ -51,11 +51,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(struct_type);
mod->AST().AddConstructedType(struct_type);
ValidatorImpl& v = Build();
EXPECT_TRUE(v.ValidateConstructedTypes(mod->constructed_types()));
EXPECT_TRUE(v.ValidateConstructedTypes(mod->AST().ConstructedTypes()));
}
TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
@ -71,11 +71,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsLastNoBlock_Fail) {
decos);
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(struct_type);
mod->AST().AddConstructedType(struct_type);
ValidatorImpl& v = Build();
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
EXPECT_FALSE(v.ValidateConstructedTypes(mod->AST().ConstructedTypes()));
EXPECT_EQ(v.error(),
"v-0031: a struct containing a runtime-sized array must be "
"in the 'storage' storage class: 'Foo'");
@ -99,11 +99,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayIsNotLast_Fail) {
auto* struct_type = ty.struct_("Foo", st);
mod->AddConstructedType(struct_type);
mod->AST().AddConstructedType(struct_type);
ValidatorImpl& v = Build();
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
EXPECT_FALSE(v.ValidateConstructedTypes(mod->AST().ConstructedTypes()));
EXPECT_EQ(v.error(),
"12:34 v-0015: runtime arrays may only appear as the last member "
"of a struct");
@ -125,11 +125,11 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
ast::StructMemberList{Member("b", alias), Member("a", ty.u32)}, decos);
auto* struct_type = ty.struct_("s", st);
mod->AddConstructedType(struct_type);
mod->AST().AddConstructedType(struct_type);
ValidatorImpl& v = Build();
EXPECT_FALSE(v.ValidateConstructedTypes(mod->constructed_types()));
EXPECT_FALSE(v.ValidateConstructedTypes(mod->AST().ConstructedTypes()));
EXPECT_EQ(v.error(),
"v-0015: runtime arrays may only appear as the last member "
"of a struct");
@ -151,11 +151,11 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
ast::StructMemberList{Member("a", ty.u32), Member("b", alias)}, decos);
auto* struct_type = ty.struct_("s", st);
mod->AddConstructedType(struct_type);
mod->AST().AddConstructedType(struct_type);
ValidatorImpl& v = Build();
EXPECT_TRUE(v.ValidateConstructedTypes(mod->constructed_types()));
EXPECT_TRUE(v.ValidateConstructedTypes(mod->AST().ConstructedTypes()));
}
TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {

View File

@ -140,12 +140,12 @@ bool GeneratorImpl::Generate(std::ostream& out) {
register_global(global);
}
for (auto* const ty : program_->constructed_types()) {
for (auto* const ty : program_->AST().ConstructedTypes()) {
if (!EmitConstructedType(out, ty)) {
return false;
}
}
if (!program_->constructed_types().empty()) {
if (!program_->AST().ConstructedTypes().empty()) {
out << std::endl;
}

View File

@ -358,7 +358,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::GroupDecoration>(1),
});
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
td.RegisterVariableForTesting(coord_var);
mod->AST().AddGlobalVariable(coord_var);
@ -1053,7 +1053,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::GroupDecoration>(0),
});
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
mod->AST().AddGlobalVariable(data_var);

View File

@ -119,12 +119,12 @@ bool GeneratorImpl::Generate() {
global_variables_.set(global->symbol(), global);
}
for (auto* const ty : program_->constructed_types()) {
for (auto* const ty : program_->AST().ConstructedTypes()) {
if (!EmitConstructedType(ty)) {
return false;
}
}
if (!program_->constructed_types().empty()) {
if (!program_->AST().ConstructedTypes().empty()) {
out_ << std::endl;
}

View File

@ -350,7 +350,7 @@ TEST_F(MslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
@ -405,7 +405,7 @@ TEST_F(MslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
@ -722,7 +722,7 @@ TEST_F(MslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
@ -791,7 +791,7 @@ TEST_F(MslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
@ -986,7 +986,7 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0)});
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
mod->AST().AddGlobalVariable(data_var);

View File

@ -242,7 +242,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
create<ast::GroupDecoration>(0),
});
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
mod->AST().AddGlobalVariable(data_var);

View File

@ -84,12 +84,12 @@ GeneratorImpl::GeneratorImpl(const Program* program)
GeneratorImpl::~GeneratorImpl() = default;
bool GeneratorImpl::Generate() {
for (auto* const ty : program_->constructed_types()) {
for (auto* const ty : program_->AST().ConstructedTypes()) {
if (!EmitConstructedType(ty)) {
return false;
}
}
if (!program_->constructed_types().empty())
if (!program_->AST().ConstructedTypes().empty())
out_ << std::endl;
for (auto* var : program_->AST().GlobalVariables()) {
@ -121,12 +121,12 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
// TODO(dsinclair): We always emit constructed types even if they aren't
// strictly needed
for (auto* const ty : program_->constructed_types()) {
for (auto* const ty : program_->AST().ConstructedTypes()) {
if (!EmitConstructedType(ty)) {
return false;
}
}
if (!program_->constructed_types().empty()) {
if (!program_->AST().ConstructedTypes().empty()) {
out_ << std::endl;
}

View File

@ -191,7 +191,7 @@ TEST_F(WgslGeneratorImplTest,
create<ast::GroupDecoration>(0),
});
mod->AddConstructedType(s);
mod->AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
mod->AST().AddGlobalVariable(data_var);