From 626b0a29da8727ab2ac32c39afa858f57fdf6d66 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Sun, 22 Sep 2024 09:52:37 +0100 Subject: [PATCH 1/5] Workaround Swift 6 bug for missing related references to external overriden declarations. Closes #820 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e1a23c9..08973348c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,20 @@ - Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. - Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. +## 2.21.1 (2024-09-28) + +##### Breaking + +- None. + +##### Enhancements + +- None. + +##### Bug Fixes + +- Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. + ## 2.21.0 (2024-06-15) ##### Breaking From df0d2f49c807007cf6875af27eb88a06d0be7cf1 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Fri, 23 Aug 2024 09:29:07 +0200 Subject: [PATCH 2/5] Exclude unused exported imports from results --- CHANGELOG.md | 3 +- .../Syntax/ImportSyntaxVisitor.swift | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 08973348c..cd6ad6d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,6 @@ ##### Bug Fixes - Enums with the `@main` attribute are now retained. -- Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. -- Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. ## 2.21.1 (2024-09-28) @@ -27,6 +25,7 @@ ##### Bug Fixes - Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. +- Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. ## 2.21.0 (2024-06-15) diff --git a/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift b/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift new file mode 100644 index 000000000..c576faf21 --- /dev/null +++ b/Sources/PeripheryKit/Syntax/ImportSyntaxVisitor.swift @@ -0,0 +1,39 @@ +import Foundation +import SwiftSyntax + +struct ImportStatement { + let module: String + let isTestable: Bool + let isExported: Bool + let location: SourceLocation +} + +final class ImportSyntaxVisitor: PeripherySyntaxVisitor { + var importStatements: [ImportStatement] = [] + + private let sourceLocationBuilder: SourceLocationBuilder + + init(sourceLocationBuilder: SourceLocationBuilder) { + self.sourceLocationBuilder = sourceLocationBuilder + } + + func visit(_ node: ImportDeclSyntax) { + let parts = node.path.map { $0.name.text } + let module = parts.first ?? "" + let attributes = node.attributes.compactMap { + if case let .attribute(attr) = $0 { + attr.attributeName.trimmedDescription + } else { + nil + } + } + let location = sourceLocationBuilder.location(at: node.positionAfterSkippingLeadingTrivia) + let statement = ImportStatement( + module: module, + isTestable: attributes.contains("testable"), + isExported: attributes.contains("_exported") || node.modifiers.contains { $0.name.text == "public" }, + location: location + ) + importStatements.append(statement) + } +} From 63d102216803c792951ac610ef7267c1e22a731a Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Tue, 20 Aug 2024 12:24:03 +0200 Subject: [PATCH 3/5] Enums can also be entry points --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6ad6d11..b63631d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ##### Bug Fixes -- Enums with the `@main` attribute are now retained. +- None. ## 2.21.1 (2024-09-28) @@ -24,6 +24,7 @@ ##### Bug Fixes +- Enums with the `@main` attribute are now retained. - Fixed issue in Swift 6 where declarations that override external type members are incorrectly identified as unused. - Unused public/exported imports are excluded from the results even if unused in the declaring file as the exported symbols may be referenced in other files, and thus removing the import would result in a build failure. From 4393b6dacf5331f699ef04035c106d441d28e20e Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Sat, 28 Sep 2024 12:00:53 +0100 Subject: [PATCH 4/5] Fix build --- Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift b/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift index a515244a6..f85bbb9df 100644 --- a/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift +++ b/Sources/SourceGraph/Mutators/ExternalOverrideRetainer.swift @@ -1,4 +1,3 @@ -import Configuration import Foundation import Shared @@ -10,9 +9,9 @@ final class ExternalOverrideRetainer: SourceGraphMutator { private let graph: SourceGraph private let isSwift6FixEnabled: Bool - required init(graph: SourceGraph, configuration _: Configuration, swiftVersion: SwiftVersion) { + required init(graph: SourceGraph, configuration _: Configuration) { self.graph = graph - isSwift6FixEnabled = swiftVersion.version.isVersion(greaterThanOrEqualTo: "6.0") + isSwift6FixEnabled = SwiftVersion.current.version.isVersion(greaterThanOrEqualTo: "6.0") } func mutate() { From b861330665ec594c12668419f60ff0af83f16555 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Sat, 28 Sep 2024 12:11:19 +0100 Subject: [PATCH 5/5] Release 2.21.1 --- Sources/Frontend/Version.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Frontend/Version.swift b/Sources/Frontend/Version.swift index 5d8e52f77..e02d6a966 100644 --- a/Sources/Frontend/Version.swift +++ b/Sources/Frontend/Version.swift @@ -1 +1 @@ -let PeripheryVersion = "3.0.0.beta4" +let PeripheryVersion = "2.21.1"