Re-allow dynamic indexing of 'let' arrays and matrices

Spec change: https://github.com/gpuweb/gpuweb/pull/2427
Reverses: tint:867

This reverts and fixes commits:
 b6fdcc54df
 10442eff7d

Added a bunch of end-to-end tests.

Fixed: tint:1352
Change-Id: I34968243bbec1cab838c8ba50a6f027146bbfd06
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/75401
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-01-06 18:11:01 +00:00
committed by Tint LUCI CQ
parent 294ce9394f
commit 3cbb136b8a
164 changed files with 2495 additions and 122 deletions

View File

@@ -59,9 +59,8 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) {
auto* acc = IndexAccessor("my_const", Expr(Source{{12, 34}}, idx));
WrapInFunction(Decl(idx), acc);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: index must be signed or unsigned integer literal");
EXPECT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "");
}
TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
@@ -70,9 +69,8 @@ TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
WrapInFunction(Decl(idx), acc);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: index must be signed or unsigned integer literal");
EXPECT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "");
}
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
@@ -82,9 +80,8 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
IndexAccessor(IndexAccessor("my_var", Expr(Source{{12, 34}}, idx)), 1);
WrapInFunction(Decl(idx), acc);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: index must be signed or unsigned integer literal");
EXPECT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "");
}
TEST_F(ResolverIndexAccessorTest, Matrix) {
@@ -221,9 +218,8 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
},
ast::DecorationList{});
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: index must be signed or unsigned integer literal");
EXPECT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "");
}
TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {

View File

@@ -1197,18 +1197,6 @@ sem::Expression* Resolver::IndexAccessor(
return nullptr;
}
if (obj_ty->IsAnyOf<sem::Array, sem::Matrix>()) {
if (!obj_raw_ty->Is<sem::Reference>()) {
// TODO(bclayton): expand this to allow any const_expr expression
// https://github.com/gpuweb/gpuweb/issues/1272
if (!idx->Declaration()->As<ast::IntLiteralExpression>()) {
AddError("index must be signed or unsigned integer literal",
idx->Declaration()->source);
return nullptr;
}
}
}
// If we're extracting from a reference, we return a reference.
if (auto* ref = obj_raw_ty->As<sem::Reference>()) {
ty = builder_->create<sem::Reference>(ty, ref->StorageClass(),