Import Tint changes from Dawn
Changes:
- 614b1fdb067393236b1448ee34f7591aa6aec3c5 [renamer] Preserve swizzles through materialize by James Price <jrprice@google.com>
GitOrigin-RevId: 614b1fdb067393236b1448ee34f7591aa6aec3c5
Change-Id: I3d39909bb557caadbde561b962033a471811f0a6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/176280
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/lang/wgsl/ast/transform/renamer.cc b/src/tint/lang/wgsl/ast/transform/renamer.cc
index 487697d..423df11 100644
--- a/src/tint/lang/wgsl/ast/transform/renamer.cc
+++ b/src/tint/lang/wgsl/ast/transform/renamer.cc
@@ -1294,7 +1294,7 @@
Switch(
node,
[&](const MemberAccessorExpression* accessor) {
- auto* sem = src.Sem().Get(accessor)->UnwrapLoad();
+ auto* sem = src.Sem().Get(accessor)->Unwrap();
if (sem->Is<sem::Swizzle>()) {
preserved_identifiers.Add(accessor->member);
} else if (auto* str_expr = src.Sem().GetVal(accessor->object)) {
diff --git a/src/tint/lang/wgsl/ast/transform/renamer_test.cc b/src/tint/lang/wgsl/ast/transform/renamer_test.cc
index b24a440..b3aa2ac 100644
--- a/src/tint/lang/wgsl/ast/transform/renamer_test.cc
+++ b/src/tint/lang/wgsl/ast/transform/renamer_test.cc
@@ -208,6 +208,32 @@
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
}
+TEST_F(RenamerTest, PreserveSwizzles_ThroughMaterialize) {
+ auto* src = R"(
+const v = vec4();
+const x = v.x * 2u;
+)";
+
+ auto* expect = R"(
+const tint_symbol = vec4();
+
+const tint_symbol_1 = (tint_symbol.x * 2u);
+)";
+
+ auto got = Run<Renamer>(src);
+
+ EXPECT_EQ(expect, str(got));
+
+ auto* data = got.data.Get<Renamer::Data>();
+
+ ASSERT_NE(data, nullptr);
+ Renamer::Remappings expected_remappings = {
+ {"v", "tint_symbol"},
+ {"x", "tint_symbol_1"},
+ };
+ EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
+}
+
TEST_F(RenamerTest, PreserveBuiltins) {
auto* src = R"(
@vertex