From fbda33194d7afbc87bb2462e65a2116abe3def30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Thu, 5 Dec 2024 11:17:59 +0100 Subject: [PATCH] Remove existential return type in `recursiveFiles(startingPoint:options:)` to workaround https://github.com/swiftlang/swift/issues/77955 --- .../FileManagerProtocol+FilesSequence.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift b/Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift index 1579dd826..8cbe18b1c 100644 --- a/Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift +++ b/Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift @@ -16,21 +16,24 @@ extension FileManagerProtocol { /// - startingPoint: The file or directory that's the top of the directory structure that the file manager traverses. /// - options: Options for how the file manager enumerates the contents of directories. Defaults to `.skipsHiddenFiles`. /// - Returns: A sequence of the files in the directory structure. - package func recursiveFiles(startingPoint: URL, options: FileManager.DirectoryEnumerationOptions = .skipsHiddenFiles) -> some Sequence { - IteratorSequence(FilesIterator(fileManager: self, startingPoint: startingPoint, options: options)) + package func recursiveFiles(startingPoint: URL, options: FileManager.DirectoryEnumerationOptions = .skipsHiddenFiles) -> IteratorSequence<_FilesIterator> { + IteratorSequence(_FilesIterator(fileManager: self, startingPoint: startingPoint, options: options)) } } +// FIXME: This should be private and `FileManagerProtocol.recursiveFiles(startingPoint:options:)` should return `some Sequence` +// but because of https://github.com/swiftlang/swift/issues/77955 it needs to be exposed as an explicit type to avoid a SIL Validation error in the Swift compiler. + /// An iterator that traverses the directory structure and returns the files in breadth-first order. -private struct FilesIterator: IteratorProtocol { +package struct _FilesIterator: IteratorProtocol { /// The file manager that the iterator uses to traverse the directory structure. - var fileManager: FileManager - var options: Foundation.FileManager.DirectoryEnumerationOptions + private var fileManager: any FileManagerProtocol // This can't be a generic because of https://github.com/swiftlang/swift/issues/77955 + private var options: FileManager.DirectoryEnumerationOptions private var foundFiles: [URL] private var foundDirectories: [URL] - init(fileManager: FileManager, startingPoint: URL, options: Foundation.FileManager.DirectoryEnumerationOptions) { + fileprivate init(fileManager: any FileManagerProtocol, startingPoint: URL, options: FileManager.DirectoryEnumerationOptions) { self.fileManager = fileManager self.options = options @@ -44,7 +47,7 @@ private struct FilesIterator: IteratorProtocol } } - mutating func next() -> URL? { + package mutating func next() -> URL? { // If the iterator has already found some files, return those first if !foundFiles.isEmpty { return foundFiles.removeFirst()