Skip to content

Commit e8b4c11

Browse files
committed
Resolve switch covers known cases, but 'Enum' may have additional unknown values warnings.
When building with CMake during the Swift compiler build, the libraries in this package are built with library evolution enabled. That causes the compiler to emit diagnostics that encourage use of `@unknown default` to handle unknown cases that might be added in the future. Silence these warnings by adding `@unknown default` cases where they are missing. Guard these with the `RESILIENT_LIBRARIES` compilation condition to avoid triggering a `Default will never be executed` diagnostic during the package build. Note that this would not be required if `_RegexParser` could always build without library evolution, but that change had to be reverted (rdar://124541877).
1 parent a765595 commit e8b4c11

File tree

8 files changed

+99
-0
lines changed

8 files changed

+99
-0
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ fileprivate extension Compiler.ByteCodeGen {
156156
name, isScalarMode: options.semanticLevel == .unicodeScalar)
157157
case .relative:
158158
throw Unsupported("Backreference kind: \(ref)")
159+
#if RESILIENT_LIBRARIES
160+
@unknown default:
161+
fatalError()
162+
#endif
159163
}
160164
}
161165

@@ -657,6 +661,10 @@ fileprivate extension Compiler.ByteCodeGen {
657661
// quantification break if trying to restore to a prior
658662
// iteration because the register got overwritten?
659663
//
664+
#if RESILIENT_LIBRARIES
665+
@unknown default:
666+
fatalError()
667+
#endif
660668
}
661669

662670
builder.label(exit)

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ extension AST.Atom {
324324
.backtrackingDirective, .changeMatchingOptions, .invalid:
325325
// FIXME: implement
326326
return nil
327+
328+
#if RESILIENT_LIBRARIES
329+
@unknown default:
330+
fatalError()
331+
#endif
327332
}
328333
}
329334
}
@@ -686,7 +691,13 @@ extension AST.Atom.CharacterProperty {
686691

687692
case .invalid:
688693
throw Unreachable("Expected valid property")
694+
695+
#if RESILIENT_LIBRARIES
696+
@unknown default:
697+
throw Unreachable("Unknown kind \(kind)")
698+
#endif
689699
}
700+
690701
}()
691702

692703
if !isInverted { return preInversion }
@@ -856,6 +867,10 @@ extension Unicode.BinaryProperty {
856867
case .expandsOnNFC, .expandsOnNFD, .expandsOnNFKD,
857868
.expandsOnNFKC:
858869
throw Unsupported("Unicode-deprecated: \(self)")
870+
#if RESILIENT_LIBRARIES
871+
@unknown default:
872+
break
873+
#endif
859874
}
860875

861876
throw Unsupported("TODO: map prop \(self)")
@@ -906,6 +921,10 @@ extension Unicode.POSIXProperty {
906921
case .xdigit:
907922
return consume(propertyScalarPredicate(\.isHexDigit)) // or number
908923

924+
#if RESILIENT_LIBRARIES
925+
@unknown default:
926+
fatalError()
927+
#endif
909928
}
910929
}
911930
}
@@ -1024,6 +1043,11 @@ extension Unicode.ExtendedGeneralCategory {
10241043
return consume(categoryScalarPredicate(.paragraphSeparator))
10251044
case .spaceSeparator:
10261045
return consume(categoryScalarPredicate(.spaceSeparator))
1046+
1047+
#if RESILIENT_LIBRARIES
1048+
@unknown default:
1049+
fatalError()
1050+
#endif
10271051
}
10281052
}
10291053
}

Sources/_StringProcessing/Engine/InstPayload.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ struct QuantifyPayload: RawRepresentable {
423423
kindVal = 1
424424
case .possessive:
425425
kindVal = 2
426+
#if RESILIENT_LIBRARIES
427+
@unknown default:
428+
fatalError()
429+
#endif
426430
}
427431
// TODO: refactor / reimplement
428432
let maxExtraTripsVal: UInt64 = maxExtraTrips == nil ? 1 : UInt64(maxExtraTrips!) << 1

Sources/_StringProcessing/LiteralPrinter.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ extension LiteralPrinter {
216216
output("{,\(n.value!)}")
217217
case let .range(low, high):
218218
output("{\(low.value!),\(high.value!)}")
219+
#if RESILIENT_LIBRARIES
220+
@unknown default:
221+
fatalError()
222+
#endif
219223
}
220224

221225
outputQuantificationKind(kind)
@@ -235,6 +239,10 @@ extension LiteralPrinter {
235239
output(options.isReluctantByDefault ? "" : "?")
236240
case .possessive:
237241
output("+")
242+
#if RESILIENT_LIBRARIES
243+
@unknown default:
244+
fatalError()
245+
#endif
238246
}
239247
case let .syntax(kind):
240248
// Syntactically-specified quantification modifiers can stay as-is.
@@ -245,6 +253,10 @@ extension LiteralPrinter {
245253
output("?")
246254
case .possessive:
247255
output("+")
256+
#if RESILIENT_LIBRARIES
257+
@unknown default:
258+
fatalError()
259+
#endif
248260
}
249261
}
250262
}
@@ -351,6 +363,10 @@ extension LiteralPrinter {
351363
output("\\g{\(prefix)\(abs(value))}")
352364
case .named(let name):
353365
output("\\g{\(name)}")
366+
#if RESILIENT_LIBRARIES
367+
@unknown default:
368+
fatalError()
369+
#endif
354370
}
355371
}
356372

@@ -558,6 +574,11 @@ extension AST.MatchingOption.Kind {
558574

559575
// NSRE Compatibility option; no literal representation
560576
case .nsreCompatibleDot: return nil
577+
578+
#if RESILIENT_LIBRARIES
579+
@unknown default:
580+
fatalError()
581+
#endif
561582
}
562583
}
563584
}
@@ -597,6 +618,11 @@ extension DSLTree._AST.GroupKind {
597618

598619
case let .changeMatchingOptions(sequence):
599620
return sequence._patternString + ":"
621+
622+
#if RESILIENT_LIBRARIES
623+
@unknown default:
624+
fatalError()
625+
#endif
600626
}
601627
}
602628
}

Sources/_StringProcessing/MatchingOptions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ extension MatchingOptions {
217217
self = .extended
218218
case .extraExtended:
219219
self = .extraExtended
220+
#if RESILIENT_LIBRARIES
221+
@unknown default:
222+
fatalError()
223+
#endif
220224
}
221225
}
222226

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@ extension AST.Atom {
11051105

11061106
case .changeMatchingOptions:
11071107
return "/* TODO: change matching options */"
1108+
1109+
#if RESILIENT_LIBRARIES
1110+
@unknown default:
1111+
fatalError()
1112+
#endif
11081113
}
11091114
}
11101115
}
@@ -1125,6 +1130,9 @@ extension AST.Quantification.Amount {
11251130
case let .nOrMore(n): return "Repeat(\(n._patternBase)...)"
11261131
case let .upToN(n): return "Repeat(...\(n._patternBase))"
11271132
case let .range(n, m): return "Repeat(\(n._patternBase)...\(m._patternBase))"
1133+
#if RESILIENT_LIBRARIES
1134+
@unknown default: fatalError()
1135+
#endif
11281136
}
11291137
}
11301138

@@ -1144,6 +1152,9 @@ extension AST.Quantification.Kind {
11441152
case .eager: return ".eager"
11451153
case .reluctant: return ".reluctant"
11461154
case .possessive: return ".possessive"
1155+
#if RESILIENT_LIBRARIES
1156+
@unknown default: fatalError()
1157+
#endif
11471158
}
11481159
}
11491160
}

Sources/_StringProcessing/Regex/ASTConversion.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ extension AST.Node {
9797
case let .absentFunction(abs):
9898
// TODO: What should this map to?
9999
return .absentFunction(.init(ast: abs))
100+
101+
#if RESILIENT_LIBRARIES
102+
@unknown default:
103+
fatalError()
104+
#endif
100105
}
101106
}
102107

@@ -141,9 +146,18 @@ extension AST.CustomCharacterClass {
141146
return .intersection(lhs, rhs)
142147
case .symmetricDifference:
143148
return .symmetricDifference(lhs, rhs)
149+
#if RESILIENT_LIBRARIES
150+
@unknown default:
151+
fatalError()
152+
#endif
144153
}
145154
case let .trivia(t):
146155
return .trivia(t.contents)
156+
157+
#if RESILIENT_LIBRARIES
158+
@unknown default:
159+
fatalError()
160+
#endif
147161
}
148162
}
149163

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ extension CaptureList.Builder {
651651
addCaptures(of: child, optionalNesting: nesting, visibleInTypedOutput: visibleInTypedOutput)
652652
case .clearer, .repeater, .stopper:
653653
break
654+
#if RESILIENT_LIBRARIES
655+
@unknown default:
656+
fatalError()
657+
#endif
654658
}
655659

656660
case let .convertedRegexLiteral(n, _):
@@ -926,6 +930,10 @@ extension DSLTree {
926930
return true
927931
case .exactly(let num), .nOrMore(let num), .range(let num, _):
928932
return num.value.map { $0 > 0 } ?? false
933+
#if RESILIENT_LIBRARIES
934+
@unknown default:
935+
fatalError()
936+
#endif
929937
}
930938
}
931939
}

0 commit comments

Comments
 (0)