-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround Swift 6 bug for missing related references to external ove…
…rriden declarations. Closes #820
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
46 changes: 46 additions & 0 deletions
46
Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Configuration | ||
import Foundation | ||
import Shared | ||
|
||
/// Retains instance functions/vars that override external declarations. | ||
/// | ||
/// It's not possible to determine if a declaration that overrides an external declaration is used, as the | ||
/// external implementation may call the overridden declaration. | ||
final class ExternalOverrideRetainer: SourceGraphMutator { | ||
private let graph: SourceGraph | ||
private let isSwift6FixEnabled: Bool | ||
|
||
required init(graph: SourceGraph, configuration _: Configuration, swiftVersion: SwiftVersion) { | ||
self.graph = graph | ||
isSwift6FixEnabled = swiftVersion.version.isVersion(greaterThanOrEqualTo: "6.0") | ||
} | ||
|
||
func mutate() { | ||
for decl in graph.declarations(ofKinds: Declaration.Kind.overrideKinds) { | ||
guard decl.isOverride else { continue } | ||
|
||
var didIdentifyRelatedRef = false | ||
|
||
for relatedRef in decl.related { | ||
if relatedRef.kind == decl.kind, | ||
relatedRef.name == decl.name, | ||
relatedRef.location == decl.location | ||
{ | ||
didIdentifyRelatedRef = true | ||
|
||
if graph.explicitDeclaration(withUsr: relatedRef.usr) == nil { | ||
// The related decl is external. | ||
graph.markRetained(decl) | ||
} | ||
|
||
break | ||
} | ||
} | ||
|
||
// https://github.com/swiftlang/swift/issues/76628 | ||
if !didIdentifyRelatedRef, isSwift6FixEnabled { | ||
graph.markRetained(decl) | ||
} | ||
} | ||
} | ||
} |
This file contains 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