Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into case-paths-core
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jan 9, 2025
2 parents 734aae2 + dc49b7a commit 5d99edc
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 70 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,11 @@ jobs:
# - uses: actions/checkout@v4
# - name: Build
# run: swift build -c ${{ matrix.config }}

android:
name: Android
runs-on: ubuntu-22.04
env:
OMIT_MACRO_TESTS: 1
steps:
- uses: johankool/swift-android-test-action@v1
14 changes: 7 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"location" : "https://github.com/swiftlang/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
Expand All @@ -33,8 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
"revision" : "42a086182681cf661f5c47c9b7dc3931de18c6d7",
"version" : "1.17.6"
}
},
{
Expand All @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "27d767d643fa2cf083d0a73d74fa84cacb53e85c",
"version" : "1.4.1"
"revision" : "a3f634d1a409c7979cabc0a71b3f26ffa9fc8af1",
"version" : "1.4.3"
}
}
],
Expand Down
22 changes: 22 additions & 0 deletions Sources/CasePaths/Internal/KeyPath+Sendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if compiler(>=6)
public typealias _SendableKeyPath<Root, Value> = any Sendable & KeyPath<Root, Value>
#else
public typealias _SendableKeyPath<Root, Value> = KeyPath<Root, Value>
#endif

// NB: Dynamic member lookup does not currently support sendable key paths and even breaks
// autocomplete.
//
// * https://github.com/swiftlang/swift/issues/77035
// * https://github.com/swiftlang/swift/issues/77105
extension _AppendKeyPath {
@_transparent
package func unsafeSendable<Root, Value>() -> _SendableKeyPath<Root, Value>
where Self == KeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableKeyPath<Root, Value>.self)
#else
self
#endif
}
}
53 changes: 10 additions & 43 deletions Sources/CasePathsCore/CasePathable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,20 @@ extension Case {
self = Case<Root>()[keyPath: keyPath]
}

// #if swift(>=6)
// public subscript<AppendedValue>(
// dynamicMember keyPath: KeyPath<Value.AllCasePaths, AnyCasePath<Value, AppendedValue>>
// & Sendable
// ) -> Case<AppendedValue>
// where Value: CasePathable {
// Case<AppendedValue>(
// embed: { embed(Value.allCasePaths[keyPath: keyPath].embed($0)) },
// extract: { extract(from: $0).flatMap(Value.allCasePaths[keyPath: keyPath].extract) }
// )
// }
// #else
public subscript<AppendedValue>(
dynamicMember keyPath: KeyPath<Value.AllCasePaths, AnyCasePath<Value, AppendedValue>>
) -> Case<AppendedValue>
where Value: CasePathable {
@UncheckedSendable var keyPath = keyPath
let keyPath = keyPath.unsafeSendable()
return Case<AppendedValue>(
embed: { [$keyPath] in
embed(Value.allCasePaths[keyPath: $keyPath.wrappedValue].embed($0))
embed: {
embed(Value.allCasePaths[keyPath: keyPath].embed($0))
},
extract: { [$keyPath] in
extract(from: $0).flatMap(Value.allCasePaths[keyPath: $keyPath.wrappedValue].extract)
extract: {
extract(from: $0).flatMap(Value.allCasePaths[keyPath: keyPath].extract)
}
)
}
// #endif

public func embed(_ value: Value) -> Any {
self._embed(value)
Expand Down Expand Up @@ -521,25 +508,6 @@ extension AnyCasePath {
}

extension AnyCasePath where Value: CasePathable {
// #if swift(>=6)
// /// Returns a new case path created by appending the case path at the given key path to this one.
// ///
// /// This subscript is automatically invoked by case key path expressions via dynamic member
// /// lookup, and should not be invoked directly.
// ///
// /// - Parameter keyPath: A key path to a case-pathable case path.
// public subscript<AppendedValue>(
// dynamicMember keyPath: KeyPath<Value.AllCasePaths, AnyCasePath<Value, AppendedValue>>
// & Sendable
// ) -> AnyCasePath<Root, AppendedValue> {
// AnyCasePath<Root, AppendedValue>(
// embed: { self.embed(Value.allCasePaths[keyPath: keyPath].embed($0)) },
// extract: {
// self.extract(from: $0).flatMap(Value.allCasePaths[keyPath: keyPath].extract(from:))
// }
// )
// }
// #else
/// Returns a new case path created by appending the case path at the given key path to this one.
///
/// This subscript is automatically invoked by case key path expressions via dynamic member
Expand All @@ -549,17 +517,16 @@ extension AnyCasePath where Value: CasePathable {
public subscript<AppendedValue>(
dynamicMember keyPath: KeyPath<Value.AllCasePaths, AnyCasePath<Value, AppendedValue>>
) -> AnyCasePath<Root, AppendedValue> {
@UncheckedSendable var keyPath = keyPath
let keyPath = keyPath.unsafeSendable()
return AnyCasePath<Root, AppendedValue>(
embed: { [$keyPath] in
embed(Value.allCasePaths[keyPath: $keyPath.wrappedValue].embed($0))
embed: {
embed(Value.allCasePaths[keyPath: keyPath].embed($0))
},
extract: { [$keyPath] in
extract: {
extract(from: $0).flatMap(
Value.allCasePaths[keyPath: $keyPath.wrappedValue].extract(from:)
Value.allCasePaths[keyPath: keyPath].extract(from:)
)
}
)
}
// #endif
}
14 changes: 0 additions & 14 deletions Sources/CasePathsCore/Optional+CasePathable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ extension Optional: CasePathable, CasePathIterable {
}

extension Case {
// #if swift(>=6)
// /// A case path to the presence of a nested value.
// ///
// /// This subscript can chain into an optional's wrapped value without explicitly specifying each
// /// `some` component.
// @_disfavoredOverload
// public subscript<Member>(
// dynamicMember keyPath: KeyPath<Value.AllCasePaths, AnyCasePath<Value, Member?>> & Sendable
// ) -> Case<Member>
// where Value: CasePathable {
// self[dynamicMember: keyPath].some
// }
// #else
/// A case path to the presence of a nested value.
///
/// This subscript can chain into an optional's wrapped value without explicitly specifying each
Expand All @@ -78,7 +65,6 @@ extension Case {
where Value: CasePathable {
self[dynamicMember: keyPath].some
}
// #endif
}

extension Optional.AllCasePaths: Sequence {
Expand Down
2 changes: 1 addition & 1 deletion Tests/CasePathsTests/CasePathableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class CasePathableTests: XCTestCase {
XCTAssertEqual(result, .success(2))
}

#if DEBUG && !os(Linux) && !os(Windows) && !os(WASI)
#if DEBUG && !os(Linux) && !os(Windows) && !os(WASI) && !os(Android)
func testModifyWrongCase() {
guard ProcessInfo.processInfo.environment["CI"] == nil else { return }
var response = Result<Int, MyError>.failure(MyError())
Expand Down
2 changes: 1 addition & 1 deletion Tests/CasePathsTests/CasePathsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ final class CasePathsTests: XCTestCase {
XCTAssertEqual(foo, .bar(.int(42)))
}

#if DEBUG && !os(Linux) && !os(Windows) && !os(WASI)
#if DEBUG && !os(Linux) && !os(Windows) && !os(WASI) && !os(Android)
func testCasePathableModify_Failure() {
guard ProcessInfo.processInfo.environment["CI"] == nil else { return }
var foo = Foo.bar(.int(21))
Expand Down
8 changes: 4 additions & 4 deletions Tests/CasePathsTests/CaseSetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
}

public subscript<Member>(
dynamicMember keyPath: CaseKeyPath<Element, Member> & Sendable
dynamicMember keyPath: CaseKeyPath<Element, Member> // & Sendable
) -> Member? {
get { storage[keyPath].flatMap { $0[case: keyPath] } }
set { storage[keyPath] = newValue.map(keyPath.callAsFunction) }
}

public subscript(
dynamicMember keyPath: CaseKeyPath<Element, Void> & Sendable
dynamicMember keyPath: CaseKeyPath<Element, Void> // & Sendable
) -> Bool {
get { storage[keyPath].flatMap { $0[case: keyPath] } != nil }
set { storage[keyPath] = newValue ? keyPath() : nil }
Expand Down Expand Up @@ -153,9 +153,9 @@
extension CaseSet {
@_disfavoredOverload
public subscript<Member>(
dynamicMember keyPath: CaseKeyPath<Element, Member> & Sendable
dynamicMember keyPath: CaseKeyPath<Element, Member> // & Sendable
) -> CaseSetBuilder<Element, Member> {
CaseSetBuilder(set: self, keyPath: keyPath)
CaseSetBuilder(set: self, keyPath: keyPath.unsafeSendable())
}
}

Expand Down

0 comments on commit 5d99edc

Please sign in to comment.