Skip to content

Commit f1043a6

Browse files
committed
Make SpecRegistry Sendable and use Swift Concurrency
TSan found some races in the spec proxy registration code, switch that to Swift async to get better compile time assurance it's free of data races.
1 parent 9460a7e commit f1043a6

File tree

7 files changed

+84
-84
lines changed

7 files changed

+84
-84
lines changed

Sources/SWBCore/Core.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ extension Core {
721721
/// The delegate used to convey information to registry subsystems about the core, including a channel for those registries to report diagnostics. This struct is created by the core itself and refers to the core. It exists as a struct separate from core to avoid creating an ownership cycle between the core and the registry objects.
722722
///
723723
/// Although primarily used by registries during the loading of the core, this delegate is persisted since registries may need to report additional information after loading. For example, new toolchains may be downloaded.
724-
struct CoreRegistryDelegate : PlatformRegistryDelegate, SDKRegistryDelegate, SpecRegistryDelegate, ToolchainRegistryDelegate, SpecRegistryProvider {
724+
struct CoreRegistryDelegate : PlatformRegistryDelegate, SDKRegistryDelegate, SpecRegistryDelegate, ToolchainRegistryDelegate, SpecRegistryProvider, Sendable {
725725
unowned let core: Core
726726

727727
var diagnosticsEngine: DiagnosticProducingDelegateProtocolPrivate<DiagnosticsEngine> {

Sources/SWBCore/DiagnosticSupport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Diagnostic {
1818
public static let libRemarksAvailable = isLibRemarksAvailable()
1919
}
2020

21-
public struct DiagnosticProducingDelegateProtocolPrivate<T> {
21+
public struct DiagnosticProducingDelegateProtocolPrivate<T: Sendable>: Sendable {
2222
fileprivate let instance: T
2323

2424
public init(_ instance: T) {

Sources/SWBCore/SpecImplementations/SpecRegistry.swift

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

Tests/SWBCoreTests/PlatformRegistryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import SWBMacro
1919

2020
@Suite fileprivate struct PlatformRegistryTests {
2121
final class TestDataDelegate: PlatformRegistryDelegate {
22-
final class MockSpecRegistryDelegate : SpecRegistryDelegate {
22+
final class MockSpecRegistryDelegate: SpecRegistryDelegate, Sendable {
2323
let diagnosticsEngine: DiagnosticProducingDelegateProtocolPrivate<DiagnosticsEngine>
2424

2525
init(_ diagnosticsEngine: DiagnosticsEngine) {

Tests/SWBCoreTests/SpecLoadingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import SWBMacro
2121
var specDataCaches = Registry<Spec, any SpecDataCache>()
2222

2323
class TestDataDelegate : SpecParserDelegate {
24-
class MockSpecRegistryDelegate : SpecRegistryDelegate {
24+
final class MockSpecRegistryDelegate: SpecRegistryDelegate, Sendable {
2525
private let _diagnosticsEngine: DiagnosticsEngine
2626

2727
init(_ diagnosticsEngine: DiagnosticsEngine) {

Tests/SWBCoreTests/SpecParserTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fileprivate final class MockSpecType: SpecType {
2929

3030
@Suite fileprivate struct SpecParserTests {
3131
final class TestDataDelegate : SpecParserDelegate {
32-
class MockSpecRegistryDelegate : SpecRegistryDelegate {
32+
final class MockSpecRegistryDelegate: SpecRegistryDelegate, Sendable {
3333
private let _diagnosticsEngine: DiagnosticsEngine
3434

3535
init(_ diagnosticsEngine: DiagnosticsEngine) {

Tests/SWBCoreTests/SpecRegistryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SWBUtil
1818
@_spi(Testing) import SWBCore
1919

2020
@Suite fileprivate struct SpecRegistryTests: CoreBasedTests {
21-
final class TestDataDelegate: SpecRegistryDelegate {
21+
final class TestDataDelegate: SpecRegistryDelegate, Sendable {
2222
private let _diagnosticsEngine = DiagnosticsEngine()
2323

2424
var diagnosticsEngine: DiagnosticProducingDelegateProtocolPrivate<DiagnosticsEngine> {

0 commit comments

Comments
 (0)