tint/transform: Skip Unshadow if possible
Change-Id: I73b7213aafe3ff25a5f6526e7002d2ec3dda57c3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116871 Kokoro: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
b607bfbddf
commit
7a41bf1e2f
src/tint/transform
|
@ -81,19 +81,29 @@ struct Unshadow::State {
|
|||
});
|
||||
};
|
||||
|
||||
ctx.ReplaceAll([&](const ast::Variable* v) -> const ast::Variable* {
|
||||
if (auto* local = sem.Get<sem::LocalVariable>(v)) {
|
||||
bool made_changes = false;
|
||||
|
||||
for (auto* node : ctx.src->SemNodes().Objects()) {
|
||||
Switch(
|
||||
node, //
|
||||
[&](const sem::LocalVariable* local) {
|
||||
if (local->Shadows()) {
|
||||
return rename(local);
|
||||
ctx.Replace(local->Declaration(), [&, local] { return rename(local); });
|
||||
made_changes = true;
|
||||
}
|
||||
}
|
||||
if (auto* param = sem.Get<sem::Parameter>(v)) {
|
||||
},
|
||||
[&](const sem::Parameter* param) {
|
||||
if (param->Shadows()) {
|
||||
return rename(param);
|
||||
ctx.Replace(param->Declaration(), [&, param] { return rename(param); });
|
||||
made_changes = true;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
if (!made_changes) {
|
||||
return SkipTransform;
|
||||
}
|
||||
|
||||
ctx.ReplaceAll(
|
||||
[&](const ast::IdentifierExpression* ident) -> const tint::ast::IdentifierExpression* {
|
||||
if (auto* sem_ident = sem.Get(ident)) {
|
||||
|
|
|
@ -23,11 +23,8 @@ using UnshadowTest = TransformTest;
|
|||
|
||||
TEST_F(UnshadowTest, EmptyModule) {
|
||||
auto* src = "";
|
||||
auto* expect = "";
|
||||
|
||||
auto got = Run<Unshadow>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
EXPECT_FALSE(ShouldRun<Unshadow>(src));
|
||||
}
|
||||
|
||||
TEST_F(UnshadowTest, Noop) {
|
||||
|
@ -48,11 +45,7 @@ fn F(c : i32) {
|
|||
}
|
||||
)";
|
||||
|
||||
auto* expect = src;
|
||||
|
||||
auto got = Run<Unshadow>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
EXPECT_FALSE(ShouldRun<Unshadow>(src));
|
||||
}
|
||||
|
||||
TEST_F(UnshadowTest, LocalShadowsAlias) {
|
||||
|
|
Loading…
Reference in New Issue