[spirv-reader] Simplify null composites
Use the shortcut for zero-values: a type constructor without
any parameters. Scalars still use plain literals like false, 1u, 1.0.
Change-Id: Ie436f1af28cbab0b4c87a07b057deb04632eb534
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23680
Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/src/reader/spirv/function_misc_test.cc b/src/reader/spirv/function_misc_test.cc
index 3cb8ddfc..56f4da0 100644
--- a/src/reader/spirv/function_misc_test.cc
+++ b/src/reader/spirv/function_misc_test.cc
@@ -135,8 +135,6 @@
{
TypeConstructor{
__vec_2__u32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
}
@@ -149,8 +147,6 @@
{
TypeConstructor{
__vec_2__i32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
}
@@ -163,8 +159,6 @@
{
TypeConstructor{
__vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
}
}
}
@@ -195,16 +189,6 @@
{
TypeConstructor{
__mat_2_2__f32
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
}
}
}
@@ -236,8 +220,6 @@
{
TypeConstructor{
__array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
}
@@ -268,10 +250,6 @@
{
TypeConstructor{
__alias_S__struct_S
- ScalarConstructor{false}
- ScalarConstructor{0}
- ScalarConstructor{0}
- ScalarConstructor{0.000000}
}
}
}
diff --git a/src/reader/spirv/function_var_test.cc b/src/reader/spirv/function_var_test.cc
index dd9f283..0a97ef5 100644
--- a/src/reader/spirv/function_var_test.cc
+++ b/src/reader/spirv/function_var_test.cc
@@ -492,8 +492,6 @@
{
TypeConstructor{
__array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
}
@@ -526,8 +524,6 @@
{
TypeConstructor{
__alias_Arr__array__u32_2_16
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
}
@@ -599,13 +595,6 @@
{
TypeConstructor{
__alias_S__struct_S
- ScalarConstructor{0}
- ScalarConstructor{0.000000}
- TypeConstructor{
- __array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
- }
}
}
}
diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc
index 4ad72ee..5a42b77 100644
--- a/src/reader/spirv/parser_impl.cc
+++ b/src/reader/spirv/parser_impl.cc
@@ -38,6 +38,7 @@
#include "src/ast/bool_literal.h"
#include "src/ast/builtin_decoration.h"
#include "src/ast/decorated_variable.h"
+#include "src/ast/expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
@@ -969,10 +970,6 @@
std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
ast::type::Type* type) {
- // TODO(dneto): Use the no-operands constructor syntax when it becomes
- // available in Tint.
- // https://github.com/gpuweb/gpuweb/issues/685
- // https://bugs.chromium.org/p/tint/issues/detail?id=34
if (!type) {
Fail() << "trying to create null value for a null type";
@@ -998,45 +995,10 @@
return std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(type, 0.0f));
}
- if (type->IsVector()) {
- const auto* vec_ty = type->AsVector();
- ast::ExpressionList ast_components;
- for (size_t i = 0; i < vec_ty->size(); ++i) {
- ast_components.emplace_back(MakeNullValue(vec_ty->type()));
- }
+ if (type->IsVector() || type->IsMatrix() || type->IsArray() ||
+ type->IsStruct()) {
return std::make_unique<ast::TypeConstructorExpression>(
- type, std::move(ast_components));
- }
- if (type->IsMatrix()) {
- const auto* mat_ty = type->AsMatrix();
- // Matrix components are columns
- auto* column_ty =
- ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
- mat_ty->type(), mat_ty->rows()));
- ast::ExpressionList ast_components;
- for (size_t i = 0; i < mat_ty->columns(); ++i) {
- ast_components.emplace_back(MakeNullValue(column_ty));
- }
- return std::make_unique<ast::TypeConstructorExpression>(
- type, std::move(ast_components));
- }
- if (type->IsArray()) {
- auto* arr_ty = type->AsArray();
- ast::ExpressionList ast_components;
- for (size_t i = 0; i < arr_ty->size(); ++i) {
- ast_components.emplace_back(MakeNullValue(arr_ty->type()));
- }
- return std::make_unique<ast::TypeConstructorExpression>(
- original_type, std::move(ast_components));
- }
- if (type->IsStruct()) {
- auto* struct_ty = type->AsStruct();
- ast::ExpressionList ast_components;
- for (auto& member : struct_ty->impl()->members()) {
- ast_components.emplace_back(MakeNullValue(member->type()));
- }
- return std::make_unique<ast::TypeConstructorExpression>(
- original_type, std::move(ast_components));
+ original_type, ast::ExpressionList{});
}
Fail() << "can't make null value for type: " << type->type_name();
return nullptr;
diff --git a/src/reader/spirv/parser_impl_module_var_test.cc b/src/reader/spirv/parser_impl_module_var_test.cc
index b0c9d00..d4c5b87 100644
--- a/src/reader/spirv/parser_impl_module_var_test.cc
+++ b/src/reader/spirv/parser_impl_module_var_test.cc
@@ -382,8 +382,6 @@
{
TypeConstructor{
__vec_2__bool
- ScalarConstructor{false}
- ScalarConstructor{false}
}
}
})"));
@@ -405,8 +403,6 @@
{
TypeConstructor{
__vec_2__bool
- ScalarConstructor{false}
- ScalarConstructor{false}
}
}
})"));
@@ -428,8 +424,6 @@
{
TypeConstructor{
__vec_2__u32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -451,8 +445,6 @@
{
TypeConstructor{
__vec_2__u32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -474,8 +466,6 @@
{
TypeConstructor{
__vec_2__i32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -497,8 +487,6 @@
{
TypeConstructor{
__vec_2__i32
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -520,8 +508,6 @@
{
TypeConstructor{
__vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
}
}
})"));
@@ -543,8 +529,6 @@
{
TypeConstructor{
__vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
}
}
})"));
@@ -608,21 +592,6 @@
{
TypeConstructor{
__mat_2_3__f32
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
}
}
})"));
@@ -644,21 +613,6 @@
{
TypeConstructor{
__mat_2_3__f32
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
- TypeConstructor{
- __vec_2__f32
- ScalarConstructor{0.000000}
- ScalarConstructor{0.000000}
- }
}
}
})"));
@@ -704,8 +658,6 @@
{
TypeConstructor{
__array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -727,8 +679,6 @@
{
TypeConstructor{
__array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
}
}
})"));
@@ -781,13 +731,6 @@
{
TypeConstructor{
__alias_S__struct_S
- ScalarConstructor{0}
- ScalarConstructor{0.000000}
- TypeConstructor{
- __array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
- }
}
}
})"))
@@ -810,13 +753,6 @@
{
TypeConstructor{
__alias_S__struct_S
- ScalarConstructor{0}
- ScalarConstructor{0.000000}
- TypeConstructor{
- __array__u32_2
- ScalarConstructor{0}
- ScalarConstructor{0}
- }
}
}
})"))