From 644690696f7155f0dc40b5c2afef7ba00719a0dd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 10 Nov 2025 13:45:46 -0800 Subject: [PATCH] Use approachable concurrency with FeedFinder. --- Modules/FeedFinder/Package.swift | 3 +++ .../FeedFinder/Sources/FeedFinder/FeedFinder.swift | 14 +++++++------- .../Sources/FeedFinder/FeedSpecifier.swift | 4 ++-- .../Sources/FeedFinder/HTMLFeedFinder.swift | 6 +++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Modules/FeedFinder/Package.swift b/Modules/FeedFinder/Package.swift index b8eec32dc..78de38844 100644 --- a/Modules/FeedFinder/Package.swift +++ b/Modules/FeedFinder/Package.swift @@ -24,6 +24,9 @@ let package = Package( "RSCore" ], swiftSettings: [ + .enableUpcomingFeature("NonisolatedNonsendingByDefault"), + .enableUpcomingFeature("InferIsolatedConformances"), + .defaultIsolation(MainActor.self), .unsafeFlags(["-warnings-as-errors"]) ] ), diff --git a/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift b/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift index acb950c09..d692efab6 100644 --- a/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift +++ b/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift @@ -23,11 +23,11 @@ public enum FeedFinderError: LocalizedError { } } -public final class FeedFinder { +nonisolated public final class FeedFinder { private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FeedFinder") - public static func find(url: URL) async throws -> Set { + @concurrent public static func find(url: URL) async throws -> Set { // Check special cases first. if let feedSpecifier = FeedSpecifier.knownFeedSpecifier(url: url) { logger.info("FeedFinder: found special case feed URL: \(url.absoluteString) - \(feedSpecifier.urlString)") @@ -68,10 +68,10 @@ public final class FeedFinder { } } -private extension FeedFinder { - +nonisolated private extension FeedFinder { + static func addFeedSpecifier(_ feedSpecifier: FeedSpecifier, feedSpecifiers: inout [String: FeedSpecifier]) { - // If there’s an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn’t, use that non-nil title. Use the better source. + // If there's an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn't, use that non-nil title. Use the better source. if let existingFeedSpecifier = feedSpecifiers[feedSpecifier.urlString] { let mergedFeedSpecifier = existingFeedSpecifier.feedSpecifierByMerging(feedSpecifier) @@ -122,8 +122,8 @@ private extension FeedFinder { var feedSpecifiers = HTMLFeedFinder(parserData: parserData).feedSpecifiers if feedSpecifiers.isEmpty { - // Odds are decent it’s a WordPress site, and just adding /feed/ will work. - // It’s also fairly common for /index.xml to work. + // Odds are decent it's a WordPress site, and just adding /feed/ will work. + // It's also fairly common for /index.xml to work. if let url = URL(string: urlString) { let feedURL = url.appendingPathComponent("feed", isDirectory: true) let wordpressFeedSpecifier = FeedSpecifier(title: nil, urlString: feedURL.absoluteString, source: .HTMLLink, orderFound: 1) diff --git a/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift b/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift index 31d1e2691..c79a4d5a3 100644 --- a/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift +++ b/Modules/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift @@ -9,7 +9,7 @@ import Foundation import RSWeb -public struct FeedSpecifier: Hashable, Sendable { +nonisolated public struct FeedSpecifier: Hashable, Sendable { public enum Source: Int, Sendable { case UserEntered = 0, HTMLHead, HTMLLink @@ -77,7 +77,7 @@ public struct FeedSpecifier: Hashable, Sendable { } } -private extension FeedSpecifier { +nonisolated private extension FeedSpecifier { func calculatedScore() -> Int { var score = 0 diff --git a/Modules/FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift b/Modules/FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift index 815d53f9f..83f7438be 100644 --- a/Modules/FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift +++ b/Modules/FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift @@ -9,9 +9,9 @@ import Foundation import RSParser -private let feedURLWordsToMatch = ["feed", "xml", "rss", "atom", "json"] +nonisolated private let feedURLWordsToMatch = ["feed", "xml", "rss", "atom", "json"] -final class HTMLFeedFinder { +nonisolated final class HTMLFeedFinder { var feedSpecifiers: Set { return Set(feedSpecifiersDictionary.values) @@ -42,7 +42,7 @@ final class HTMLFeedFinder { } } -private extension HTMLFeedFinder { +nonisolated private extension HTMLFeedFinder { func addFeedSpecifier(_ feedSpecifier: FeedSpecifier) { // If there’s an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn’t, use that non-nil title. Use the better source.