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

@@ -107,14 +107,12 @@ class InspectorHelper : public ProgramBuilder {
std::string in, out;
std::tie(in, out) = inout;
AST().AddGlobalVariable(
Var(in, ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)}));
AST().AddGlobalVariable(
Var(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)}));
Global(in, ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)});
Global(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)});
}
}
@@ -175,11 +173,10 @@ class InspectorHelper : public ProgramBuilder {
constructor =
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
}
auto* var = Const(name, ast::StorageClass::kNone, type, constructor,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(id),
});
AST().AddGlobalVariable(var);
GlobalConst(name, ast::StorageClass::kNone, type, constructor,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(id),
});
}
/// @param type AST type of the literal, must resolve to BoolLiteral
@@ -320,13 +317,11 @@ class InspectorHelper : public ProgramBuilder {
ast::StorageClass storage_class,
uint32_t group,
uint32_t binding) {
auto* var = Var(name, storage_class, type, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(binding),
create<ast::GroupDecoration>(group),
});
AST().AddGlobalVariable(var);
GlobalConst(name, storage_class, type, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(binding),
create<ast::GroupDecoration>(group),
});
}
/// Adds an uniform buffer variable to the program
@@ -460,16 +455,14 @@ class InspectorHelper : public ProgramBuilder {
}
void AddGlobalVariable(const std::string& name, type::Type* type) {
AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type));
Global(name, ast::StorageClass::kUniformConstant, type);
}
/// Adds a depth texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
void AddDepthTexture(const std::string& name, type::Type* type) {
AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type));
Global(name, ast::StorageClass::kUniformConstant, type);
}
/// Generates a function that references a specific sampler variable
@@ -1104,13 +1097,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
}
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
AST().AddGlobalVariable(
Var("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}));
AST().AddGlobalVariable(
Var("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}));
Global("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Global("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});