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
+26 -4
View File
@@ -8,7 +8,29 @@ import Testing
import Foundation
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
/// NRT `build`-closure shim (Phase 201).
///
/// `NRTJob.build` is a non-isolated `@Sendable (SynthesisEngine) throws -> Void`
/// that `EngineHost._executeJob` runs on a background task — *not* the main actor.
/// `SynthesisEngine.add(_:)` is `@MainActor` (Phase 201), so it cannot be invoked
/// directly from inside the off-main build closure. The build closure runs *before*
/// `engine.start()`, so the engine is not yet rendering and nothing else touches it
/// concurrently; hopping the add onto the main actor synchronously is therefore safe
/// in this narrow window. The `nonisolated(unsafe)` captures move the non-`Sendable`
/// engine/synth across the hop — sound because of that exclusivity.
private func nrtBuildAdd(_ engine: SynthesisEngine, _ makeSynth: @escaping @MainActor () -> any Synthesizer) throws {
nonisolated(unsafe) let e: SynthesisEngine = engine
var thrown: (any Error)? = nil
DispatchQueue.main.sync {
MainActor.assumeIsolated {
do { try e.add(makeSynth()) } catch { thrown = error }
}
}
if let thrown: any Error = thrown { throw thrown }
}
/// Phase 197 — `EngineHost` facade coverage.
@MainActor
@Suite("EngineHost (Phase 197)")
struct EngineHostTests {
@@ -240,7 +262,7 @@ struct EngineHostTests {
sampleRate: 44100,
numOutputChannels: 2
) { engine in
try engine.add(ConstSynth(value: 0.1 * Double(i + 1)))
try nrtBuildAdd(engine) { ConstSynth(value: 0.1 * Double(i + 1)) }
}
}
@@ -279,7 +301,7 @@ struct EngineHostTests {
sampleRate: 44100,
numOutputChannels: 2
) { engine in
try engine.add(ConstSynth(value: 0.1))
try nrtBuildAdd(engine) { ConstSynth(value: 0.1) }
},
NRTJob(
outputURL: dir.appendingPathComponent("fail.caf"),
@@ -359,7 +381,7 @@ struct EngineHostTests {
sampleRate: 44100,
numOutputChannels: 2
) { engine in
try engine.add(ConstSynth(value: 0.1))
try nrtBuildAdd(engine) { ConstSynth(value: 0.1) }
}
}
@@ -397,7 +419,7 @@ struct EngineHostTests {
sampleRate: 44100,
numOutputChannels: 2
) { engine in
try engine.add(ConstSynth(value: 0.1))
try nrtBuildAdd(engine) { ConstSynth(value: 0.1) }
}
]
var count: Int = 0