fixes for Swift 6 and threading concerns

This commit is contained in:
2026-06-02 12:09:44 -07:00
parent 2fa4bfd45e
commit 6d3a0930a1
327 changed files with 1596 additions and 199 deletions
+21 -3
View File
@@ -81,7 +81,12 @@ open class LyrebirdAudioUnit: AUAudioUnit {
/// Required override. Construct and return the synthesizer instance that this
/// AU should host.
open class func makeSynthesizer() -> SynthesizerBase {
///
/// `@MainActor` (Phase 201): the override constructs a `@MainActor` `SynthesizerBase`
/// subclass, so the factory must be main-actor-isolated for a consumer building under
/// the MainActor-default mode to override it with no concurrency annotations — the same
/// rationale as `SynthesizerBase.build()`. Invoked from `init` on the host's main thread.
@MainActor open class func makeSynthesizer() -> SynthesizerBase {
fatalError("LyrebirdAudioUnit subclasses must override `makeSynthesizer()`")
}
@@ -222,7 +227,9 @@ open class LyrebirdAudioUnit: AUAudioUnit {
) throws {
// 1. Resolve subclass configuration.
let synth: SynthesizerBase = Self.makeSynthesizer()
// `makeSynthesizer()` is `@MainActor` (it builds a `@MainActor` synth); `AUAudioUnit`
// instances are created by the host on the main thread, so `assumeIsolated` is valid.
let synth: SynthesizerBase = MainActor.assumeIsolated { Self.makeSynthesizer() }
let blockSize: Int = Self.lyrebirdBlockSize
let outputBusSpecs: [LyrebirdAUBusSpec] = Self.lyrebirdOutputBusses
let inputBusSpecs: [LyrebirdAUBusSpec] = Self.lyrebirdInputBusses
@@ -436,7 +443,18 @@ open class LyrebirdAudioUnit: AUAudioUnit {
newEngine.auOutputBusOffsets = _outputBusOffsets
newEngine.auInputBusOffsets = _inputBusOffsets
try newEngine.start()
try newEngine.add(synthesizer)
// `engine.add` is `@MainActor` (Phase 201). `allocateRenderResources()` overrides
// `AUAudioUnit`'s nonisolated declaration, so this method cannot itself be
// `@MainActor`. AU hosts usually call render-resource allocation on the main thread,
// but the contract does not guarantee it — the bridge runs the add inline when on
// main and hops synchronously otherwise, so an off-main host (e.g. auval) does not
// trap. The `nonisolated(unsafe)` local transfers the non-`Sendable` engine into the
// bridge closure without tripping region-isolation's sending check (the same value is
// reused below at `engine = newEngine`). `synthesizer` is `Sendable` (`SynthesizerBase`
// is `@MainActor` ⇒ implicitly Sendable), so it needs no such annotation.
nonisolated(unsafe) let engineToConfigure: SynthesisEngine = newEngine
let synthToAdd: SynthesizerBase = synthesizer
try lyrebirdRunMainActorMutation { try engineToConfigure.add(synthToAdd) }
engine = newEngine
}