Skip to content

Commit 9e07efb

Browse files
committed
Add @_effects(readnone) to string-based Regex inits
It doesn't seem like regex instantiation is being hoisted out of loops, which means that both the parsing (which happens at runtime) and compilation (which happens on first use) are being lost for string-based and possibly literal regexes. This may address the issue.
1 parent 650b2c1 commit 9e07efb

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Sources/_StringProcessing/Regex/AnyRegexOutput.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ extension Regex where Output == AnyRegexOutput {
178178
/// ``init(_:as:)`` initializer instead.
179179
///
180180
/// - Parameter pattern: A string with regular expression syntax.
181+
@_effects(readnone)
181182
public init(_ pattern: String) throws {
182183
self.init(ast: try parse(pattern, .traditional))
183184
}
184185

186+
@_effects(readnone)
185187
internal init(_ pattern: String, syntax: SyntaxOptions) throws {
186188
self.init(ast: try parse(pattern, syntax))
187189
}
@@ -212,6 +214,7 @@ extension Regex {
212214
/// - Parameters:
213215
/// - pattern: A string with regular expression syntax.
214216
/// - outputType: The desired type for the output captures.
217+
@_effects(readnone)
215218
public init(
216219
_ pattern: String,
217220
as outputType: Output.Type = Output.self

Sources/_StringProcessing/Regex/Core.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public struct Regex<Output>: RegexComponent {
103103
}
104104

105105
// Compiler interface. Do not change independently.
106+
@_effects(readnone)
106107
@usableFromInline
107108
init(_regexString pattern: String) {
108109
self.init(ast: try! parse(pattern, .traditional))

0 commit comments

Comments
 (0)