From 85aed12213f424bbe01b386129ab642f9a0c9f7c Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 26 Aug 2024 19:13:41 +0000 Subject: [PATCH] Rename `HoldsAbstract` to `IsAbstract`. All of the other type methods are `Is*` except for `Abstract` which is `Holds`. This Cl changes `HoldsAbstract` to `IsAbstract`. A vector or matrix with an abstract element is still an abstract vector. Change-Id: I5ee87031ac49dc654a2f1e70e854ab700eac4e2a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203875 Reviewed-by: James Price Commit-Queue: dan sinclair --- src/tint/lang/core/type/type.cc | 10 +-- src/tint/lang/core/type/type.h | 7 +- src/tint/lang/core/type/type_test.cc | 64 +++++++++---------- .../lang/wgsl/ast/transform/fold_constants.cc | 2 +- .../ast/transform/hoist_to_decl_before.cc | 4 +- .../transform/promote_initializers_to_let.cc | 2 +- .../wgsl/ast/transform/substitute_override.cc | 2 +- src/tint/lang/wgsl/resolver/validator.cc | 2 +- 8 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/tint/lang/core/type/type.cc b/src/tint/lang/core/type/type.cc index 807e7653576..dbb50f89128 100644 --- a/src/tint/lang/core/type/type.cc +++ b/src/tint/lang/core/type/type.cc @@ -157,16 +157,16 @@ bool Type::IsHandle() const { return IsAnyOf(); } -bool Type::HoldsAbstract() const { +bool Type::IsAbstract() const { return Switch( this, // [&](const AbstractNumeric*) { return true; }, - [&](const Vector* v) { return v->Type()->HoldsAbstract(); }, - [&](const Matrix* m) { return m->Type()->HoldsAbstract(); }, - [&](const Array* a) { return a->ElemType()->HoldsAbstract(); }, + [&](const Vector* v) { return v->Type()->IsAbstract(); }, + [&](const Matrix* m) { return m->Type()->IsAbstract(); }, + [&](const Array* a) { return a->ElemType()->IsAbstract(); }, [&](const Struct* s) { for (auto* m : s->Members()) { - if (m->Type()->HoldsAbstract()) { + if (m->Type()->IsAbstract()) { return true; } } diff --git a/src/tint/lang/core/type/type.h b/src/tint/lang/core/type/type.h index 4f09d9060f5..5124d768bfb 100644 --- a/src/tint/lang/core/type/type.h +++ b/src/tint/lang/core/type/type.h @@ -163,10 +163,9 @@ class Type : public Castable { bool IsNumericScalarOrVector() const; /// @returns true if this type is a handle type bool IsHandle() const; - - /// @returns true if this type is an abstract-numeric or if the type holds an element that is an - /// abstract-numeric. - bool HoldsAbstract() const; + /// @returns true if this type is an abstract type. It could be a numeric directly or an + /// abstract container which holds an abstract numeric + bool IsAbstract() const; /// kNoConversion is returned from ConversionRank() when the implicit conversion is not /// permitted. diff --git a/src/tint/lang/core/type/type_test.cc b/src/tint/lang/core/type/type_test.cc index f9ac3465757..475f5cea0e9 100644 --- a/src/tint/lang/core/type/type_test.cc +++ b/src/tint/lang/core/type/type_test.cc @@ -524,38 +524,38 @@ TEST_F(TypeTest, Common3) { arr_mat4x3_f16); } -TEST_F(TypeTest, HoldsAbstract) { - EXPECT_TRUE(af->HoldsAbstract()); - EXPECT_TRUE(ai->HoldsAbstract()); - EXPECT_FALSE(f32->HoldsAbstract()); - EXPECT_FALSE(f16->HoldsAbstract()); - EXPECT_FALSE(i32->HoldsAbstract()); - EXPECT_FALSE(u32->HoldsAbstract()); - EXPECT_FALSE(vec2_f32->HoldsAbstract()); - EXPECT_FALSE(vec3_f32->HoldsAbstract()); - EXPECT_FALSE(vec3_f16->HoldsAbstract()); - EXPECT_FALSE(vec4_f32->HoldsAbstract()); - EXPECT_FALSE(vec3_u32->HoldsAbstract()); - EXPECT_FALSE(vec3_i32->HoldsAbstract()); - EXPECT_TRUE(vec3_af->HoldsAbstract()); - EXPECT_TRUE(vec3_ai->HoldsAbstract()); - EXPECT_FALSE(mat2x4_f32->HoldsAbstract()); - EXPECT_FALSE(mat3x4_f32->HoldsAbstract()); - EXPECT_FALSE(mat4x2_f32->HoldsAbstract()); - EXPECT_FALSE(mat4x3_f32->HoldsAbstract()); - EXPECT_FALSE(mat4x3_f16->HoldsAbstract()); - EXPECT_TRUE(mat4x3_af->HoldsAbstract()); - EXPECT_FALSE(str_f16->HoldsAbstract()); - EXPECT_TRUE(str_af->HoldsAbstract()); - EXPECT_FALSE(arr_i32->HoldsAbstract()); - EXPECT_TRUE(arr_ai->HoldsAbstract()); - EXPECT_FALSE(arr_vec3_i32->HoldsAbstract()); - EXPECT_TRUE(arr_vec3_ai->HoldsAbstract()); - EXPECT_FALSE(arr_mat4x3_f16->HoldsAbstract()); - EXPECT_FALSE(arr_mat4x3_f32->HoldsAbstract()); - EXPECT_TRUE(arr_mat4x3_af->HoldsAbstract()); - EXPECT_FALSE(arr_str_f16->HoldsAbstract()); - EXPECT_TRUE(arr_str_af->HoldsAbstract()); +TEST_F(TypeTest, IsAbstract) { + EXPECT_TRUE(af->IsAbstract()); + EXPECT_TRUE(ai->IsAbstract()); + EXPECT_FALSE(f32->IsAbstract()); + EXPECT_FALSE(f16->IsAbstract()); + EXPECT_FALSE(i32->IsAbstract()); + EXPECT_FALSE(u32->IsAbstract()); + EXPECT_FALSE(vec2_f32->IsAbstract()); + EXPECT_FALSE(vec3_f32->IsAbstract()); + EXPECT_FALSE(vec3_f16->IsAbstract()); + EXPECT_FALSE(vec4_f32->IsAbstract()); + EXPECT_FALSE(vec3_u32->IsAbstract()); + EXPECT_FALSE(vec3_i32->IsAbstract()); + EXPECT_TRUE(vec3_af->IsAbstract()); + EXPECT_TRUE(vec3_ai->IsAbstract()); + EXPECT_FALSE(mat2x4_f32->IsAbstract()); + EXPECT_FALSE(mat3x4_f32->IsAbstract()); + EXPECT_FALSE(mat4x2_f32->IsAbstract()); + EXPECT_FALSE(mat4x3_f32->IsAbstract()); + EXPECT_FALSE(mat4x3_f16->IsAbstract()); + EXPECT_TRUE(mat4x3_af->IsAbstract()); + EXPECT_FALSE(str_f16->IsAbstract()); + EXPECT_TRUE(str_af->IsAbstract()); + EXPECT_FALSE(arr_i32->IsAbstract()); + EXPECT_TRUE(arr_ai->IsAbstract()); + EXPECT_FALSE(arr_vec3_i32->IsAbstract()); + EXPECT_TRUE(arr_vec3_ai->IsAbstract()); + EXPECT_FALSE(arr_mat4x3_f16->IsAbstract()); + EXPECT_FALSE(arr_mat4x3_f32->IsAbstract()); + EXPECT_TRUE(arr_mat4x3_af->IsAbstract()); + EXPECT_FALSE(arr_str_f16->IsAbstract()); + EXPECT_TRUE(arr_str_af->IsAbstract()); } } // namespace diff --git a/src/tint/lang/wgsl/ast/transform/fold_constants.cc b/src/tint/lang/wgsl/ast/transform/fold_constants.cc index afce608058d..7eee69cecba 100644 --- a/src/tint/lang/wgsl/ast/transform/fold_constants.cc +++ b/src/tint/lang/wgsl/ast/transform/fold_constants.cc @@ -102,7 +102,7 @@ struct State { return nullptr; } - if (cv->Type()->HoldsAbstract() && !cv->Type()->IsFloatScalar() && + if (cv->Type()->IsAbstract() && !cv->Type()->IsFloatScalar() && !cv->Type()->IsSignedIntegerScalar() && !cv->Type()->IsUnsignedIntegerScalar()) { return nullptr; } diff --git a/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc b/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc index 4c9cd1bbf82..fd763a1f56f 100644 --- a/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc +++ b/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc @@ -56,7 +56,7 @@ struct HoistToDeclBefore::State { switch (kind) { case VariableKind::kLet: { auto* ty = ctx.src->Sem().GetVal(expr)->Type(); - TINT_ASSERT(!ty->HoldsAbstract()); + TINT_ASSERT(!ty->IsAbstract()); auto builder = [this, expr, name, ty] { return b.Decl(b.Let(name, Transform::CreateASTTypeFor(ctx, ty), ctx.CloneWithoutTransform(expr))); @@ -69,7 +69,7 @@ struct HoistToDeclBefore::State { case VariableKind::kVar: { auto* ty = ctx.src->Sem().GetVal(expr)->Type(); - TINT_ASSERT(!ty->HoldsAbstract()); + TINT_ASSERT(!ty->IsAbstract()); auto builder = [this, expr, name, ty] { return b.Decl(b.Var(name, Transform::CreateASTTypeFor(ctx, ty), ctx.CloneWithoutTransform(expr))); diff --git a/src/tint/lang/wgsl/ast/transform/promote_initializers_to_let.cc b/src/tint/lang/wgsl/ast/transform/promote_initializers_to_let.cc index b67da7a75fe..46176c1e0f3 100644 --- a/src/tint/lang/wgsl/ast/transform/promote_initializers_to_let.cc +++ b/src/tint/lang/wgsl/ast/transform/promote_initializers_to_let.cc @@ -60,7 +60,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program& src, return false; } - if (expr->Type()->HoldsAbstract()) { + if (expr->Type()->IsAbstract()) { // Do not hoist expressions that are not materialized, as doing so would cause // premature materialization. return false; diff --git a/src/tint/lang/wgsl/ast/transform/substitute_override.cc b/src/tint/lang/wgsl/ast/transform/substitute_override.cc index 2c5e06a8b13..477a7fb5c05 100644 --- a/src/tint/lang/wgsl/ast/transform/substitute_override.cc +++ b/src/tint/lang/wgsl/ast/transform/substitute_override.cc @@ -120,7 +120,7 @@ Transform::ApplyResult SubstituteOverride::Apply(const Program& src, ctx.ReplaceAll([&](const IndexAccessorExpression* expr) -> const IndexAccessorExpression* { if (auto* sem = src.Sem().Get(expr)) { if (auto* access = sem->UnwrapMaterialize()->As()) { - if (access->Object()->UnwrapMaterialize()->Type()->HoldsAbstract() && + if (access->Object()->UnwrapMaterialize()->Type()->IsAbstract() && access->Index()->Stage() == core::EvaluationStage::kOverride) { auto* obj = b.Call(wgsl::str(wgsl::BuiltinFn::kTintMaterialize), ctx.Clone(expr->object)); diff --git a/src/tint/lang/wgsl/resolver/validator.cc b/src/tint/lang/wgsl/resolver/validator.cc index 47a193903c5..4cf6a62bc86 100644 --- a/src/tint/lang/wgsl/resolver/validator.cc +++ b/src/tint/lang/wgsl/resolver/validator.cc @@ -1712,7 +1712,7 @@ bool Validator::BinaryExpression(const ast::Node* node, // If lhs value is a concrete type, and rhs is a const-expression greater than or equal // to the bit width of lhs, then it is a shader-creation error. const auto* elem_type = lhs->Type()->UnwrapRef()->DeepestElement(); - if (!elem_type->HoldsAbstract() && rhs->Stage() == core::EvaluationStage::kConstant) { + if (!elem_type->IsAbstract() && rhs->Stage() == core::EvaluationStage::kConstant) { const uint32_t bit_width = elem_type->Size() * 8; auto* rhs_val = rhs->ConstantValue(); for (size_t i = 0, n = rhs_val->NumElements(); i < n; i++) {