Skip to content

Suppress compiler warnings about Errors with non-Sendable members #729

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
Mar 9, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion Sources/_RegexParser/Regex/Parse/CompilerInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ public let currentRegexLiteralFormatVersion = 1

@_spi(CompilerInterface)
public struct CompilerLexError: Error {
var underlyingLocation: UnsafeSourceLocation

public var message: String
public var location: UnsafeRawPointer
public var location: UnsafeRawPointer { return underlyingLocation.ptr }
public var completelyErroneous: Bool

init(
message: String, location: UnsafeRawPointer, completelyErroneous: Bool
) {
self.message = message
self.underlyingLocation = UnsafeSourceLocation(location)
self.completelyErroneous = completelyErroneous
}
}

/// Interface for the Swift compiler.
Expand Down
20 changes: 18 additions & 2 deletions Sources/_RegexParser/Regex/Parse/DelimiterLexing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ extension Delimiter {
}
}

/// A wrapper for an `UnsafeRawPointer` representing a source location, marked
/// `@unchecked Sendable` to help errors carrying such information satisfy their
/// `Sendable` requirement.
///
/// TODO: consider further refactoring to avoid needing to lie to the compiler
/// about Sendability.
struct UnsafeSourceLocation: @unchecked Sendable {
let ptr: UnsafeRawPointer

init(_ ptr: UnsafeRawPointer) {
self.ptr = ptr
}
}

public struct DelimiterLexError: Error, CustomStringConvertible {
public enum Kind: Hashable {
case unterminated
Expand All @@ -81,12 +95,14 @@ public struct DelimiterLexError: Error, CustomStringConvertible {

public var kind: Kind

var resumeLocation: UnsafeSourceLocation

/// The pointer at which to resume lexing.
public var resumePtr: UnsafeRawPointer
public var resumePtr: UnsafeRawPointer { resumeLocation.ptr }

init(_ kind: Kind, resumeAt resumePtr: UnsafeRawPointer) {
self.kind = kind
self.resumePtr = resumePtr
self.resumeLocation = UnsafeSourceLocation(resumePtr)
}

public var description: String {
Expand Down
3 changes: 2 additions & 1 deletion Sources/_StringProcessing/Engine/MEBuiltins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,10 @@ extension String {
) -> String.Index? {
// TODO: Branch here on scalar semantics
// Don't want to pay character cost if unnecessary
guard var (char, next) =
guard let (char, nextIndex) =
characterAndEnd(at: currentPosition, limitedBy: end)
else { return nil }
var next = nextIndex
let scalar = unicodeScalars[currentPosition]

let asciiCheck = !isStrictASCII
Expand Down