Skip to content

Commit 3c83989

Browse files
committed
Enable resilience for _MatchingEngine and _StringProcessing.
_MatchingEngine and _StringProcessing are built with resilience enabled in Swift core libs. Currently the compiler build produces lots of warnings of missing `@unknown default`. We enable resilience in this package so that we can catch these issues early.
1 parent e6ec173 commit 3c83989

File tree

8 files changed

+33
-5
lines changed

8 files changed

+33
-5
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
@@ -1,4 +1,5 @@
11
/// A regex abstract syntax tree
2+
@frozen
23
public indirect enum AST:
34
Hashable/*, _ASTPrintable ASTValue, ASTAction*/
45
{

Sources/_MatchingEngine/Regex/AST/Atom.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extension AST {
88
self.location = loc
99
}
1010

11+
@frozen
1112
public enum Kind: Hashable {
1213
/// Just a character
1314
///
@@ -68,6 +69,7 @@ extension AST.Atom {
6869

6970
// Characters, character types, literals, etc., derived from
7071
// an escape sequence.
72+
@frozen
7173
public enum EscapedBuiltin: Hashable {
7274
// TOOD: better doc comments
7375

@@ -320,6 +322,7 @@ extension AST.Atom {
320322
}
321323

322324
extension AST.Atom.CharacterProperty {
325+
@frozen
323326
public enum Kind: Hashable {
324327
/// Matches any character, equivalent to Oniguruma's '\O'.
325328
case any
@@ -358,6 +361,7 @@ extension AST.Atom.CharacterProperty {
358361
}
359362

360363
// TODO: erm, separate out or fold into something? splat it in?
364+
@frozen
361365
public enum PCRESpecialCategory: String, Hashable {
362366
case alphanumeric = "Xan"
363367
case posixSpace = "Xps"
@@ -371,6 +375,7 @@ extension AST.Atom.CharacterProperty {
371375
// TODO: I haven't thought through this a bunch; this seems like
372376
// a sensible type to have and break down this way. But it could
373377
// easily get folded in with the kind of reference
378+
@frozen
374379
public enum Reference: Hashable {
375380
// \n \gn \g{n} \g<n> \g'n' (?n) (?(n)...
376381
// Oniguruma: \k<n>, \k'n'
@@ -397,6 +402,7 @@ public enum Reference: Hashable {
397402

398403
extension AST.Atom {
399404
/// Anchors and other built-in zero-width assertions
405+
@frozen
400406
public enum AssertionKind: String {
401407
/// \A
402408
case startOfSubject = #"\A"#

Sources/_MatchingEngine/Utility/MissingUnicode.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extension Unicode {
88
/// but is defined by https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt.
99
/// We may want to split it out, as it's the only case that is a union of
1010
/// other script types.
11+
@frozen
1112
public enum Script: String, Hashable {
1213
case adlam = "Adlam"
1314
case ahom = "Ahom"
@@ -176,6 +177,7 @@ extension Unicode {
176177

177178
/// POSIX character properties not already covered by general categories or
178179
/// binary properties.
180+
@frozen
179181
public enum POSIXProperty: String, Hashable {
180182
case alnum = "alnum"
181183
case blank = "blank"
@@ -193,6 +195,7 @@ extension Unicode {
193195

194196
/// Unicode.GeneralCategory + cases for "meta categories" such as "L", which
195197
/// encompasses Lu | Ll | Lt | Lm | Lo.
198+
@frozen
196199
public enum ExtendedGeneralCategory: String, Hashable {
197200
case other = "C"
198201
case control = "Cc"
@@ -242,6 +245,7 @@ extension Unicode {
242245

243246
/// A list of unicode properties that can either be true or false.
244247
/// https://www.unicode.org/Public/UCD/latest/ucd/PropertyAliases.txt
248+
@frozen
245249
public enum BinaryProperty: String, Hashable {
246250
case asciiHexDigit = "ASCII_Hex_Digit"
247251
case alphabetic = "Alphabetic"
@@ -316,6 +320,7 @@ extension Unicode {
316320
/// Oniguruma properties that are not covered by Unicode spellings.
317321
/// TODO: These should become aliases for the Block (blk) Unicode character
318322
/// property.
323+
@frozen
319324
public enum OnigurumaSpecialProperty: String, Hashable {
320325
case inBasicLatin = "In_Basic_Latin"
321326
case inLatin1Supplement = "In_Latin_1_Supplement"

Sources/_StringProcessing/CharacterClass.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public struct CharacterClass: Hashable {
5656
return lhs.matches(c) && !rhs.matches(c)
5757
case .symmetricDifference:
5858
return lhs.matches(c) != rhs.matches(c)
59+
@unknown default:
60+
fatalError("unhandled")
5961
}
6062
}
6163
}
@@ -410,6 +412,8 @@ extension AST.CustomCharacterClass {
410412
lhs: .characterClass(.custom(lhs)),
411413
op: op.value,
412414
rhs: .characterClass(.custom(rhs)))))
415+
@unknown default:
416+
fatalError("unhandled")
413417
}
414418
}
415419
return result

Sources/_StringProcessing/Compiler.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ class Compiler {
408408
// quantification break if trying to restore to a prior
409409
// iteration because the register got overwritten?
410410
//
411+
@unknown default:
412+
fatalError("unhandled")
411413
}
412414

413415
builder.label(exit)

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extension AST {
3939
return try a.generateConsumer(opts)
4040
case .customCharacterClass(let ccc):
4141
return try ccc.generateConsumer(opts)
42-
4342
case .alternation, .concatenation, .group,
4443
.quantification, .quote, .trivia, .empty,
4544
.groupTransform: return nil
@@ -180,8 +179,14 @@ extension AST.CustomCharacterClass.Member {
180179
return rhsIdxOpt == nil ? idx : nil
181180
}
182181
return rhsIdxOpt
182+
183+
@unknown default:
184+
fatalError("unhandled")
183185
}
184186
}
187+
188+
@unknown default:
189+
fatalError("unhandled")
185190
}
186191
}
187192
}
@@ -513,9 +518,9 @@ extension Unicode.POSIXProperty {
513518

514519
case .xdigit:
515520
return consumeScalarProp(\.isHexDigit) // or number
521+
516522
}
517523
}
518-
519524
}
520525

521526
extension Unicode.ExtendedGeneralCategory {

Sources/_StringProcessing/Legacy/LegacyCompile.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ func compile(
252252
case .atom(let a) where a.characterClass != nil:
253253
fatalError("unreachable")
254254
}
255-
256255
}
257256

258257
try compileNode(ast)

0 commit comments

Comments
 (0)