Skip to content
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

Fix language mode compatibility #158

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 16 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,29 @@ jobs:
- name: Test example tvOS
run: scripts/test.sh example-cross-platform tvos

upcoming_feature:
name: Upcoming features
test_upcoming_features:
name: Test upcoming features with Xcode 15
runs-on: macos-14
env:
DEVELOPER_DIR: /Applications/Xcode_15.4.app
steps:
- uses: actions/checkout@v4
- name: Test with upcoming features
- name: Test upcoming features
run: ENABLE_UPCOMING_FEATURES=1 scripts/test.sh library ios

test_language_mode:
name: Test Swift 5 language mode
runs-on: macos-14
strategy:
matrix:
ra1028 marked this conversation as resolved.
Show resolved Hide resolved
enable_upcoming_features:
- 0
- 1
steps:
- uses: actions/checkout@v4
- name: Test Swift 5 language mode
run: ENABLE_UPCOMING_FEATURES=${{ matrix.enable_upcoming_features }} scripts/test.sh library ios SWIFT_VERSION=5

benchmark:
name: Benchmark
runs-on: macos-14
Expand Down
18 changes: 15 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import PackageDescription

let swiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("ExistentialAny")
]
let swiftSettings: [SwiftSetting]

if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
swiftSettings = [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("InferSendableFromCaptures"),
.enableUpcomingFeature("StrictConcurrency"),
]
}
else {
swiftSettings = [
.enableUpcomingFeature("ExistentialAny")
]
}

let package = Package(
name: "swiftui-atom-properties",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let swiftSettings: [SwiftSetting]

if Context.environment["ENABLE_UPCOMING_FEATURES"] != nil {
if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
swiftSettings = [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("DisableOutwardActorInference"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Atoms/AsyncPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum AsyncPhase<Success, Failure: Error> {
}
}

#if compiler(>=6)
#if swift(>=6)
/// Creates a new phase by evaluating a async throwing closure, capturing the
/// returned value as a success, or thrown error as a failure.
///
Expand Down
6 changes: 3 additions & 3 deletions Sources/Atoms/Atom/AsyncPhaseAtom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public protocol AsyncPhaseAtom: AsyncAtom where Produced == AsyncPhase<Success,
/// The type of success value that this atom produces.
associatedtype Success

#if compiler(>=6)
#if swift(>=6)
/// The type of errors that this atom produces.
associatedtype Failure: Error

Expand Down Expand Up @@ -80,7 +80,7 @@ public extension AsyncPhaseAtom {
var producer: AtomProducer<Produced> {
AtomProducer { context in
let task = Task {
#if compiler(>=6)
#if swift(>=6)
do throws(Failure) {
let value = try await context.transaction(value)

Expand Down Expand Up @@ -119,7 +119,7 @@ public extension AsyncPhaseAtom {
var phase = Produced.suspending

let task = Task {
#if compiler(>=6)
#if swift(>=6)
do throws(Failure) {
let value = try await context.transaction(value)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Atoms/Core/Producer/AtomProducerContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal struct AtomProducerContext<Value> {
return body(context)
}

#if compiler(>=6)
#if swift(>=6)
func transaction<T, E: Error>(_ body: @MainActor (AtomTransactionContext) async throws(E) -> T) async throws(E) -> T {
transactionState.begin()
let context = AtomTransactionContext(store: store, transactionState: transactionState)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Atoms/Core/SubscriberState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
internal final class SubscriberState {
let token = SubscriberKey.Token()

#if compiler(>=6)
#if swift(>=6)
nonisolated(unsafe) var subscribing = Set<AtomKey>()
nonisolated(unsafe) var unsubscribe: ((Set<AtomKey>) -> Void)?

Expand Down
4 changes: 2 additions & 2 deletions Sources/Atoms/Modifier/ChangesOfModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension Atom {
/// - Parameter keyPath: A key path for the property of the original atom value.
///
/// - Returns: An atom that provides the partial property of the original atom value.
#if compiler(>=6) || hasFeature(InferSendableFromCaptures)
#if swift(>=6) || hasFeature(InferSendableFromCaptures)
func changes<T: Equatable>(
of keyPath: any KeyPath<Produced, T> & Sendable
) -> ModifiedAtom<Self, ChangesOfModifier<Produced, T>> {
Expand All @@ -48,7 +48,7 @@ public struct ChangesOfModifier<Base, Produced: Equatable>: AtomModifier {
/// A type of value the modified atom produces.
public typealias Produced = Produced

#if compiler(>=6) || hasFeature(InferSendableFromCaptures)
#if swift(>=6) || hasFeature(InferSendableFromCaptures)
/// A type representing the stable identity of this modifier.
public struct Key: Hashable, Sendable {
private let keyPath: any KeyPath<Base, Produced> & Sendable
Expand Down
2 changes: 1 addition & 1 deletion Sources/Atoms/PropertyWrapper/ViewContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct ViewContext: DynamicProperty {
self.location = SourceLocation(fileID: fileID, line: line)
}

#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@State
private var signal = false
@State
Expand Down
2 changes: 1 addition & 1 deletion Sources/Atoms/PropertyWrapper/Watch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct Watch<Node: Atom>: DynamicProperty {
/// access ``wrappedValue`` directly. Instead, you use the property variable created
/// with the `@Watch` attribute.
/// Accessing this property starts watching the atom.
#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@MainActor
#endif
public var wrappedValue: Node.Produced {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Atoms/PropertyWrapper/WatchState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct WatchState<Node: StateAtom>: DynamicProperty {
/// with the `@WatchState` attribute.
/// Accessing to the getter of this property starts watching the atom, but doesn't
/// by setting a new value.
#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@MainActor
#endif
public var wrappedValue: Node.Produced {
Expand All @@ -64,7 +64,7 @@ public struct WatchState<Node: StateAtom>: DynamicProperty {
/// To get the ``projectedValue``, prefix the property variable with `$`.
/// Accessing this property itself does not start watching the atom, but does when
/// the view accesses to the getter of the binding.
#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@MainActor
#endif
public var projectedValue: Binding<Node.Produced> {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Atoms/PropertyWrapper/WatchStateObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct WatchStateObject<Node: ObservableObjectAtom>: DynamicProperty {
/// access ``wrappedValue`` directly. Instead, you use the property variable created
/// with the `@WatchStateObject` attribute.
/// Accessing this property starts watching the atom.
#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@MainActor
#endif
public var wrappedValue: Node.Produced {
Expand All @@ -95,7 +95,7 @@ public struct WatchStateObject<Node: ObservableObjectAtom>: DynamicProperty {
///
/// Use the projected value to pass a binding value down a view hierarchy.
/// To get the projected value, prefix the property variable with `$`.
#if compiler(>=6) || hasFeature(DisableOutwardActorInference)
#if swift(>=6) || hasFeature(DisableOutwardActorInference)
@MainActor
#endif
public var projectedValue: Wrapper {
Expand Down
2 changes: 1 addition & 1 deletion Tests/AtomsTests/Atom/AsyncPhaseAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AsyncPhaseAtomTests: XCTestCase {

let phase = context.watch(atom)

#if compiler(>=6)
#if swift(>=6)
XCTAssertEqual(phase.error, URLError(.badURL))
#else
XCTAssertEqual(phase.error as? URLError, URLError(.badURL))
Expand Down
2 changes: 1 addition & 1 deletion Tests/AtomsTests/Utilities/TestAtom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct TestAsyncPhaseAtom<Success, Failure: Error>: AsyncPhaseAtom, @unchecked S
UniqueKey()
}

#if compiler(>=6)
#if swift(>=6)
func value(context: Context) async throws(Failure) -> Success {
try getResult().get()
}
Expand Down
13 changes: 9 additions & 4 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -eu

TARGET=$1
PLATFORM=$2
ARGS=${@:3}

pushd "$(cd $(dirname $0)/.. && pwd)" &>/dev/null

Expand All @@ -22,20 +23,24 @@ watchos)
;;
esac

clean_test() {
xcodebuild clean test "$@" $ARGS
}

case $TARGET in
library)
xcodebuild clean test -scheme swiftui-atom-properties -destination platform="$platform"
clean_test -scheme swiftui-atom-properties -destination platform="$platform"
;;
example-ios)
cd Examples/Packages/iOS
xcodebuild clean test -scheme iOSExamples -destination platform="$platform"
clean_test -scheme iOSExamples -destination platform="$platform"
;;
example-cross-platform)
cd Examples/Packages/CrossPlatform
xcodebuild clean test -scheme CrossPlatformExamples -destination platform="$platform"
clean_test -scheme CrossPlatformExamples -destination platform="$platform"
;;
benchmark)
cd Benchmarks
xcodebuild clean test -scheme BenchmarkTests -destination platform="$platform"
clean_test -scheme BenchmarkTests -destination platform="$platform"
;;
esac