Retain nested types referenced only by sibling method signatures#1137
Open
danwood wants to merge 2 commits into
Open
Retain nested types referenced only by sibling method signatures#1137danwood wants to merge 2 commits into
danwood wants to merge 2 commits into
Conversation
A nested type used solely as the return type or a parameter type of a sibling method was incorrectly reported as unused. The index store records the type reference against the method declaration rather than emitting a standalone reference occurrence for the type, so when the enclosing type was marked used the nested type had no incoming reference to follow. UsedDeclarationMarker now walks the return-type and parameter-type references of a used declaration's child functions, ensuring such nested types are retained. Adds a retention test covering a nested struct and nested enum reachable only through a sibling method's signature.
The improved used-marking now reports the individual members of SetupSelection (its cases and selectedValues) as unused on Linux, where XcodeSupport — the sole consumer — is not compiled. Previously only the enum type itself was reported and baselined. Replace the type entry with the three member USRs in the Linux and Linux-Bazel baselines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
A nested type that is used only as the return type or a parameter type of a sibling method in the same enclosing type is incorrectly reported as unused, even when the enclosing type is reachable. For example:
PayloadandModeare reported unused despite appearing in the method signatures.Root cause
The Swift index store records the type reference for a return/parameter type against the method declaration; it does not emit a standalone reference occurrence for the type itself.
UsedDeclarationMarker.markUsed(_:)follows a declaration's ownreferencesandrelated, but it does not descend into the signature-type references held by the declaration's child functions. So when the enclosing type is marked used, a nested type reachable only through a sibling method's signature has no incoming reference to follow and is left unmarked.Fix
When a declaration is marked used, also walk the
returnTypeandparameterTypereferences of its child function declarations and mark the referenced declarations used. This retains nested types that appear only in sibling method signatures, without affecting types reachable through ordinary references.Tests
Adds
testRetainsNestedTypeUsedAsSiblingMethodSignatureType, with a fixture containing a nested struct used as a method return type and a nested enum used as a method parameter type, reachable only through those signatures. The test fails before the change (both nested types reported unused) and passes after. The full existing suite continues to pass with no regressions.