Skip to content

Commit

Permalink
Swift Language Support: Drop <5.9, Add 6.0 (#226)
Browse files Browse the repository at this point in the history
* Swift Language Support: Drop <5.9, Add 6.0

* wip

* wip

* wip

* wip

* wip

* wip
  • Loading branch information
stephencelis authored Jun 18, 2024
1 parent 1b9fc8f commit 8d94dcd
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 249 deletions.
27 changes: 11 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
config: ['debug', 'release']
xcode: ['14.3.1', '15.4.0']
xcode: ['15.4']
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
Expand All @@ -34,16 +34,6 @@ jobs:
- name: Build for library evolution
run: make build-for-library-evolution

# integration:
# name: Integration (UI Tests)
# runs-on: macos-13
# steps:
# - uses: actions/checkout@v4
# - name: Select Xcode 14.3.1
# run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
# - name: Run tests
# run: make test-integration

ubuntu:
strategy:
matrix:
Expand All @@ -64,19 +54,24 @@ jobs:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: swiftwasm/[email protected]
# - uses: bytecodealliance/actions/wasmtime/setup@v1
# - uses: swiftwasm/setup-swiftwasm@v1
# with:
# shell-action: carton test
# swift-version: "wasm-5.9.2-RELEASE"
# - name: Build tests
# run: swift build --triple wasm32-unknown-wasi --build-tests
# - name: Run tests
# run: wasmtime .build/debug/swift-dependenciesPackageTests.wasm

# windows:
# name: Windows
# runs-on: windows-latest
# steps:
# - uses: compnerd/gha-setup-swift@main
# with:
# branch: swift-5.8-release
# tag: 5.8-RELEASE

# branch: swift-5.10-release
# tag: 5.10-RELEASE
#
# - uses: actions/checkout@v4
# - name: Run tests
# run: swift test
Expand Down
18 changes: 0 additions & 18 deletions Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
"identity" : "swift-benchmark",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/swift-benchmark",
"state" : {
"revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096",
"version" : "0.1.2"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
Expand Down
18 changes: 0 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
}
},
{
"identity" : "swift-benchmark",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/swift-benchmark",
"state" : {
"revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096",
"version" : "0.1.2"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
Expand Down
68 changes: 60 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version: 5.7.1
// swift-tools-version: 5.9

import CompilerPluginSupport
import PackageDescription

let package = Package(
Expand All @@ -14,16 +15,26 @@ let package = Package(
.library(
name: "Dependencies",
targets: ["Dependencies"]
)
),
.library(
name: "DependenciesMacros",
targets: ["DependenciesMacros"]
),
],
dependencies: [
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"601.0.0"),
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-clocks", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.1.0"),
],
targets: [
.target(
name: "DependenciesTestObserver",
dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.target(
name: "Dependencies",
dependencies: [
Expand All @@ -36,22 +47,63 @@ let package = Package(
.testTarget(
name: "DependenciesTests",
dependencies: [
"Dependencies"
"Dependencies",
"DependenciesMacros",
]
),
.executableTarget(
name: "swift-dependencies-benchmark",
.target(
name: "DependenciesMacros",
dependencies: [
"Dependencies",
.product(name: "Benchmark", package: "swift-benchmark"),
"DependenciesMacrosPlugin",
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.macro(
name: "DependenciesMacrosPlugin",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
]
)

#if !os(macOS) && !os(WASI)
package.products.append(
.library(
name: "DependenciesTestObserver",
type: .dynamic,
targets: ["DependenciesTestObserver"]
)
)
#endif

#if !os(WASI)
package.dependencies.append(
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0")
)
package.targets.append(contentsOf: [
.testTarget(
name: "DependenciesMacrosPluginTests",
dependencies: [
"DependenciesMacros",
"DependenciesMacrosPlugin",
.product(name: "MacroTesting", package: "swift-macro-testing"),
]
),
])
#endif

#if !os(Windows)
// Add the documentation compiler plugin if possible
package.dependencies.append(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
)
#endif

for target in package.targets {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings?.append(contentsOf: [
.enableExperimentalFeature("StrictConcurrency")
])
}
25 changes: 3 additions & 22 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import CompilerPluginSupport
import PackageDescription
Expand All @@ -23,7 +23,6 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"601.0.0"),
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-clocks", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
Expand Down Expand Up @@ -66,14 +65,8 @@ let package = Package(
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
.executableTarget(
name: "swift-dependencies-benchmark",
dependencies: [
"Dependencies",
.product(name: "Benchmark", package: "swift-benchmark"),
]
),
]
],
swiftLanguageVersions: [.v6]
)

#if !os(macOS) && !os(WASI)
Expand Down Expand Up @@ -108,15 +101,3 @@ let package = Package(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
)
#endif

for target in package.targets {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings?.append(contentsOf: [
.enableExperimentalFeature("StrictConcurrency")
])
// target.swiftSettings?.append(
// .unsafeFlags([
// "-enable-library-evolution",
// ])
// )
}
4 changes: 2 additions & 2 deletions Sources/Dependencies/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public struct Dependency<Value>: @unchecked Sendable, _HasInitialValues {
/// ```
///
/// - Parameter key: A dependency key to a specific resulting value.
public init<Key: TestDependencyKey>(
public init<Key: TestDependencyKey<Value>>(
_ key: Key.Type,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) where Key.Value == Value {
) {
self.init(
\DependencyValues.[HashableType<Key>(file: file, line: line)],
file: file,
Expand Down
33 changes: 12 additions & 21 deletions Sources/Dependencies/DependencyValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public struct DependencyValues: Sendable {
@TaskLocal static var currentDependency = CurrentDependency()

fileprivate var cachedValues = CachedValues()
private var storage: [ObjectIdentifier: AnySendable] = [:]
private var storage: [ObjectIdentifier: any Sendable] = [:]

/// Creates a dependency values instance.
///
Expand Down Expand Up @@ -214,13 +214,12 @@ public struct DependencyValues: Sendable {
file file: StaticString = #file,
function function: StaticString = #function,
line line: UInt = #line
) -> Key.Value where Key.Value: Sendable {
) -> Key.Value {
get {
guard let base = self.storage[ObjectIdentifier(key)]?.base,
let dependency = base as? Key.Value
guard let base = self.storage[ObjectIdentifier(key)], let dependency = base as? Key.Value
else {
let context =
self.storage[ObjectIdentifier(DependencyContextKey.self)]?.base as? DependencyContext
self.storage[ObjectIdentifier(DependencyContextKey.self)] as? DependencyContext
?? defaultContext

switch context {
Expand Down Expand Up @@ -249,7 +248,7 @@ public struct DependencyValues: Sendable {
return dependency
}
set {
self.storage[ObjectIdentifier(key)] = AnySendable(newValue)
self.storage[ObjectIdentifier(key)] = newValue
}
}

Expand Down Expand Up @@ -295,14 +294,6 @@ public struct DependencyValues: Sendable {
}
}

private struct AnySendable: @unchecked Sendable {
let base: Any
@inlinable
init<Base: Sendable>(_ base: Base) {
self.base = base
}
}

struct CurrentDependency {
var name: StaticString?
var file: StaticString?
Expand Down Expand Up @@ -352,33 +343,33 @@ private final class CachedValues: @unchecked Sendable {
}

private let lock = NSRecursiveLock()
fileprivate var cached = [CacheKey: AnySendable]()
fileprivate var cached = [CacheKey: any Sendable]()

func value<Key: TestDependencyKey>(
for key: Key.Type,
context: DependencyContext,
file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line
) -> Key.Value where Key.Value: Sendable {
) -> Key.Value {
XCTFailContext.$current.withValue(XCTFailContext(file: file, line: line)) {
self.lock.lock()
defer { self.lock.unlock() }

let cacheKey = CacheKey(id: ObjectIdentifier(key), context: context)
guard let base = self.cached[cacheKey]?.base, let value = base as? Key.Value
guard let base = self.cached[cacheKey], let value = base as? Key.Value
else {
let value: Key.Value?
switch context {
case .live:
value = _liveValue(key) as? Key.Value
value = (key as? any DependencyKey.Type)?.liveValue as? Key.Value
case .preview:
value = Key.previewValue
case .test:
value = Key.testValue
}

guard let value = value
guard let value
else {
#if DEBUG
if !DependencyValues.isSetting {
Expand Down Expand Up @@ -436,12 +427,12 @@ private final class CachedValues: @unchecked Sendable {
#endif
let value = Key.testValue
if !DependencyValues.isSetting {
self.cached[cacheKey] = AnySendable(value)
self.cached[cacheKey] = value
}
return value
}

self.cached[cacheKey] = AnySendable(value)
self.cached[cacheKey] = value
return value
}

Expand Down
Loading

0 comments on commit 8d94dcd

Please sign in to comment.