Resolver: make IsConstructible non-recursive for arrays and struct members

Also fix cases of implicit conversions of bool to int when creating
sem::Array.

Bug: tint:917
Change-Id: I5392fb737efc410f039b4dbd96cffc5daa4fd3a2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58783
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Antonio Maiorano
2021-07-20 18:28:31 +00:00
committed by Tint LUCI CQ
parent 701820b1f4
commit 68a6dd0073
24 changed files with 94 additions and 44 deletions

View File

@@ -142,7 +142,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest,
TEST_F(ResolverInferredTypeTest, InferArray_Pass) {
auto* type = ty.array(ty.u32(), 10);
auto* expected_type =
create<sem::Array>(create<sem::U32>(), 10, 4, 4 * 10, 4, true);
create<sem::Array>(create<sem::U32>(), 10, 4, 4 * 10, 4, 4);
auto* ctor_expr = Construct(type);
auto* var = Var("a", nullptr, ast::StorageClass::kFunction, ctor_expr);

View File

@@ -99,12 +99,12 @@ TEST_F(ResolverIsHostShareable, Atomic) {
}
TEST_F(ResolverIsHostShareable, ArraySizedOfHostShareable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 5, 4, 20, 4, true);
auto* arr = create<sem::Array>(create<sem::I32>(), 5, 4, 20, 4, 4);
EXPECT_TRUE(r()->IsHostShareable(arr));
}
TEST_F(ResolverIsHostShareable, ArrayUnsizedOfHostShareable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 0, 4, 4, 4, true);
auto* arr = create<sem::Array>(create<sem::I32>(), 0, 4, 4, 4, 4);
EXPECT_TRUE(r()->IsHostShareable(arr));
}

View File

@@ -74,12 +74,12 @@ TEST_F(ResolverIsStorableTest, Atomic) {
}
TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 5, 4, 20, 4, true);
auto* arr = create<sem::Array>(create<sem::I32>(), 5, 4, 20, 4, 4);
EXPECT_TRUE(r()->IsStorable(arr));
}
TEST_F(ResolverIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 0, 4, 4, 4, true);
auto* arr = create<sem::Array>(create<sem::I32>(), 0, 4, 4, 4, 4);
EXPECT_TRUE(r()->IsStorable(arr));
}

View File

@@ -200,36 +200,6 @@ bool Resolver::IsPlain(const sem::Type* type) const {
type->Is<sem::Array>() || type->Is<sem::Struct>();
}
// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
bool Resolver::IsConstructible(const sem::Type* type) const {
if (type->Is<sem::Atomic>()) {
return false;
}
if (type->is_scalar() || type->Is<sem::Vector>() || type->Is<sem::Matrix>()) {
return true;
}
if (auto* arr = type->As<sem::Array>()) {
if (arr->IsRuntimeSized()) {
return false;
}
return IsConstructible(arr->ElemType());
}
if (auto* str = type->As<sem::Struct>()) {
for (auto* m : str->Members()) {
if (!IsConstructible(m->Type())) {
return false;
}
}
return true;
}
return false;
}
// https://gpuweb.github.io/gpuweb/wgsl.html#storable-types
bool Resolver::IsStorable(const sem::Type* type) const {
return IsPlain(type) || type->Is<sem::Texture>() || type->Is<sem::Sampler>();
@@ -1208,7 +1178,7 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func,
}
if (IsPlain(info->type)) {
if (!IsConstructible(info->type) &&
if (!info->type->IsConstructible() &&
IsValidationEnabled(
info->declaration->decorations(),
ast::DisabledValidation::kIgnoreConstructibleFunctionParameter)) {
@@ -1411,7 +1381,7 @@ bool Resolver::ValidateFunction(const ast::Function* func,
}
if (!info->return_type->Is<sem::Void>()) {
if (!IsConstructible(info->return_type)) {
if (!info->return_type->IsConstructible()) {
AddError("function return type must be a constructible type",
func->return_type()->source());
return false;

View File

@@ -83,10 +83,6 @@ class Resolver {
/// @returns true if the given type is a plain type
bool IsPlain(const sem::Type* type) const;
/// @param type the given type
/// @returns true if the given type is a constructible type
bool IsConstructible(const sem::Type* type) const;
/// @param type the given type
/// @returns true if the given type is storable
bool IsStorable(const sem::Type* type) const;