Skip to content

Commit

Permalink
Rename HoldsAbstract to IsAbstract.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: dan sinclair <[email protected]>
  • Loading branch information
dj2 authored and Dawn LUCI CQ committed Aug 26, 2024
1 parent 92be693 commit 85aed12
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 47 deletions.
10 changes: 5 additions & 5 deletions src/tint/lang/core/type/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ bool Type::IsHandle() const {
return IsAnyOf<Sampler, Texture>();
}

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;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/tint/lang/core/type/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ class Type : public Castable<Type, UniqueNode> {
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.
Expand Down
64 changes: 32 additions & 32 deletions src/tint/lang/core/type/type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/wgsl/ast/transform/fold_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/wgsl/ast/transform/substitute_override.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<sem::IndexAccessorExpression>()) {
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));
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/wgsl/resolver/validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 85aed12

Please sign in to comment.