Skip to content

Commit aeea84d

Browse files
authored
Merge pull request #28728 from lorentey/assert-vs-internalInvariant
[stdlib] Don’t use assert() in the stdlib
2 parents 7e2c245 + d83a425 commit aeea84d

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

stdlib/public/core/Diffing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fileprivate func _myers<C,D>(
319319
y &-= 1
320320
}
321321

322-
assert((x == prev_x && y > prev_y) || (y == prev_y && x > prev_x))
322+
_internalInvariant((x == prev_x && y > prev_y) || (y == prev_y && x > prev_x))
323323
if y != prev_y {
324324
changes.append(.insert(offset: prev_y, element: b[prev_y], associatedWith: nil))
325325
} else {

stdlib/public/core/KeyPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ internal struct InstantiateKeyPathBuffer: KeyPathPatternVisitor {
31513151
case .unresolvedIndirectOffset(let pointerToOffset):
31523152
// Look up offset in the indirectly-referenced variable we have a
31533153
// pointer.
3154-
assert(pointerToOffset.pointee <= UInt32.max)
3154+
_internalInvariant(pointerToOffset.pointee <= UInt32.max)
31553155
let offset = UInt32(truncatingIfNeeded: pointerToOffset.pointee)
31563156
let header = RawKeyPathComponent.Header(storedWithOutOfLineOffset: kind,
31573157
mutable: mutable)

stdlib/public/core/Sort.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ extension UnsafeMutableBufferPointer {
692692

693693
result = try result && _finalizeRuns(
694694
&runs, buffer: buffer.baseAddress!, by: areInIncreasingOrder)
695-
assert(runs.count == 1, "Didn't complete final merge")
695+
_internalInvariant(runs.count == 1, "Didn't complete final merge")
696696
}
697697

698698
// FIXME: Remove this, it works around rdar://problem/45044610

stdlib/public/core/StringNormalization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extension UnsafeBufferPointer where Element == UInt8 {
108108
if index == 0 || index == count {
109109
return true
110110
}
111-
assert(!UTF8.isContinuation(self[_unchecked: index]))
111+
_internalInvariant(!UTF8.isContinuation(self[_unchecked: index]))
112112

113113
// Sub-300 latiny fast-path
114114
if self[_unchecked: index] < 0xCC { return true }

stdlib/public/core/StringSwitch.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ internal func _createStringTableCache(_ cacheRawPtr: Builtin.RawPointer) {
9292
let context = UnsafePointer<_StringSwitchContext>(cacheRawPtr).pointee
9393
var cache = _StringSwitchCache()
9494
cache.reserveCapacity(context.cases.count)
95-
assert(MemoryLayout<_StringSwitchCache>.size <= MemoryLayout<Builtin.Word>.size)
95+
_internalInvariant(
96+
MemoryLayout<_StringSwitchCache>.size <= MemoryLayout<Builtin.Word>.size)
9697

9798
for (idx, s) in context.cases.enumerated() {
9899
let key = String(_builtinStringLiteral: s.utf8Start._rawValue,

0 commit comments

Comments
 (0)