Simplify usage of the TypeDeterminer in tests

Make private all TypeDeterminer::DetermineXXX() methods, forcing all tests to use the root-level TypeDeterminer::Determine() method.
Remove TypeDeterminer::RegisterVariableForTesting().

The main use for calling the TypeDeterminer::DetermineXXX() methods was to perform type determination on a partial AST.
This was messy and often resulting in multiple calls into TypeDeterminer. Most tests already perform a full TypeDeterminer::Determine() call when the program is built, so many of these were redundant.
The exposure of these internal methods for testing also makes refactoring the TypeDeterminer extremely difficult.

Add a number of ProgramBuilder helper methods for attaching the partial AST in these tests to the root of the AST, greatly simplifying the use of the TypeDeterminer:
* ProgramBuilder::Global() and ProgramBuilder::GlobalConst() are helpers that register the variable returned by ProgramBuilder::Var() and ProgramBuilder::Const(), respectively.
* ProgramBuilder::WrapInFunction() is a variadic function that accepts variables, expressions and statements, attaching these to the root of the AST via a dummy function.

Most test classes now no longer use their own TypeDeterminer, and instead properly depend on the automatic type determination performed at Program build time.

Bug: tint:390
Change-Id: Ie901890420c5de170cdf2a7aaef9b96fc3bebd60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40062
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-02-03 17:19:59 +00:00
committed by Commit Bot service account
parent 87c78ddabc
commit 401b96b9bb
59 changed files with 1946 additions and 2388 deletions

View File

@@ -160,18 +160,18 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
};
switch (texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
return b->Var(
return b->Global(
"texture", ast::StorageClass::kUniformConstant,
b->create<type::SampledTexture>(texture_dimension, datatype), nullptr,
decos);
case ast::intrinsic::test::TextureKind::kDepth:
return b->Var("texture", ast::StorageClass::kUniformConstant,
b->create<type::DepthTexture>(texture_dimension), nullptr,
decos);
return b->Global("texture", ast::StorageClass::kUniformConstant,
b->create<type::DepthTexture>(texture_dimension),
nullptr, decos);
case ast::intrinsic::test::TextureKind::kMultisampled:
return b->Var(
return b->Global(
"texture", ast::StorageClass::kUniformConstant,
b->create<type::MultisampledTexture>(texture_dimension, datatype),
nullptr, decos);
@@ -182,8 +182,8 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
st->set_type(datatype);
auto* ac = b->create<type::AccessControl>(access_control, st);
return b->Var("texture", ast::StorageClass::kUniformConstant, ac, nullptr,
decos);
return b->Global("texture", ast::StorageClass::kUniformConstant, ac,
nullptr, decos);
}
}
@@ -197,8 +197,8 @@ ast::Variable* TextureOverloadCase::buildSamplerVariable(
b->create<ast::GroupDecoration>(0),
b->create<ast::BindingDecoration>(1),
};
return b->Var("sampler", ast::StorageClass::kUniformConstant,
b->create<type::Sampler>(sampler_kind), nullptr, decos);
return b->Global("sampler", ast::StorageClass::kUniformConstant,
b->create<type::Sampler>(sampler_kind), nullptr, decos);
}
std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {

View File

@@ -242,10 +242,12 @@ struct TextureOverloadCase {
/// @returns the vector component type of the texture function return value
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test texture
/// @returns a variable holding the test texture, automatically registered as
/// a global variable.
ast::Variable* buildTextureVariable(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test sampler
/// @returns a Variable holding the test sampler, automatically registered as
/// a global variable.
ast::Variable* buildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload

View File

@@ -62,8 +62,7 @@ TEST_F(ModuleTest, IsValid_Empty) {
}
TEST_F(ModuleTest, IsValid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, ty.f32());
AST().AddGlobalVariable(var);
Global("var", StorageClass::kInput, ty.f32());
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
@@ -75,8 +74,7 @@ TEST_F(ModuleTest, IsValid_Null_GlobalVariable) {
}
TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, nullptr);
AST().AddGlobalVariable(var);
Global("var", StorageClass::kInput, nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}