From f8ff869c4faecb2bd96bb28438af477de591e06b Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Tue, 29 Sep 2026 17:14:03 -0700 Subject: [PATCH] Don't build the stdlib modules as members of the same package. When this project is built with SwiftPM, the `_RegexParser`, `_StringProcessing`, and `RegexBuilder` modules are all built with `-package-name swift_experimental_string_processing`. The compiler does not consider a conformance to be retroactive when the conforming type or the protocol comes from a module in the same package, so the `@retroactive` attributes in `RegexBuilder` became errors in the Swift 6 language mode and were removed. However, when these modules are built with CMake as part of the Swift toolchain, no package name is specified and the compiler instead warns that the conformances of `String`, `Substring`, `Character`, and `UnicodeScalar` to `RegexComponent` are retroactive. Opt the stdlib targets out of package access in the package manifest so that the SwiftPM build matches the toolchain build, and restore the `@retroactive` attributes. --- Package.swift | 3 +++ Sources/RegexBuilder/DSL.swift | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 5567d18c2..1ca2a7400 100644 --- a/Package.swift +++ b/Package.swift @@ -74,6 +74,7 @@ let package = Package( .target( name: "_RegexParser", dependencies: [], + packageAccess: false, swiftSettings: privateStdlibSettings), .testTarget( name: "MatchingEngineTests", @@ -89,10 +90,12 @@ let package = Package( "_RegexParser", "_CUnicode", ], + packageAccess: false, swiftSettings: publicStdlibSettings), .target( name: "RegexBuilder", dependencies: ["_StringProcessing", "_RegexParser"], + packageAccess: false, swiftSettings: publicStdlibSettings), .target(name: "TestSupport", swiftSettings: [availabilityDefinition]), diff --git a/Sources/RegexBuilder/DSL.swift b/Sources/RegexBuilder/DSL.swift index 7e19caae2..42266466f 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: RegexComponent { +extension String: @retroactive RegexComponent { public typealias Output = Substring public var regex: Regex { .init(verbatim: self) } } @available(SwiftStdlib 5.7, *) -extension Substring: RegexComponent { +extension Substring: @retroactive RegexComponent { public typealias Output = Substring public var regex: Regex { String(self).regex } } @available(SwiftStdlib 5.7, *) -extension Character: RegexComponent { +extension Character: @retroactive RegexComponent { public typealias Output = Substring public var regex: Regex { @@ -55,7 +55,7 @@ extension Character: RegexComponent { } @available(SwiftStdlib 5.7, *) -extension UnicodeScalar: RegexComponent { +extension UnicodeScalar: @retroactive RegexComponent { public typealias Output = Substring public var regex: Regex {