Skip to content

Make SourceLocationConverter Sendable #2675

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
Jun 12, 2024
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
5 changes: 3 additions & 2 deletions Sources/SwiftSyntax/SourceLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fileprivate struct SourceLocationDirectiveArguments {
/// Converts ``AbsolutePosition``s of syntax nodes to ``SourceLocation``s, and
/// vice-versa. The ``AbsolutePosition``s must be originating from nodes that are
/// part of the same tree that was used to initialize this class.
public final class SourceLocationConverter {
public final class SourceLocationConverter: Sendable {
private let fileName: String
/// The source of the file, modeled as data so it can contain invalid UTF-8.
private let source: [UInt8]
Expand All @@ -157,7 +157,7 @@ public final class SourceLocationConverter {
/// `#sourceLocation(...)` directive within the current file.
/// - `arguments` are the `file` and `line` arguments of the directive or `nil`
/// if spelled as `#sourceLocation()` to reset the source location directive.
private var sourceLocationDirectives: [(sourceLine: Int, arguments: SourceLocationDirectiveArguments?)] = []
private let sourceLocationDirectives: [(sourceLine: Int, arguments: SourceLocationDirectiveArguments?)]

/// Create a new ``SourceLocationConverter`` to convert between ``AbsolutePosition``
/// and ``SourceLocation`` in a syntax tree.
Expand Down Expand Up @@ -212,6 +212,7 @@ public final class SourceLocationConverter {
return computeLines(SyntaxText(buffer: syntaxArenaBuf))
}
precondition(source.utf8.count == endOfFile.utf8Offset)
self.sourceLocationDirectives = []
}

/// Execute the body with an array that contains each source line.
Expand Down