diff --git a/Documentation/Evolution/RegexBuilderDSL.md b/Documentation/Evolution/RegexBuilderDSL.md index 635112e93..73303cb74 100644 --- a/Documentation/Evolution/RegexBuilderDSL.md +++ b/Documentation/Evolution/RegexBuilderDSL.md @@ -329,7 +329,7 @@ public enum RegexComponentBuilder { /// recording its source location. public static func buildExpression( _ regex: R, - file: String = #file, + file: String = #filePath, function: String = #function, line: Int = #line, column: Int = #column @@ -478,7 +478,7 @@ public enum AlternationBuilder { /// recording its source location. public static func buildExpression( _ regex: R, - file: String = #file, + file: String = #filePath, function: String = #function, line: Int = #line, column: Int = #column diff --git a/Package.swift b/Package.swift index e9198908d..5567d18c2 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -31,6 +31,7 @@ let availabilityDefinition = PackageDescription.SwiftSetting.unsafeFlags([ let privateStdlibSettings: [PackageDescription.SwiftSetting] = [ .unsafeFlags(["-Xfrontend", "-disable-implicit-concurrency-module-import"]), .unsafeFlags(["-Xfrontend", "-disable-implicit-string-processing-module-import"]), + .enableUpcomingFeature("MemberImportVisibility"), ] /// Swift settings for building a user-facing stdlib-like module. @@ -38,6 +39,7 @@ let publicStdlibSettings: [PackageDescription.SwiftSetting] = [ .unsafeFlags(["-enable-library-evolution"]), .unsafeFlags(["-Xfrontend", "-disable-implicit-concurrency-module-import"]), .unsafeFlags(["-Xfrontend", "-disable-implicit-string-processing-module-import"]), + .enableUpcomingFeature("MemberImportVisibility"), availabilityDefinition ] diff --git a/Sources/RegexBenchmark/Utils/Time.swift b/Sources/RegexBenchmark/Utils/Time.swift index 36d615450..25e1bebfe 100644 --- a/Sources/RegexBenchmark/Utils/Time.swift +++ b/Sources/RegexBenchmark/Utils/Time.swift @@ -14,7 +14,7 @@ import Foundation import ArgumentParser -public struct Time { +public struct Time: Sendable { public let seconds: TimeInterval public init(_ seconds: TimeInterval) { diff --git a/Sources/RegexBuilder/DSL.swift b/Sources/RegexBuilder/DSL.swift index 42266466f..7e19caae2 100644 --- a/Sources/RegexBuilder/DSL.swift +++ b/Sources/RegexBuilder/DSL.swift @@ -32,21 +32,21 @@ internal protocol _BuiltinRegexComponent: RegexComponent { // MARK: - Primitive regex components @available(SwiftStdlib 5.7, *) -extension String: @retroactive RegexComponent { +extension String: RegexComponent { public typealias Output = Substring public var regex: Regex { .init(verbatim: self) } } @available(SwiftStdlib 5.7, *) -extension Substring: @retroactive RegexComponent { +extension Substring: RegexComponent { public typealias Output = Substring public var regex: Regex { String(self).regex } } @available(SwiftStdlib 5.7, *) -extension Character: @retroactive RegexComponent { +extension Character: RegexComponent { public typealias Output = Substring public var regex: Regex { @@ -55,7 +55,7 @@ extension Character: @retroactive RegexComponent { } @available(SwiftStdlib 5.7, *) -extension UnicodeScalar: @retroactive RegexComponent { +extension UnicodeScalar: RegexComponent { public typealias Output = Substring public var regex: Regex { diff --git a/Sources/RegexTester/CompileOnceTest.swift b/Sources/RegexTester/CompileOnceTest.swift index 56de4afd8..c486603ba 100644 --- a/Sources/RegexTester/CompileOnceTest.swift +++ b/Sources/RegexTester/CompileOnceTest.swift @@ -15,14 +15,14 @@ import _StringProcessing import Foundation @available(SwiftStdlib 5.8, *) -let litPattern = #/a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1/# +nonisolated(unsafe) let litPattern = #/a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1/# @available(SwiftStdlib 5.8, *) -let strPattern = try! Regex("a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1") +nonisolated(unsafe) let strPattern = try! Regex("a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1") @available(SwiftStdlib 5.8, *) struct CompileOnceTest: ParsableCommand { - static let litPattern = #/a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1/# - static let strPattern = try! Regex("a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1") + nonisolated(unsafe) static let litPattern = #/a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1/# + nonisolated(unsafe) static let strPattern = try! Regex("a+bcd(?:g*)ab+?c?de(?:(?:(?i:f)))hij|zzz++a|3|2|1") var N: Int { 10_000 } var testString = "zzzzzzzzza" diff --git a/Sources/TestSupport/TestSupport.swift b/Sources/TestSupport/TestSupport.swift index fc9353f32..65cfd3539 100644 --- a/Sources/TestSupport/TestSupport.swift +++ b/Sources/TestSupport/TestSupport.swift @@ -23,7 +23,7 @@ public func XCTExpectFailure( /// Guards certain tests to make sure we have a new stdlib available. public func ensureNewStdlib( - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) -> Bool { guard #available(SwiftStdlib 5.7, *) else { XCTExpectFailure { XCTFail("Unsupported stdlib", file: file, line: line) } diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index b1953bcd4..fb3b44315 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -12,15 +12,7 @@ // swift run VariadicsGenerator --max-arity 10 > Sources/RegexBuilder/Variadics.swift import ArgumentParser -#if os(macOS) -import Darwin -#elseif canImport(Glibc) -import Glibc -#elseif os(Windows) -import CRT -#elseif canImport(Bionic) -import Bionic -#endif +import Foundation // (T), (T) // (T), (T, T) @@ -100,10 +92,10 @@ func outputForEach( struct StandardErrorStream: TextOutputStream { func write(_ string: String) { - fputs(string, stderr) + FileHandle.standardError.write(Data(string.utf8)) } } -var standardError = StandardErrorStream() +nonisolated(unsafe) var standardError = StandardErrorStream() typealias Counter = Int64 let regexComponentProtocolName = "RegexComponent" diff --git a/Sources/_RegexParser/Utility/AllScalars.swift b/Sources/_RegexParser/Utility/AllScalars.swift index ec3bf81ea..805054465 100644 --- a/Sources/_RegexParser/Utility/AllScalars.swift +++ b/Sources/_RegexParser/Utility/AllScalars.swift @@ -10,7 +10,7 @@ //===----------------------------------------------------------------------===// extension Unicode.Scalar { - public struct AllScalars: RandomAccessCollection { + public struct AllScalars: RandomAccessCollection, Sendable { // Unicode scalar values are in two discontiguous blocks: // 0...0xD7FF and 0xE000...0x10FFFF internal static var lowerSectionFirstValue: Int { 0 } diff --git a/Sources/_RegexParser/Utility/Errors.swift b/Sources/_RegexParser/Utility/Errors.swift index 8dbe67fa0..1ca93c548 100644 --- a/Sources/_RegexParser/Utility/Errors.swift +++ b/Sources/_RegexParser/Utility/Errors.swift @@ -22,7 +22,7 @@ public struct Unsupported: Error, CustomStringConvertible { public init( _ s: String, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { self.message = s @@ -44,7 +44,7 @@ public struct Unreachable: Error, CustomStringConvertible { public init( _ s: String, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { self.message = s diff --git a/Sources/_StringProcessing/Compiler.swift b/Sources/_StringProcessing/Compiler.swift index 09cdef90d..bcc5677e0 100644 --- a/Sources/_StringProcessing/Compiler.swift +++ b/Sources/_StringProcessing/Compiler.swift @@ -115,7 +115,7 @@ func _compileRegex( } @_spi(RegexBenchmark) -public struct _CompileOptions: OptionSet { +public struct _CompileOptions: OptionSet, Sendable { public let rawValue: Int public init(rawValue: Int) { self.rawValue = rawValue diff --git a/Sources/_StringProcessing/ConsumerInterface.swift b/Sources/_StringProcessing/ConsumerInterface.swift index c842b8ba6..62df83b17 100644 --- a/Sources/_StringProcessing/ConsumerInterface.swift +++ b/Sources/_StringProcessing/ConsumerInterface.swift @@ -335,9 +335,11 @@ func consumeCharacterWithSingleScalar( func consumeFunction( for opts: MatchingOptions ) -> (@escaping ScalarPredicate) -> MEProgram.ConsumeFunction { - opts.semanticLevel == .graphemeCluster - ? consumeCharacterWithLeadingScalar - : consumeScalar + if opts.semanticLevel == .graphemeCluster { + consumeCharacterWithLeadingScalar + } else { + consumeScalar + } } extension AST.Atom.CharacterProperty { diff --git a/Sources/_StringProcessing/Regex/DSLTree.swift b/Sources/_StringProcessing/Regex/DSLTree.swift index 62100f148..36c4baf29 100644 --- a/Sources/_StringProcessing/Regex/DSLTree.swift +++ b/Sources/_StringProcessing/Regex/DSLTree.swift @@ -416,7 +416,7 @@ extension DSLTree.Node { @_spi(RegexBuilder) public struct ReferenceID: Hashable { - private static var counter: Int = 0 + nonisolated(unsafe) private static var counter: Int = 0 var base: Int public var _raw: Int { diff --git a/Tests/RegexBuilderTests/AlgorithmsTests.swift b/Tests/RegexBuilderTests/AlgorithmsTests.swift index d9d27e7a1..b51efb067 100644 --- a/Tests/RegexBuilderTests/AlgorithmsTests.swift +++ b/Tests/RegexBuilderTests/AlgorithmsTests.swift @@ -27,7 +27,7 @@ class RegexConsumerTests: XCTestCase { input: String, result: String, _ replace: (Regex.Match) -> String, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { XCTAssertEqual(input.replacing(regex, with: replace), result) @@ -67,7 +67,7 @@ class RegexConsumerTests: XCTestCase { input: String, _ replace: (Regex.Match) -> String, _ tests: (subrange: Range, maxReplacement: Int, result: String)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (subrange, maxReplacement, result) in tests { @@ -125,7 +125,7 @@ class AlgorithmsResultBuilderTests: XCTestCase { _ tests: (input: String, expectedCaptures: MatchType?)..., matchType: MatchType.Type, equivalence: (MatchType, MatchType) -> Bool, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, @RegexComponentBuilder _ content: () -> some RegexComponent ) throws { @@ -152,7 +152,7 @@ class AlgorithmsResultBuilderTests: XCTestCase { func expectEqual( _ algo: EquatableAlgo, _ tests: (input: String, expected: Expected)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, @RegexComponentBuilder _ content: () -> some RegexComponent ) throws { diff --git a/Tests/RegexBuilderTests/CustomTests.swift b/Tests/RegexBuilderTests/CustomTests.swift index 348a1c290..69339fcfc 100644 --- a/Tests/RegexBuilderTests/CustomTests.swift +++ b/Tests/RegexBuilderTests/CustomTests.swift @@ -127,7 +127,7 @@ enum MatchCall { fileprivate func customTest( _ regex: Regex, _ tests: (input: String, call: MatchCall, match: Match?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, call, match) in tests { @@ -147,7 +147,7 @@ fileprivate func customTest( _ regex: some RegexComponent, _ isEquivalent: (Match, Match) -> Bool, _ tests: (input: String, call: MatchCall, match: Match?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, call, match) in tests { @@ -431,7 +431,7 @@ class CustomRegexComponentTests: XCTestCase { func customTest( _ regex: Regex, _ tests: (input: String, match: Match?, expectError: E?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, match, expectError) in tests { @@ -449,7 +449,7 @@ class CustomRegexComponentTests: XCTestCase { func customTest( _ regex: Regex, _ tests: (input: String, match: Match?, expectError1: Error1?, expectError2: Error2?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, match, expectError1, expectError2) in tests { @@ -469,7 +469,7 @@ class CustomRegexComponentTests: XCTestCase { func customTest( _ regex: Regex<(Substring, Capture)>, _ tests: (input: String, match: (Substring, Capture)?, expectError1: Error1?, expectError2: Error2?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, match, expectError1, expectError2) in tests { @@ -490,7 +490,7 @@ class CustomRegexComponentTests: XCTestCase { func customTest( _ regex: Regex<(Substring, Capture1, Capture2)>, _ tests: (input: String, match: (Substring, Capture1, Capture2)?, expectError1: Error1?, expectError2: Error2?)..., - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (input, match, expectError1, expectError2) in tests { @@ -646,7 +646,7 @@ class CustomRegexComponentTests: XCTestCase { _ regex: Regex, _ input: Concat, expected: (wholeMatch: Match?, firstMatch: Match?, prefixMatch: Match?), - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let wholeResult = input.wholeMatch(of: regex)?.output let firstResult = input.firstMatch(of: regex)?.output @@ -661,7 +661,7 @@ class CustomRegexComponentTests: XCTestCase { _ regex: Regex, _ input: Concat, expected: (wholeMatch: CaptureMatch1?, firstMatch: CaptureMatch1?, prefixMatch: CaptureMatch1?), - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let wholeResult = input.wholeMatch(of: regex)?.output let firstResult = input.firstMatch(of: regex)?.output diff --git a/Tests/RegexBuilderTests/DSLListCoalescingTests.swift b/Tests/RegexBuilderTests/DSLListCoalescingTests.swift index 4deb807e6..8afd872c5 100644 --- a/Tests/RegexBuilderTests/DSLListCoalescingTests.swift +++ b/Tests/RegexBuilderTests/DSLListCoalescingTests.swift @@ -401,7 +401,7 @@ class DSLListCoalescingTests: XCTestCase { } -extension DSLTree.Node: @retroactive Equatable { +extension DSLTree.Node: Equatable { public static func == (lhs: DSLTree.Node, rhs: DSLTree.Node) -> Bool { switch (lhs, rhs) { case (.concatenation(let l), .concatenation(let r)): return l == r diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index a72a49fc0..9d067596b 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -14,6 +14,10 @@ import XCTest import RegexBuilder import TestSupport +// Module-local conformances for testing +extension Regex: @unchecked Sendable {} +extension Regex.Match: @unchecked Sendable {} + @available(SwiftStdlib 5.7, *) class RegexDSLTests: XCTestCase { func _testDSLCaptures( @@ -21,7 +25,7 @@ class RegexDSLTests: XCTestCase { matchType: MatchType.Type, _ equivalence: (MatchType, MatchType) -> Bool, xfail: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, @RegexComponentBuilder _ content: () -> some RegexComponent ) throws { @@ -976,7 +980,7 @@ class RegexDSLTests: XCTestCase { func testCanOnlyMatchAtStart() throws { func expectCanOnlyMatchAtStart( _ expectation: Bool, - file: StaticString = #file, line: UInt = #line, + file: StaticString = #filePath, line: UInt = #line, @RegexComponentBuilder _ content: () -> some RegexComponent ) { let regex = content().regex @@ -1643,7 +1647,7 @@ class RegexDSLTests: XCTestCase { var label: String init(_ label: String) { self.label = label } - static var traceOutput = "" + nonisolated(unsafe) static var traceOutput = "" func consuming(_ input: String, startingAt index: String.Index, in bounds: Range) throws -> (upperBound: String.Index, output: Void)? { print("Matching '\(label)'", to: &Self.traceOutput) diff --git a/Tests/RegexTests/AlgorithmsTests.swift b/Tests/RegexTests/AlgorithmsTests.swift index d41917ce3..5807a5d98 100644 --- a/Tests/RegexTests/AlgorithmsTests.swift +++ b/Tests/RegexTests/AlgorithmsTests.swift @@ -17,7 +17,7 @@ class RegexConsumerTests: XCTestCase { } -var enablePrinting = false +let enablePrinting = false func output(_ s: @autoclosure () -> T) { if enablePrinting { print(s()) @@ -33,12 +33,12 @@ func makeSingleUseSequence(element: T, count: Int) -> UnfoldSequence } struct CountedOptionSet: OptionSet { - static var arrayLiteralCreationCount = 0 + nonisolated(unsafe) static var arrayLiteralCreationCount = 0 var rawValue: Int - static var one = Self(rawValue: 1) - static var two = Self(rawValue: 1) + static let one = Self(rawValue: 1) + static let two = Self(rawValue: 1) } extension CountedOptionSet { @@ -120,7 +120,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ regex: String, _ expected: [Range], - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let regex = try! Regex(regex) @@ -164,7 +164,7 @@ class AlgorithmTests: XCTestCase { _ input: String, _ pattern: String, _ expected: [Range], - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let actualSeq: [Range] = input.ranges(of: pattern).map(input.offsets(of:)) XCTAssertEqual(actualSeq, expected, file: file, line: line) @@ -222,7 +222,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ regex: String, _ expected: [Substring], - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let regex = try! Regex(regex) let actual = Array(string.split(separator: regex, omittingEmptySubsequences: false)) @@ -243,7 +243,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ separator: String, _ expected: [Substring], - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let actual = Array(string.split(separator: separator, omittingEmptySubsequences: false)) XCTAssertEqual(actual, expected, file: file, line: line) @@ -379,7 +379,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ regex: String, _ expected: Substring, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let regex = try! Regex(regex) let actual = string.trimmingPrefix(regex) @@ -403,7 +403,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ predicate: (Character) -> Bool, _ expected: Substring, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let actual = string.trimmingPrefix(while: predicate) XCTAssertEqual(actual, expected, file: file, line: line) @@ -425,7 +425,7 @@ class AlgorithmTests: XCTestCase { _ string: String, _ pattern: String, _ expected: Substring, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let actual = string.trimmingPrefix(pattern) XCTAssertEqual(actual, expected, file: file, line: line) @@ -465,7 +465,7 @@ class AlgorithmTests: XCTestCase { _ regex: String, _ replacement: String, _ expected: String, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let regex = try! Regex(regex) let actual = string.replacing(regex, with: replacement) @@ -494,7 +494,7 @@ class AlgorithmTests: XCTestCase { _ pattern: String, _ replacement: String, _ expected: String, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let actual = string.replacing(pattern, with: replacement) XCTAssertEqual(actual, expected, file: file, line: line) @@ -577,7 +577,7 @@ class AlgorithmTests: XCTestCase { _ expected: Bool, _ a: some StringProtocol, _ b: some StringProtocol, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let result = a.firstRange(of: b) != nil XCTAssertEqual(expected, result, file: file, line: line) diff --git a/Tests/RegexTests/CaptureTests.swift b/Tests/RegexTests/CaptureTests.swift index bbf41d3b3..f17ac1967 100644 --- a/Tests/RegexTests/CaptureTests.swift +++ b/Tests/RegexTests/CaptureTests.swift @@ -137,7 +137,7 @@ func captureTest( _ expected: CaptureList, _ tests: (input: String, output: [StringCapture])..., skipEngine: Bool = false, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { let ast = try! parse(regex, .traditional) diff --git a/Tests/RegexTests/CompileTests.swift b/Tests/RegexTests/CompileTests.swift index 1d967c7ed..0879a875e 100644 --- a/Tests/RegexTests/CompileTests.swift +++ b/Tests/RegexTests/CompileTests.swift @@ -152,7 +152,7 @@ extension RegexTests { private func testCompilationEquivalence( _ equivs: [String], - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws { assert(!equivs.isEmpty) @@ -179,7 +179,7 @@ extension RegexTests { private func testCompileError( _ regex: String, _ error: RegexCompilationError, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { do { _ = try _compileRegex(regex) @@ -266,7 +266,7 @@ extension RegexTests { func expectInitialOptions( _ regex: Regex, _ optionSequence: AST.MatchingOptionSequence, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws { var options = MatchingOptions() @@ -280,7 +280,7 @@ extension RegexTests { func expectInitialOptions( _ pattern: String, _ optionSequence: AST.MatchingOptionSequence, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws { let regex = try Regex(pattern) @@ -322,7 +322,7 @@ extension RegexTests { semanticLevel: RegexSemanticLevel? = nil, contains targets: Set = [], doesNotContain invalid: Set = [], - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { do { @@ -562,7 +562,7 @@ extension RegexTests { func expectCanOnlyMatchAtStart( _ regexStr: String, _ expectTrue: Bool, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws { let regex = try Regex(regexStr) diff --git a/Tests/RegexTests/LexTests.swift b/Tests/RegexTests/LexTests.swift index ccfd18eb8..331292a1e 100644 --- a/Tests/RegexTests/LexTests.swift +++ b/Tests/RegexTests/LexTests.swift @@ -19,7 +19,7 @@ func diagnose( expecting expected: ParseError, _ syntax: SyntaxOptions = .traditional, _ f: (inout Parser) -> (), - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { var parser = Parser(Source(input), syntax: syntax) diff --git a/Tests/RegexTests/MatchTests.swift b/Tests/RegexTests/MatchTests.swift index 34fff7465..73b0a7b91 100644 --- a/Tests/RegexTests/MatchTests.swift +++ b/Tests/RegexTests/MatchTests.swift @@ -14,6 +14,10 @@ import XCTest @testable @_spi(RegexBenchmark) @_spi(Foundation) import _StringProcessing import TestSupport +// Module-local conformances for testing +extension Regex: @unchecked Sendable {} +extension Regex.Match: @unchecked Sendable {} + struct MatchError: Error { var message: String init(_ message: String) { @@ -27,7 +31,7 @@ struct MatchError: Error { func _roundTripLiteral( _ regexStr: String, syntax: SyntaxOptions, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws -> Regex? { guard let pattern = try Regex(regexStr, syntax: syntax)._literalPattern else { @@ -45,7 +49,7 @@ func _firstMatch( validateOptimizations: Bool, semanticLevel: RegexSemanticLevel = .graphemeCluster, syntax: SyntaxOptions = .traditional, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws -> (String, [String?])? { var regex = try Regex(regexStr, syntax: syntax).matchingSemantics(semanticLevel) @@ -182,7 +186,7 @@ func flatCaptureTest( xfail: Bool = false, validateOptimizations: Bool = true, semanticLevel: RegexSemanticLevel = .graphemeCluster, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (test, expect) in tests { @@ -244,7 +248,7 @@ func matchTest( xfail: Bool = false, validateOptimizations: Bool = true, semanticLevel: RegexSemanticLevel = .graphemeCluster, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { for (test, expect) in tests { @@ -2831,7 +2835,7 @@ extension RegexTests { func expectCompletion( regex: String, in target: String, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { let expectation = XCTestExpectation(description: "Run the given regex to completion") diff --git a/Tests/RegexTests/ParseTests.swift b/Tests/RegexTests/ParseTests.swift index cbb9e6b32..0bb189731 100644 --- a/Tests/RegexTests/ParseTests.swift +++ b/Tests/RegexTests/ParseTests.swift @@ -40,7 +40,7 @@ func parseTest( throwsError expectedErrors: ParseError..., unsupported: Bool = false, uncheckedErrors: Bool = false, syntax: SyntaxOptions = .traditional, captures expectedCaptures: CaptureList = [], - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { parseTest( @@ -57,7 +57,7 @@ func parseTest( uncheckedErrors: Bool = false, syntax: SyntaxOptions = .traditional, captures expectedCaptures: CaptureList = [], - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { let ast = parseWithRecovery(input, syntax) @@ -143,7 +143,7 @@ func parseTest( @discardableResult func delimiterLexingTest( _ input: String, ignoreTrailing: Bool = false, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) -> String { input.withCString(encodedAs: UTF8.self) { ptr in let endPtr = ptr + input.utf8.count @@ -173,7 +173,7 @@ func parseWithDelimitersTest( _ input: String, _ expecting: AST.Node, throwsError expectedErrors: ParseError..., unsupported: Bool = false, uncheckedErrors: Bool = false, ignoreTrailing: Bool = false, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { // First try lexing. let literal = delimiterLexingTest( @@ -200,7 +200,7 @@ func parseWithDelimitersTest( func parseNotEqualTest( _ lhs: String, _ rhs: String, syntax: SyntaxOptions = .traditional, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let lhsAST = parseWithRecovery(lhs, syntax) let rhsAST = parseWithRecovery(rhs, syntax) @@ -217,7 +217,7 @@ func rangeTest( _ input: String, syntax: SyntaxOptions = .traditional, _ expectedRange: (String) -> Range, at locFn: (AST.Node) -> SourceLocation = \.location, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let ast = parseWithRecovery(input, syntax).root let range = input.offsets(of: locFn(ast).range) @@ -275,7 +275,7 @@ func matchDiagnostics( func diagnosticTest( _ input: String, _ expectedErrors: ParseError..., unsupported: Bool = false, syntax: SyntaxOptions = .traditional, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { let ast = parseWithRecovery(input, syntax) matchDiagnostics( @@ -286,7 +286,7 @@ func diagnosticTest( func diagnosticWithDelimitersTest( _ input: String, _ expectedErrors: ParseError..., unsupported: Bool = false, - ignoreTrailing: Bool = false, file: StaticString = #file, line: UInt = #line + ignoreTrailing: Bool = false, file: StaticString = #filePath, line: UInt = #line ) { // First try lexing. let literal = delimiterLexingTest( @@ -302,7 +302,7 @@ func diagnosticWithDelimitersTest( func delimiterLexingDiagnosticTest( _ input: String, _ expected: DelimiterLexError.Kind, syntax: SyntaxOptions = .traditional, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { do { _ = try input.withCString { ptr in @@ -328,7 +328,7 @@ func delimiterLexingDiagnosticTest( func compilerInterfaceDiagnosticMessageTest( _ input: String, _ expectedErr: String, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) { do { let captureBuffer = UnsafeMutableRawBufferPointer(start: nil, count: 0) diff --git a/Tests/RegexTests/RenderDSLTests.swift b/Tests/RegexTests/RenderDSLTests.swift index b6b249242..1d6427d7b 100644 --- a/Tests/RegexTests/RenderDSLTests.swift +++ b/Tests/RegexTests/RenderDSLTests.swift @@ -30,7 +30,7 @@ extension BidirectionalCollection { func testConversion( _ regex: String, _ expectedDSL: String, - file: StaticString = #file, line: UInt = #line + file: StaticString = #filePath, line: UInt = #line ) throws { let ast = try _RegexParser.parse(regex, .traditional) let actualDSL = renderAsBuilderDSL(ast: ast).trimmingSuffix(while: \.isWhitespace) diff --git a/Tests/RegexTests/SyntaxOptionsTests.swift b/Tests/RegexTests/SyntaxOptionsTests.swift index 13618488c..11e3969db 100644 --- a/Tests/RegexTests/SyntaxOptionsTests.swift +++ b/Tests/RegexTests/SyntaxOptionsTests.swift @@ -14,11 +14,11 @@ import XCTest -private let dplus = oneOrMore( +nonisolated(unsafe) private let dplus = oneOrMore( of: atom(.escaped(.decimalDigit))) -private let dotAST = concat( +nonisolated(unsafe) private let dotAST = concat( dplus, ".", dplus, ".", dplus, ".", dplus) -private let dotASTQuoted = concat( +nonisolated(unsafe) private let dotASTQuoted = concat( dplus, quote("."), dplus, quote("."), dplus, quote("."), dplus) extension RegexTests { diff --git a/Tests/RegexTests/UTS18Tests.swift b/Tests/RegexTests/UTS18Tests.swift index ae7aa2aa0..f4c93a222 100644 --- a/Tests/RegexTests/UTS18Tests.swift +++ b/Tests/RegexTests/UTS18Tests.swift @@ -56,7 +56,7 @@ fileprivate func expectFirstMatch( _ input: String, _ r: Regex, _ output: Output, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line) { XCTAssertEqual(input.firstMatch(of: r)?.output, output, file: file, line: line)