Skip to content

Commit e9ccfdc

Browse files
authored
Merge pull request #103 from rxwei/resilience
Enable resilience for _MatchingEngine and _StringProcessing.
2 parents b188e9e + 0ebfed3 commit e9ccfdc

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

Package.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ let package = Package(
3131
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
3232
.target(
3333
name: "_MatchingEngine",
34-
dependencies: [/*"_Unicode"*/]),
34+
dependencies: [/*"_Unicode"*/],
35+
swiftSettings: [
36+
.unsafeFlags(["-enable-library-evolution"])
37+
]),
3538
.testTarget(
3639
name: "MatchingEngineTests",
3740
dependencies: ["_MatchingEngine"]),
3841
.target(
3942
name: "_StringProcessing",
40-
dependencies: ["_MatchingEngine"]),
43+
dependencies: ["_MatchingEngine"],
44+
swiftSettings: [
45+
.unsafeFlags(["-enable-library-evolution"])
46+
]),
4147
.target(
4248
name: "_Unicode",
4349
dependencies: []),

Sources/_MatchingEngine/Regex/AST/AST.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
/// A regex abstract syntax tree
13+
@frozen
1314
public indirect enum AST:
1415
Hashable/*, _ASTPrintable ASTValue, ASTAction*/
1516
{

Sources/_MatchingEngine/Regex/AST/Atom.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extension AST {
1919
self.location = loc
2020
}
2121

22+
@frozen
2223
public enum Kind: Hashable {
2324
/// Just a character
2425
///
@@ -79,6 +80,7 @@ extension AST.Atom {
7980

8081
// Characters, character types, literals, etc., derived from
8182
// an escape sequence.
83+
@frozen
8284
public enum EscapedBuiltin: Hashable {
8385
// TOOD: better doc comments
8486

@@ -331,6 +333,7 @@ extension AST.Atom {
331333
}
332334

333335
extension AST.Atom.CharacterProperty {
336+
@frozen
334337
public enum Kind: Hashable {
335338
/// Matches any character, equivalent to Oniguruma's '\O'.
336339
case any
@@ -369,6 +372,7 @@ extension AST.Atom.CharacterProperty {
369372
}
370373

371374
// TODO: erm, separate out or fold into something? splat it in?
375+
@frozen
372376
public enum PCRESpecialCategory: String, Hashable {
373377
case alphanumeric = "Xan"
374378
case posixSpace = "Xps"
@@ -382,6 +386,7 @@ extension AST.Atom.CharacterProperty {
382386
// TODO: I haven't thought through this a bunch; this seems like
383387
// a sensible type to have and break down this way. But it could
384388
// easily get folded in with the kind of reference
389+
@frozen
385390
public enum Reference: Hashable {
386391
// \n \gn \g{n} \g<n> \g'n' (?n) (?(n)...
387392
// Oniguruma: \k<n>, \k'n'
@@ -408,6 +413,7 @@ public enum Reference: Hashable {
408413

409414
extension AST.Atom {
410415
/// Anchors and other built-in zero-width assertions
416+
@frozen
411417
public enum AssertionKind: String {
412418
/// \A
413419
case startOfSubject = #"\A"#

Sources/_MatchingEngine/Regex/AST/CustomCharClass.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension AST {
2727
self.location = sr
2828
}
2929

30+
@frozen
3031
public enum Member: Hashable {
3132
/// A nested custom character class `[[ab][cd]]`
3233
case custom(CustomCharacterClass)
@@ -51,14 +52,15 @@ extension AST {
5152
self.rhs = rhs
5253
}
5354
}
55+
@frozen
5456
public enum SetOp: String, Hashable {
5557
case subtraction = "--"
5658
case intersection = "&&"
5759
case symmetricDifference = "~~"
5860
}
61+
@frozen
5962
public enum Start: String {
6063
case normal = "["
61-
6264
case inverted = "[^"
6365
}
6466
}

Sources/_MatchingEngine/Regex/AST/Quantification.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension AST {
2929
self.location = r
3030
}
3131

32+
@frozen
3233
public enum Amount: Hashable {
3334
case zeroOrMore // *
3435
case oneOrMore // +
@@ -39,6 +40,7 @@ extension AST {
3940
case range(Located<Int>, Located<Int>) // {n,m}
4041
}
4142

43+
@frozen
4244
public enum Kind: String, Hashable {
4345
case eager = ""
4446
case reluctant = "?"

Sources/_MatchingEngine/Utility/MissingUnicode.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extension Unicode {
1919
/// but is defined by https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt.
2020
/// We may want to split it out, as it's the only case that is a union of
2121
/// other script types.
22+
@frozen
2223
public enum Script: String, Hashable {
2324
case adlam = "Adlam"
2425
case ahom = "Ahom"
@@ -187,6 +188,7 @@ extension Unicode {
187188

188189
/// POSIX character properties not already covered by general categories or
189190
/// binary properties.
191+
@frozen
190192
public enum POSIXProperty: String, Hashable {
191193
case alnum = "alnum"
192194
case blank = "blank"
@@ -204,6 +206,7 @@ extension Unicode {
204206

205207
/// Unicode.GeneralCategory + cases for "meta categories" such as "L", which
206208
/// encompasses Lu | Ll | Lt | Lm | Lo.
209+
@frozen
207210
public enum ExtendedGeneralCategory: String, Hashable {
208211
case other = "C"
209212
case control = "Cc"
@@ -253,6 +256,7 @@ extension Unicode {
253256

254257
/// A list of unicode properties that can either be true or false.
255258
/// https://www.unicode.org/Public/UCD/latest/ucd/PropertyAliases.txt
259+
@frozen
256260
public enum BinaryProperty: String, Hashable {
257261
case asciiHexDigit = "ASCII_Hex_Digit"
258262
case alphabetic = "Alphabetic"
@@ -327,6 +331,7 @@ extension Unicode {
327331
/// Oniguruma properties that are not covered by Unicode spellings.
328332
/// TODO: These should become aliases for the Block (blk) Unicode character
329333
/// property.
334+
@frozen
330335
public enum OnigurumaSpecialProperty: String, Hashable {
331336
case inBasicLatin = "In_Basic_Latin"
332337
case inLatin1Supplement = "In_Latin_1_Supplement"

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ extension AST {
5050
return try a.generateConsumer(opts)
5151
case .customCharacterClass(let ccc):
5252
return try ccc.generateConsumer(opts)
53-
5453
case .alternation, .concatenation, .group,
5554
.quantification, .quote, .trivia, .empty,
5655
.groupTransform: return nil
@@ -524,9 +523,9 @@ extension Unicode.POSIXProperty {
524523

525524
case .xdigit:
526525
return consumeScalarProp(\.isHexDigit) // or number
526+
527527
}
528528
}
529-
530529
}
531530

532531
extension Unicode.ExtendedGeneralCategory {

Sources/_StringProcessing/Legacy/LegacyCompile.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ func compile(
263263
case .atom(let a) where a.characterClass != nil:
264264
fatalError("unreachable")
265265
}
266-
267266
}
268267

269268
try compileNode(ast)

0 commit comments

Comments
 (0)