Rename array size to array count in error messages.

Using `array count` is closer to the language seen in the spec and
clarifies the error messages.

Bug: chromium:1367602
Change-Id: I24388496b3a58c6a4fc62cc2db91c7ad8ca1a371
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104241
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2022-10-03 20:24:16 +00:00 committed by Dawn LUCI CQ
parent 68124ab7d1
commit ca6fedc96a
2 changed files with 32 additions and 28 deletions

View File

@ -2601,7 +2601,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
sem::ArrayCount el_count = sem::RuntimeArrayCount{}; sem::ArrayCount el_count = sem::RuntimeArrayCount{};
// Evaluate the constant array size expression. // Evaluate the constant array count expression.
if (auto* count_expr = arr->count) { if (auto* count_expr = arr->count) {
if (auto count = ArrayCount(count_expr)) { if (auto count = ArrayCount(count_expr)) {
el_count = count.Get(); el_count = count.Get();
@ -2630,7 +2630,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
} }
utils::Result<sem::ArrayCount> Resolver::ArrayCount(const ast::Expression* count_expr) { utils::Result<sem::ArrayCount> Resolver::ArrayCount(const ast::Expression* count_expr) {
// Evaluate the constant array size expression. // Evaluate the constant array count expression.
const auto* count_sem = Materialize(Expression(count_expr)); const auto* count_sem = Materialize(Expression(count_expr));
if (!count_sem) { if (!count_sem) {
return utils::Failure; return utils::Failure;
@ -2648,13 +2648,13 @@ utils::Result<sem::ArrayCount> Resolver::ArrayCount(const ast::Expression* count
auto* count_val = count_sem->ConstantValue(); auto* count_val = count_sem->ConstantValue();
if (!count_val) { if (!count_val) {
AddError("array size must evaluate to a constant integer expression or override variable", AddError("array count must evaluate to a constant integer expression or override variable",
count_expr->source); count_expr->source);
return utils::Failure; return utils::Failure;
} }
if (auto* ty = count_val->Type(); !ty->is_integer_scalar()) { if (auto* ty = count_val->Type(); !ty->is_integer_scalar()) {
AddError("array size must evaluate to a constant integer expression, but is type '" + AddError("array count must evaluate to a constant integer expression, but is type '" +
builder_->FriendlyName(ty) + "'", builder_->FriendlyName(ty) + "'",
count_expr->source); count_expr->source);
return utils::Failure; return utils::Failure;
@ -2662,7 +2662,7 @@ utils::Result<sem::ArrayCount> Resolver::ArrayCount(const ast::Expression* count
int64_t count = count_val->As<AInt>(); int64_t count = count_val->As<AInt>();
if (count < 1) { if (count < 1) {
AddError("array size (" + std::to_string(count) + ") must be greater than 0", AddError("array count (" + std::to_string(count) + ") must be greater than 0",
count_expr->source); count_expr->source);
return utils::Failure; return utils::Failure;
} }
@ -3246,7 +3246,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (count.has_value() && count.value() >= kMaxArrayElementCount) { if (count.has_value() && count.value() >= kMaxArrayElementCount) {
AddError("array size (" + std::to_string(count.value()) + ") must be less than " + AddError("array count (" + std::to_string(count.value()) + ") must be less than " +
std::to_string(kMaxArrayElementCount), std::to_string(kMaxArrayElementCount),
usage); usage);
return false; return false;

View File

@ -216,28 +216,28 @@ TEST_F(ResolverTypeValidationTest, ArraySize_AIntLiteral_Zero) {
// var<private> a : array<f32, 0>; // var<private> a : array<f32, 0>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_a)), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_a)), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Zero) {
// var<private> a : array<f32, 0u>; // var<private> a : array<f32, 0u>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_u)), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_u)), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Zero) {
// var<private> a : array<f32, 0i>; // var<private> a : array<f32, 0i>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_i)), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_i)), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Negative) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Negative) {
// var<private> a : array<f32, -10i>; // var<private> a : array<f32, -10i>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, -10_i)), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, -10_i)), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (-10) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedConst_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedConst_Zero) {
@ -246,7 +246,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedConst_Zero) {
GlobalConst("size", Expr(0_u)); GlobalConst("size", Expr(0_u));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Zero) {
@ -255,7 +255,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Zero) {
GlobalConst("size", Expr(0_i)); GlobalConst("size", Expr(0_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Negative) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Negative) {
@ -264,16 +264,17 @@ TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Negative) {
GlobalConst("size", Expr(-10_i)); GlobalConst("size", Expr(-10_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array size (-10) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_FloatLiteral) { TEST_F(ResolverTypeValidationTest, ArraySize_FloatLiteral) {
// var<private> a : array<f32, 10.0>; // var<private> a : array<f32, 10.0>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 10_f)), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 10_f)), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(
"12:34 error: array size must evaluate to a constant integer expression, but is type " r()->error(),
"'f32'"); "12:34 error: array count must evaluate to a constant integer expression, but is type "
"'f32'");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_IVecLiteral) { TEST_F(ResolverTypeValidationTest, ArraySize_IVecLiteral) {
@ -281,9 +282,10 @@ TEST_F(ResolverTypeValidationTest, ArraySize_IVecLiteral) {
GlobalVar("a", ty.array(ty.f32(), Construct(Source{{12, 34}}, ty.vec2<i32>(), 10_i, 10_i)), GlobalVar("a", ty.array(ty.f32(), Construct(Source{{12, 34}}, ty.vec2<i32>(), 10_i, 10_i)),
ast::AddressSpace::kPrivate); ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(
"12:34 error: array size must evaluate to a constant integer expression, but is type " r()->error(),
"'vec2<i32>'"); "12:34 error: array count must evaluate to a constant integer expression, but is type "
"'vec2<i32>'");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_FloatConst) { TEST_F(ResolverTypeValidationTest, ArraySize_FloatConst) {
@ -292,9 +294,10 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FloatConst) {
GlobalConst("size", Expr(10_f)); GlobalConst("size", Expr(10_f));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(
"12:34 error: array size must evaluate to a constant integer expression, but is type " r()->error(),
"'f32'"); "12:34 error: array count must evaluate to a constant integer expression, but is type "
"'f32'");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_IVecConst) { TEST_F(ResolverTypeValidationTest, ArraySize_IVecConst) {
@ -303,9 +306,10 @@ TEST_F(ResolverTypeValidationTest, ArraySize_IVecConst) {
GlobalConst("size", Construct(ty.vec2<i32>(), 100_i, 100_i)); GlobalConst("size", Construct(ty.vec2<i32>(), 100_i, 100_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(
"12:34 error: array size must evaluate to a constant integer expression, but is type " r()->error(),
"'vec2<i32>'"); "12:34 error: array count must evaluate to a constant integer expression, but is type "
"'vec2<i32>'");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_UnderElementCountLimit) { TEST_F(ResolverTypeValidationTest, ArraySize_UnderElementCountLimit) {
@ -321,7 +325,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_OverElementCountLimit) {
ty.array(Source{{12, 34}}, ty.f32(), Expr(Source{{12, 34}}, 65536_a)), ty.array(Source{{12, 34}}, ty.f32(), Expr(Source{{12, 34}}, 65536_a)),
ast::AddressSpace::kPrivate); ast::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(1:2 error: array size (65536) must be less than 65536 EXPECT_EQ(r()->error(), R"(1:2 error: array count (65536) must be less than 65536
1:2 note: while instantiating 'var' a)"); 1:2 note: while instantiating 'var' a)");
} }
@ -386,7 +390,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_Override_ComplexExpr) {
ast::AddressSpace::kWorkgroup); ast::AddressSpace::kWorkgroup);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array size must evaluate to a constant integer expression or override " "12:34 error: array count must evaluate to a constant integer expression or override "
"variable"); "variable");
} }
@ -545,7 +549,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FunctionLet) {
WrapInFunction(size, a); WrapInFunction(size, a);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array size must evaluate to a constant integer expression or override " "12:34 error: array count must evaluate to a constant integer expression or override "
"variable"); "variable");
} }