Skip to content

Commit e6a8ec9

Browse files
committed
[SwiftCompilerSources] Handle .anyValueFields use-def walks through enums
The walker was not treating an EnumInst with zero payload, such as `Optional.none` as a root. It seems the best way to fix that is to implement the handling of .anyValueFields for enums, as they're documented in a comment to mean "follow anything", unlike .enumCase which expects to find a specific case (though perhaps if it matches and there's no payload, it should still be a root?)
1 parent a69bcf8 commit e6a8ec9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/WalkUtils.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,15 @@ extension ValueUseDefWalker {
631631
if let path = path.popIfMatches(.enumCase, index: e.caseIndex),
632632
let payload = e.payload {
633633
return walkUp(value: payload, path: path)
634+
635+
} else if path.popIfMatches(.anyValueFields, index: nil) != nil {
636+
if let payload = e.payload {
637+
return walkUp(value: payload, path: path)
638+
} else {
639+
// without a payload, this enum is itself a definition root.
640+
return rootDef(value: e, path: path)
641+
}
642+
634643
} else {
635644
return unmatchedPath(value: e, path: path)
636645
}

0 commit comments

Comments
 (0)