Skip to content

Commit dea7251

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 dea7251

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
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/_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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class Compiler {
113113

114114
case .customCharacterClass, .atom:
115115
throw unsupported(node._dumpBase)
116+
117+
@unknown default:
118+
fatalError("unhandled")
116119
}
117120
}
118121

@@ -185,6 +188,9 @@ class Compiler {
185188
!CharacterClass.word.isBoundary(
186189
input, at: pos, bounds: bounds)
187190
}
191+
192+
@unknown default:
193+
fatalError("unhandled")
188194
}
189195
}
190196

@@ -408,6 +414,8 @@ class Compiler {
408414
// quantification break if trying to restore to a prior
409415
// iteration because the register got overwritten?
410416
//
417+
@unknown default:
418+
fatalError("unhandled")
411419
}
412420

413421
builder.label(exit)

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ 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
45+
@unknown default:
46+
fatalError("unhandled")
4647
}
4748
}
4849
}
@@ -105,6 +106,9 @@ extension AST.Atom {
105106
.backreference, .subpattern, .condition:
106107
// FIXME: implement
107108
return nil
109+
110+
@unknown default:
111+
fatalError("unhandled")
108112
}
109113
}
110114
}
@@ -180,8 +184,14 @@ extension AST.CustomCharacterClass.Member {
180184
return rhsIdxOpt == nil ? idx : nil
181185
}
182186
return rhsIdxOpt
187+
188+
@unknown default:
189+
fatalError("unhandled")
183190
}
184191
}
192+
193+
@unknown default:
194+
fatalError("unhandled")
185195
}
186196
}
187197
}
@@ -300,6 +310,9 @@ extension AST.Atom.CharacterProperty {
300310

301311
case let .other(key, value):
302312
throw unsupported("TODO: map other \(key ?? "")=\(value)")
313+
314+
@unknown default:
315+
fatalError("unhandled")
303316
}
304317
}()
305318

@@ -466,6 +479,8 @@ extension Unicode.BinaryProperty {
466479
case .expandsOnNFC, .expandsOnNFD, .expandsOnNFKD,
467480
.expandsOnNFKC:
468481
throw unsupported("Unicode-deprecated: \(self)")
482+
@unknown default:
483+
fatalError("unhandled")
469484
}
470485

471486
throw unsupported("TODO: map prop \(self)")
@@ -513,6 +528,9 @@ extension Unicode.POSIXProperty {
513528

514529
case .xdigit:
515530
return consumeScalarProp(\.isHexDigit) // or number
531+
532+
@unknown default:
533+
fatalError("unhandled")
516534
}
517535
}
518536

@@ -628,6 +646,8 @@ extension Unicode.ExtendedGeneralCategory {
628646
return consumeScalarGC(.paragraphSeparator)
629647
case .spaceSeparator:
630648
return consumeScalarGC(.spaceSeparator)
649+
@unknown default:
650+
fatalError("unhandled")
631651
}
632652
}
633653
}

Sources/_StringProcessing/Legacy/LegacyCompile.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ func compile(
251251

252252
case .atom(let a) where a.characterClass != nil:
253253
fatalError("unreachable")
254-
}
255254

255+
@unknown default:
256+
fatalError("unhandled")
257+
}
256258
}
257259

258260
try compileNode(ast)

0 commit comments

Comments
 (0)