mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
tint::ProgramBuilder: Simplify variable constructors
Expand the Option argument paradigm to:
* Remove the requirement to always pass a 'type' parameter. Type inferencing is the easier, and increasingly common way to declare a variable, so this prevents a whole lot of `nullptr` smell which negatively impacts readability.
* Accept attributes directly as arguments, removing the `utils::Vector{ ... }` smell.
Rename `ProgramBuilder::VarOptionals` to `VarOptions`, and add equivalent `LetOptions`, `ConstOptions` and `OverrideOptions`.
Clean up all the calls to `Var()`, `Let()`, `Const()` and `Override()`:
* Use the `Group()` and `Binding()` helpers where possible
* Removing `nullptr` type arguments
* Replace attribute vectors with the list of attributes.
* Remove already-defaulted `ast::StorageClass::kNone` arguments.
* Remove already-defaulted `ast::Access::kUndefined` arguments.
Finally, remove the `GroupAndBinding()` helper, which only existed because you needed to pass attributes as a vector.
Change-Id: I8890e4eb0ffac9f9df2207b28a6f02a163e34d96
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99580
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
fa289d3a83
commit
58794ae118
@@ -22,12 +22,12 @@ namespace {
|
||||
using OverrideTest = TestHelper;
|
||||
|
||||
TEST_F(OverrideTest, Identifier_NoId) {
|
||||
auto* o = Override("o", nullptr, Expr(f32(1.0)));
|
||||
auto* o = Override("o", Expr(f32(1.0)));
|
||||
EXPECT_EQ(std::string("o"), o->Identifier(Symbols()));
|
||||
}
|
||||
|
||||
TEST_F(OverrideTest, Identifier_WithId) {
|
||||
auto* o = Override("o", nullptr, Expr(f32(1.0)), utils::Vector{Id(4u)});
|
||||
auto* o = Override("o", Expr(f32(1.0)), Id(4u));
|
||||
EXPECT_EQ(std::string("4"), o->Identifier(Symbols()));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace {
|
||||
using VariableDeclStatementTest = TestHelper;
|
||||
|
||||
TEST_F(VariableDeclStatementTest, Creation) {
|
||||
auto* var = Var("a", ty.f32(), StorageClass::kNone);
|
||||
auto* var = Var("a", ty.f32());
|
||||
|
||||
auto* stmt = create<VariableDeclStatement>(var);
|
||||
EXPECT_EQ(stmt->variable, var);
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||
auto* var = Var("a", ty.f32(), StorageClass::kNone);
|
||||
auto* var = Var("a", ty.f32());
|
||||
|
||||
auto* stmt = create<VariableDeclStatement>(Source{Source::Location{20, 2}}, var);
|
||||
auto src = stmt->source;
|
||||
@@ -39,7 +39,7 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||
auto* var = Var("a", ty.f32(), StorageClass::kNone);
|
||||
auto* var = Var("a", ty.f32());
|
||||
|
||||
auto* stmt = create<VariableDeclStatement>(var);
|
||||
EXPECT_TRUE(stmt->Is<VariableDeclStatement>());
|
||||
@@ -59,7 +59,7 @@ TEST_F(VariableDeclStatementTest, Assert_DifferentProgramID_Variable) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<VariableDeclStatement>(b2.Var("a", b2.ty.f32(), StorageClass::kNone));
|
||||
b1.create<VariableDeclStatement>(b2.Var("a", b2.ty.f32()));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_F(VariableTest, Creation) {
|
||||
|
||||
TEST_F(VariableTest, CreationWithSource) {
|
||||
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
|
||||
ty.f32(), StorageClass::kPrivate, nullptr, utils::Empty);
|
||||
ty.f32(), StorageClass::kPrivate, utils::Empty);
|
||||
|
||||
EXPECT_EQ(v->symbol, Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class, StorageClass::kPrivate);
|
||||
@@ -51,7 +51,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||
|
||||
TEST_F(VariableTest, CreationEmpty) {
|
||||
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
|
||||
ty.i32(), StorageClass::kWorkgroup, nullptr, utils::Empty);
|
||||
ty.i32(), StorageClass::kWorkgroup, utils::Empty);
|
||||
|
||||
EXPECT_EQ(v->symbol, Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class, StorageClass::kWorkgroup);
|
||||
@@ -66,7 +66,7 @@ TEST_F(VariableTest, Assert_MissingSymbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Var("", b.ty.i32(), StorageClass::kNone);
|
||||
b.Var("", b.ty.i32());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -76,7 +76,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Symbol) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Var(b2.Sym("x"), b1.ty.f32(), StorageClass::kNone);
|
||||
b1.Var(b2.Sym("x"), b1.ty.f32());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
@@ -86,18 +86,14 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Var("x", b1.ty.f32(), StorageClass::kNone, b2.Expr(1.2_f));
|
||||
b1.Var("x", b1.ty.f32(), b2.Expr(1.2_f));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, WithAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
utils::Vector{
|
||||
create<LocationAttribute>(1u),
|
||||
create<BuiltinAttribute>(BuiltinValue::kPosition),
|
||||
create<IdAttribute>(1200u),
|
||||
});
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Location(1u),
|
||||
Builtin(BuiltinValue::kPosition), Id(1200u));
|
||||
|
||||
auto& attributes = var->attributes;
|
||||
EXPECT_TRUE(ast::HasAttribute<ast::LocationAttribute>(attributes));
|
||||
@@ -110,11 +106,7 @@ TEST_F(VariableTest, WithAttributes) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, BindingPoint) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
utils::Vector{
|
||||
create<BindingAttribute>(2u),
|
||||
create<GroupAttribute>(1u),
|
||||
});
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2), Group(1));
|
||||
EXPECT_TRUE(var->BindingPoint());
|
||||
ASSERT_NE(var->BindingPoint().binding, nullptr);
|
||||
ASSERT_NE(var->BindingPoint().group, nullptr);
|
||||
@@ -123,17 +115,14 @@ TEST_F(VariableTest, BindingPoint) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, BindingPointAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr, utils::Empty);
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, utils::Empty);
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
EXPECT_EQ(var->BindingPoint().group, nullptr);
|
||||
EXPECT_EQ(var->BindingPoint().binding, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, BindingPointMissingGroupAttribute) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
utils::Vector{
|
||||
create<BindingAttribute>(2u),
|
||||
});
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2));
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
ASSERT_NE(var->BindingPoint().binding, nullptr);
|
||||
EXPECT_EQ(var->BindingPoint().binding->value, 2u);
|
||||
@@ -141,8 +130,7 @@ TEST_F(VariableTest, BindingPointMissingGroupAttribute) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, BindingPointMissingBindingAttribute) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, nullptr,
|
||||
utils::Vector{create<GroupAttribute>(1u)});
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Group(1));
|
||||
EXPECT_FALSE(var->BindingPoint());
|
||||
ASSERT_NE(var->BindingPoint().group, nullptr);
|
||||
EXPECT_EQ(var->BindingPoint().group->value, 1u);
|
||||
|
||||
Reference in New Issue
Block a user