Skip to content

Commit

Permalink
Isolation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Feb 16, 2024
1 parent 84e86a9 commit 82378e1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 47 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ on:
- main

env:
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer

jobs:
test:
name: Test
runs-on: macOS-13
runs-on: macOS-14
strategy:
matrix:
destination:
Expand All @@ -28,7 +28,5 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install XCBeautify
run: brew install xcbeautify
- name: Test platform ${{ matrix.destination }}
run: set -o pipefail && xcodebuild -scheme Extendable-Package -destination "${{ matrix.destination }}" test | xcbeautify --renderer github-actions
run: set -o pipefail && xcodebuild -scheme Extendable-Package -destination "${{ matrix.destination }}" test | xcbeautify
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Extendable
A set of utilities for more pleasant work with ExtensionKit

> [!NOTE]
> CI failure for the main branch is expected until Swift 5.10 is available in GitHub action images.
## Installation

```swift
Expand Down Expand Up @@ -125,6 +128,23 @@ You can its `AppExtensionBrowserView` and `ExtensionHostingView` to integrate th
let process = try await AppExtensionProcess(appExtensionIdentity: identity)
```

## Isolation and AppExtension

Currently, the `init` in the `AppExtention` protocol lacks any isolation. This makes it difficult to initialize instance variables if you are relying on the true-but-unexpressed `@MainActor` isolation of extensions. I've included a workaround that can help. SE-0414 will make this unecessary, as will ExtensionFoundation adding annotations. In the mean time though, it's nice to have no warnings.

```swift
@main
final class MyExtension: AppExtension {
@InitializerTransferred private var value: MainActorType

nonisolated init() {
self._value = InitializerTransferred(mainActorProvider: {
MainActorType()
})
}
}
```

## Contributing and Collaboration

I would love to hear from you! Issues or pull requests work great. A [Discord server][discord] is also available for live help, but I have a strong bias towards answering in the form of documentation.
Expand Down
21 changes: 21 additions & 0 deletions Sources/Extendable/AppExtension+Init.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

// from https://forums.swift.org/t/complete-checking-with-an-incorrectly-annotated-init-conformance/69955/7

/// Used to initialize properties for non-isolated init conformance.
///
/// Will be obseleted by SE-0414
@propertyWrapper
public struct InitializerTransferred<Value>: @unchecked Sendable {
public let wrappedValue: Value

public init(_ wrappedValue: Value) {
self.wrappedValue = wrappedValue
}

public init(mainActorProvider: @MainActor () -> Value) {
self.wrappedValue = MainActor.assumeIsolated {

Check failure on line 17 in Sources/Extendable/AppExtension+Init.swift

View workflow job for this annotation

GitHub Actions / Test (platform=iOS Simulator,name=iPhone 14)

'assumeIsolated(_:file:line:)' is only available in iOS 17.0 or newer
mainActorProvider()
}
}
}
2 changes: 1 addition & 1 deletion Sources/Extendable/ConnectingAppExtensionScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public struct ConnectingAppExtensionScene<Content: View>: AppExtensionScene {


public nonisolated var body: some AppExtensionScene {
MainActor.runUnsafely {
MainActor.assumeIsolated {

Check failure on line 52 in Sources/Extendable/ConnectingAppExtensionScene.swift

View workflow job for this annotation

GitHub Actions / Test (platform=macOS)

'assumeIsolated(_:file:line:)' is only available in macOS 14.0 or newer
PrimitiveAppExtensionScene(id: sceneID) {
connectingView
} onConnection: { connection in
Expand Down
20 changes: 0 additions & 20 deletions Sources/Extendable/MainActor+runUnsafely.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/ExtendableHost/ExtensionHostingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension ExtensionHostingView {
}

public nonisolated func hostViewControllerDidActivate(_ viewController: EXHostViewController) {
MainActor.runUnsafely {
MainActor.assumeIsolated {

Check failure on line 52 in Sources/ExtendableHost/ExtensionHostingView.swift

View workflow job for this annotation

GitHub Actions / Test (platform=macOS)

'assumeIsolated(_:file:line:)' is only available in macOS 14.0 or newer
guard let handler = connectionHandler else { return }

do {
Expand Down
20 changes: 0 additions & 20 deletions Sources/ExtendableHost/MainActor+runUnsafely.swift

This file was deleted.

0 comments on commit 82378e1

Please sign in to comment.