Skip to content
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
4 changes: 2 additions & 2 deletions Documentation/Evolution/RegexBuilderDSL.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public enum RegexComponentBuilder {
/// recording its source location.
public static func buildExpression<R: RegexComponent>(
_ regex: R,
file: String = #file,
file: String = #filePath,
function: String = #function,
line: Int = #line,
column: Int = #column
Expand Down Expand Up @@ -478,7 +478,7 @@ public enum AlternationBuilder {
/// recording its source location.
public static func buildExpression<R: RegexComponent>(
_ regex: R,
file: String = #file,
file: String = #filePath,
function: String = #function,
line: Int = #line,
column: Int = #column
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,13 +31,15 @@ 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.
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
]

Expand Down
2 changes: 1 addition & 1 deletion Sources/RegexBenchmark/Utils/Time.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import Foundation
import ArgumentParser

public struct Time {
public struct Time: Sendable {
public let seconds: TimeInterval

public init(_ seconds: TimeInterval) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output> { .init(verbatim: self) }
}

@available(SwiftStdlib 5.7, *)
extension Substring: @retroactive RegexComponent {
extension Substring: RegexComponent {
public typealias Output = Substring

public var regex: Regex<Output> { String(self).regex }
}

@available(SwiftStdlib 5.7, *)
extension Character: @retroactive RegexComponent {
extension Character: RegexComponent {
public typealias Output = Substring

public var regex: Regex<Output> {
Expand All @@ -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<Output> {
Expand Down
8 changes: 4 additions & 4 deletions Sources/RegexTester/CompileOnceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Sources/TestSupport/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
14 changes: 3 additions & 11 deletions Sources/VariadicsGenerator/VariadicsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this conditional import is vestigial?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the conditional bits are gone – this is just using Foundation to have access to a concurrency-safe stderr-equivalent. (This tool is only used locally to regenerate RegexBuilder overloads.)


// (T), (T)
// (T), (T, T)
Expand Down Expand Up @@ -100,10 +92,10 @@ func outputForEach<C: Collection>(

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"
Expand Down
2 changes: 1 addition & 1 deletion Sources/_RegexParser/Utility/AllScalars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions Sources/_RegexParser/Utility/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Sources/_StringProcessing/ConsumerInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Regex/DSLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Tests/RegexBuilderTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RegexConsumerTests: XCTestCase {
input: String,
result: String,
_ replace: (Regex<R.RegexOutput>.Match) -> String,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertEqual(input.replacing(regex, with: replace), result)
Expand Down Expand Up @@ -67,7 +67,7 @@ class RegexConsumerTests: XCTestCase {
input: String,
_ replace: (Regex<R.RegexOutput>.Match) -> String,
_ tests: (subrange: Range<String.Index>, maxReplacement: Int, result: String)...,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line
) {
for (subrange, maxReplacement, result) in tests {
Expand Down Expand Up @@ -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<RegexOutputType>
) throws {
Expand All @@ -152,7 +152,7 @@ class AlgorithmsResultBuilderTests: XCTestCase {
func expectEqual<Expected: Equatable>(
_ algo: EquatableAlgo,
_ tests: (input: String, expected: Expected)...,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line,
@RegexComponentBuilder _ content: () -> some RegexComponent
) throws {
Expand Down
16 changes: 8 additions & 8 deletions Tests/RegexBuilderTests/CustomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ enum MatchCall {
fileprivate func customTest<Match: Equatable>(
_ regex: Regex<Match>,
_ tests: (input: String, call: MatchCall, match: Match?)...,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line
) {
for (input, call, match) in tests {
Expand All @@ -147,7 +147,7 @@ fileprivate func customTest<Match>(
_ regex: some RegexComponent<Match>,
_ 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 {
Expand Down Expand Up @@ -431,7 +431,7 @@ class CustomRegexComponentTests: XCTestCase {
func customTest<Match: Equatable, E: Error & Equatable>(
_ regex: Regex<Match>,
_ tests: (input: String, match: Match?, expectError: E?)...,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line
) {
for (input, match, expectError) in tests {
Expand All @@ -449,7 +449,7 @@ class CustomRegexComponentTests: XCTestCase {
func customTest<Match: Equatable, Error1: Error & Equatable, Error2: Error & Equatable>(
_ regex: Regex<Match>,
_ 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 {
Expand All @@ -469,7 +469,7 @@ class CustomRegexComponentTests: XCTestCase {
func customTest<Capture: Equatable, Error1: Error & Equatable, Error2: Error & Equatable>(
_ 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 {
Expand All @@ -490,7 +490,7 @@ class CustomRegexComponentTests: XCTestCase {
func customTest<Capture1: Equatable, Capture2: Equatable, Error1: Error & Equatable, Error2: Error & Equatable>(
_ 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 {
Expand Down Expand Up @@ -646,7 +646,7 @@ class CustomRegexComponentTests: XCTestCase {
_ regex: Regex<Match>,
_ 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
Expand All @@ -661,7 +661,7 @@ class CustomRegexComponentTests: XCTestCase {
_ regex: Regex<CaptureMatch1>,
_ 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
Expand Down
2 changes: 1 addition & 1 deletion Tests/RegexBuilderTests/DSLListCoalescingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ 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<MatchType>(
_ tests: (input: String, expectedCaptures: MatchType?)...,
matchType: MatchType.Type,
_ equivalence: (MatchType, MatchType) -> Bool,
xfail: Bool = false,
file: StaticString = #file,
file: StaticString = #filePath,
line: UInt = #line,
@RegexComponentBuilder _ content: () -> some RegexComponent<MatchType>
) throws {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String.Index>) throws -> (upperBound: String.Index, output: Void)? {
print("Matching '\(label)'", to: &Self.traceOutput)
Expand Down
Loading
Loading