Skip to content

Commit

Permalink
Add Sendable conformances
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Nov 7, 2022
1 parent 18cceda commit 0d05714
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/System/FileDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,14 @@ extension FileDescriptor.OpenOptions
/// A textual representation of the open options, suitable for debugging.
public var debugDescription: String { self.description }
}

#if compiler(>=5.5) && canImport(_Concurrency)
// File descriptors aren't necessarily safe to use across threads.
// However, since they can be used in a safe way,
// we do make them `Sendable` to not make it unnecessarily complicated to
// use them across concurrency boundaries in a safe way.
extension FileDescriptor: Sendable {}
extension FileDescriptor.AccessMode: Sendable {}
extension FileDescriptor.OpenOptions: Sendable {}
extension FileDescriptor.SeekOrigin: Sendable {}
#endif
3 changes: 3 additions & 0 deletions Sources/System/FilePath/FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ extension FilePath {
/*System 0.0.1, @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)*/
extension FilePath: Hashable, Codable {}

#if compiler(>=5.5) && canImport(_Concurrency)
extension FilePath: Sendable {}
#endif
5 changes: 5 additions & 0 deletions Sources/System/FilePath/FilePathComponentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,8 @@ extension FilePath.ComponentView {
#endif // DEBUG
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension FilePath.ComponentView: Sendable {}
extension FilePath.ComponentView.Index: Sendable {}
#endif
6 changes: 6 additions & 0 deletions Sources/System/FilePath/FilePathComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,9 @@ extension FilePath.Root {
#endif
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension FilePath.Root: Sendable {}
extension FilePath.Component: Sendable {}
extension FilePath.Component.Kind: Sendable {}
#endif
4 changes: 4 additions & 0 deletions Sources/System/FilePermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,7 @@ extension FilePermissions
/// A textual representation of the file permissions, suitable for debugging.
public var debugDescription: String { self.description }
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension FilePermissions: Sendable {}
#endif
5 changes: 5 additions & 0 deletions Sources/System/SystemString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ extension SystemString {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
extension SystemChar: Sendable {}
extension SystemString: Sendable {}
#endif

// TODO: SystemString should use a COW-interchangable storage form rather
// than array, so you could "borrow" the storage from a non-bridged String
// or Data or whatever

0 comments on commit 0d05714

Please sign in to comment.