Skip to content

Require Swift 5.6 #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

/*
Expand Down
20 changes: 6 additions & 14 deletions Sources/System/FileDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ extension FileDescriptor {
extension FileDescriptor {
/// The desired read and write access for a newly opened file.
@frozen
public struct AccessMode: RawRepresentable, Hashable, Codable {
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
public struct AccessMode: RawRepresentable, Sendable, Hashable, Codable {
/// The raw C access mode.
@_alwaysEmitIntoClient
public var rawValue: CInt
Expand Down Expand Up @@ -87,7 +88,8 @@ extension FileDescriptor {

/// Options that specify behavior for a newly-opened file.
@frozen
public struct OpenOptions: OptionSet, Hashable, Codable {
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
public struct OpenOptions: OptionSet, Sendable, Hashable, Codable {
/// The raw C options.
@_alwaysEmitIntoClient
public var rawValue: CInt
Expand Down Expand Up @@ -311,7 +313,8 @@ extension FileDescriptor {

/// Options for specifying what a file descriptor's offset is relative to.
@frozen
public struct SeekOrigin: RawRepresentable, Hashable, Codable {
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
public struct SeekOrigin: RawRepresentable, Sendable, Hashable, Codable {
/// The raw C value.
@_alwaysEmitIntoClient
public var rawValue: CInt
Expand Down Expand Up @@ -475,18 +478,7 @@ extension FileDescriptor.OpenOptions
public var debugDescription: String { self.description }
}

#if compiler(>=5.5) && canImport(_Concurrency)
// The decision on whether to make FileDescriptor Sendable or not
// is currently being discussed in https://github.com/apple/swift-system/pull/112
//@available(*, unavailable, message: "File descriptors are not completely thread-safe.")
//extension FileDescriptor: Sendable {}

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FileDescriptor.AccessMode: Sendable {}

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FileDescriptor.OpenOptions: Sendable {}

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FileDescriptor.SeekOrigin: Sendable {}
#endif
7 changes: 1 addition & 6 deletions Sources/System/FilePath/FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/// are file-system–specific and have additional considerations
/// like case insensitivity, Unicode normalization, and symbolic links.
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
public struct FilePath {
public struct FilePath: Sendable {
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
// components, etc.
internal var _storage: SystemString
Expand Down Expand Up @@ -67,8 +67,3 @@ extension FilePath {

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePath: Hashable, Codable {}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePath: Sendable {}
#endif
40 changes: 5 additions & 35 deletions Sources/System/FilePath/FilePathComponentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension FilePath {
///
/// path.components.removeAll { $0.kind == .currentDirectory }
/// // path is "/home/username/bin/scripts/tree"
public struct ComponentView {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
public struct ComponentView: Sendable {
internal var _path: FilePath
internal var _start: SystemString.Index

Expand All @@ -39,30 +40,6 @@ extension FilePath {
}
}

#if SYSTEM_PACKAGE // Workaround for a __consuming getter bug in Swift 5.3.3
/// View the non-root components that make up this path.
public var components: ComponentView {
get { ComponentView(self) }
_modify {
// RRC's empty init means that we can't guarantee that the yielded
// view will restore our root. So copy it out first.
//
// TODO(perf): Small-form root (especially on Unix). Have Root
// always copy out (not worth ref counting). Make sure that we're
// not needlessly sliding values around or triggering a COW
let rootStr = self.root?._systemString ?? SystemString()
var comp = ComponentView(self)
self = FilePath()
defer {
self = comp._path
if root?._slice.elementsEqual(rootStr) != true {
self.root = Root(rootStr)
}
}
yield &comp
}
}
#else
/// View the non-root components that make up this path.
public var components: ComponentView {
__consuming get { ComponentView(self) }
Expand All @@ -85,13 +62,14 @@ extension FilePath {
yield &comp
}
}
#endif
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView: BidirectionalCollection {
public typealias Element = FilePath.Component
public struct Index: Comparable, Hashable {

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
public struct Index: Sendable, Comparable, Hashable {
internal typealias Storage = SystemString.Index

internal var _storage: Storage
Expand Down Expand Up @@ -239,11 +217,3 @@ extension FilePath.ComponentView {
#endif // DEBUG
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView: Sendable {}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView.Index: Sendable {}
#endif
20 changes: 6 additions & 14 deletions Sources/System/FilePath/FilePathComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension FilePath {
/// * `\\server\share\`
/// * `\\?\UNC\server\share\`
/// * `\\?\Volume{12345678-abcd-1111-2222-123445789abc}\`
public struct Root {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
public struct Root: Sendable {
internal var _path: FilePath
internal var _rootEnd: SystemString.Index

Expand All @@ -54,7 +55,8 @@ extension FilePath {
/// file.kind == .regular // true
/// file.extension // "txt"
/// path.append(file) // path is "/tmp/foo.txt"
public struct Component {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
public struct Component: Sendable {
internal var _path: FilePath
internal var _range: Range<SystemString.Index>

Expand All @@ -78,7 +80,8 @@ extension FilePath.Component {
/// Whether a component is a regular file or directory name, or a special
/// directory `.` or `..`
@frozen
public enum Kind {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
public enum Kind: Sendable {
/// The special directory `.`, representing the current directory.
case currentDirectory

Expand Down Expand Up @@ -285,14 +288,3 @@ extension FilePath.Root {
#endif
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Root: Sendable {}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component: Sendable {}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component.Kind: Sendable {}
#endif
7 changes: 1 addition & 6 deletions Sources/System/FilePermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// perms == [.ownerReadWrite, .groupRead, .otherRead] // true
@frozen
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
public struct FilePermissions: OptionSet, Hashable, Codable {
public struct FilePermissions: OptionSet, Sendable, Hashable, Codable {
/// The raw C file permissions.
@_alwaysEmitIntoClient
public let rawValue: CModeT
Expand Down Expand Up @@ -175,8 +175,3 @@ extension FilePermissions
/// A textual representation of the file permissions, suitable for debugging.
public var debugDescription: String { self.description }
}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePermissions: Sendable {}
#endif
10 changes: 3 additions & 7 deletions Sources/System/SystemString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/

// A platform-native character representation, currently used for file paths
internal struct SystemChar: RawRepresentable, Comparable, Hashable, Codable {
internal struct SystemChar:
RawRepresentable, Sendable, Comparable, Hashable, Codable {
internal typealias RawValue = CInterop.PlatformChar

internal var rawValue: RawValue
Expand Down Expand Up @@ -61,7 +62,7 @@ extension SystemChar {
// A platform-native string representation, currently for file paths
//
// Always null-terminated.
internal struct SystemString {
internal struct SystemString: Sendable {
internal typealias Storage = [SystemChar]
internal var nullTerminatedStorage: Storage
}
Expand Down Expand Up @@ -288,11 +289,6 @@ 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
132 changes: 0 additions & 132 deletions Tests/SystemTests/XCTestManifests.swift

This file was deleted.