Skip to content

Make DiagnosticEngine thread safe #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions Sources/SwiftSyntax/DiagnosticEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,39 @@ public class DiagnosticEngine {
public init() {
}

private var consumersQueue = DispatchQueue(
label: "com.apple.SwiftSyntax.DiagnosticEngine.consumers", attributes: .concurrent)
private var _consumers = [DiagnosticConsumer]()
/// The list of consumers of the diagnostic passing through this engine.
internal var consumers = [DiagnosticConsumer]()
private var consumers: [DiagnosticConsumer] {
get {
consumersQueue.sync {
_consumers
}
}

public private(set) var diagnostics = [Diagnostic]()
set {
consumersQueue.async(flags: .barrier) {
self._consumers = newValue
}
}
}

private var diagnosticsQueue = DispatchQueue(
label: "com.apple.SwiftSyntax.DiagnosticEngine.diagnostics", attributes: .concurrent)
private var _diagnostics = [Diagnostic]()
public private(set) var diagnostics: [Diagnostic] {
get {
diagnosticsQueue.sync {
_diagnostics
}
}
set {
diagnosticsQueue.async(flags: .barrier) {
self._diagnostics = newValue
}
}
}

internal var needsLineColumn: Bool {
// Check if any consumer is interested in line and column.
Expand Down