Skip to content

Commit 8dbffb9

Browse files
authored
Fix language mode compatibility (#158)
* Setup further testing on CI * Use swift(version) compiler condition instead of compiler(version) * Revert it back to use compiler() instead of swift() * Add nonisolated init under conditional compilation hasFeature(IsolatedDefaultValues)
1 parent 7b1510d commit 8dbffb9

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

.github/workflows/test.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,29 @@ jobs:
4545
- name: Test example tvOS
4646
run: scripts/test.sh example-cross-platform tvos
4747

48-
upcoming_feature:
49-
name: Upcoming features
48+
test_upcoming_features:
49+
name: Test upcoming features with Xcode 15
5050
runs-on: macos-14
5151
env:
5252
DEVELOPER_DIR: /Applications/Xcode_15.4.app
5353
steps:
5454
- uses: actions/checkout@v4
55-
- name: Test with upcoming features
55+
- name: Test upcoming features
5656
run: ENABLE_UPCOMING_FEATURES=1 scripts/test.sh library ios
5757

58+
test_language_mode:
59+
name: Test Swift 5 language mode
60+
runs-on: macos-14
61+
strategy:
62+
matrix:
63+
enable_upcoming_features:
64+
- 0
65+
- 1
66+
steps:
67+
- uses: actions/checkout@v4
68+
- name: Test Swift 5 language mode
69+
run: ENABLE_UPCOMING_FEATURES=${{ matrix.enable_upcoming_features }} scripts/test.sh library ios SWIFT_VERSION=5
70+
5871
benchmark:
5972
name: Benchmark
6073
runs-on: macos-14

Package.swift

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
import PackageDescription
44

5-
let swiftSettings: [SwiftSetting] = [
6-
.enableUpcomingFeature("ExistentialAny")
7-
]
5+
let swiftSettings: [SwiftSetting]
6+
7+
if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
8+
swiftSettings = [
9+
.enableUpcomingFeature("DisableOutwardActorInference"),
10+
.enableUpcomingFeature("InferSendableFromCaptures"),
11+
.enableUpcomingFeature("IsolatedDefaultValues"),
12+
.enableUpcomingFeature("StrictConcurrency"),
13+
.enableUpcomingFeature("ExistentialAny"),
14+
]
15+
}
16+
else {
17+
swiftSettings = [
18+
.enableUpcomingFeature("ExistentialAny")
19+
]
20+
}
821

922
let package = Package(
1023
name: "swiftui-atom-properties",

Package@swift-5.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import PackageDescription
44

55
let swiftSettings: [SwiftSetting]
66

7-
if Context.environment["ENABLE_UPCOMING_FEATURES"] != nil {
7+
if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
88
swiftSettings = [
9-
.enableUpcomingFeature("ExistentialAny"),
109
.enableUpcomingFeature("DisableOutwardActorInference"),
10+
.enableUpcomingFeature("IsolatedDefaultValues"),
11+
.enableUpcomingFeature("ExistentialAny"),
1112
]
1213
}
1314
else {

Sources/Atoms/Core/SubscriberState.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import Foundation
44
internal final class SubscriberState {
55
let token = SubscriberKey.Token()
66

7+
#if !hasFeature(IsolatedDefaultValues)
8+
nonisolated init() {}
9+
#endif
10+
711
#if compiler(>=6)
812
nonisolated(unsafe) var subscribing = Set<AtomKey>()
913
nonisolated(unsafe) var unsubscribe: ((Set<AtomKey>) -> Void)?
@@ -34,10 +38,6 @@ internal final class SubscriberState {
3438
_modify { yield &_unsubscribe.value }
3539
}
3640

37-
#if hasFeature(DisableOutwardActorInference)
38-
nonisolated init() {}
39-
#endif
40-
4141
deinit {
4242
if Thread.isMainThread {
4343
_unsubscribe.value?(_subscribing.value)

scripts/test.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -eu
44

55
TARGET=$1
66
PLATFORM=$2
7+
ARGS=${@:3}
78

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

@@ -22,20 +23,24 @@ watchos)
2223
;;
2324
esac
2425

26+
clean_test() {
27+
xcodebuild clean test "$@" $ARGS
28+
}
29+
2530
case $TARGET in
2631
library)
27-
xcodebuild clean test -scheme swiftui-atom-properties -destination platform="$platform"
32+
clean_test -scheme swiftui-atom-properties -destination platform="$platform"
2833
;;
2934
example-ios)
3035
cd Examples/Packages/iOS
31-
xcodebuild clean test -scheme iOSExamples -destination platform="$platform"
36+
clean_test -scheme iOSExamples -destination platform="$platform"
3237
;;
3338
example-cross-platform)
3439
cd Examples/Packages/CrossPlatform
35-
xcodebuild clean test -scheme CrossPlatformExamples -destination platform="$platform"
40+
clean_test -scheme CrossPlatformExamples -destination platform="$platform"
3641
;;
3742
benchmark)
3843
cd Benchmarks
39-
xcodebuild clean test -scheme BenchmarkTests -destination platform="$platform"
44+
clean_test -scheme BenchmarkTests -destination platform="$platform"
4045
;;
4146
esac

0 commit comments

Comments
 (0)