Skip to content

[5.2][stdlib] Don’t use assert() in the stdlib #28730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/core/Diffing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ fileprivate func _myers<C,D>(
y &-= 1
}

assert((x == prev_x && y > prev_y) || (y == prev_y && x > prev_x))
_internalInvariant((x == prev_x && y > prev_y) || (y == prev_y && x > prev_x))
if y != prev_y {
changes.append(.insert(offset: prev_y, element: b[prev_y], associatedWith: nil))
} else {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/KeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,7 @@ internal struct InstantiateKeyPathBuffer: KeyPathPatternVisitor {
case .unresolvedIndirectOffset(let pointerToOffset):
// Look up offset in the indirectly-referenced variable we have a
// pointer.
assert(pointerToOffset.pointee <= UInt32.max)
_internalInvariant(pointerToOffset.pointee <= UInt32.max)
let offset = UInt32(truncatingIfNeeded: pointerToOffset.pointee)
let header = RawKeyPathComponent.Header(storedWithOutOfLineOffset: kind,
mutable: mutable)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Sort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ extension UnsafeMutableBufferPointer {

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

// FIXME: Remove this, it works around rdar://problem/45044610
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/StringNormalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extension UnsafeBufferPointer where Element == UInt8 {
if index == 0 || index == count {
return true
}
assert(!UTF8.isContinuation(self[_unchecked: index]))
_internalInvariant(!UTF8.isContinuation(self[_unchecked: index]))

// Sub-300 latiny fast-path
if self[_unchecked: index] < 0xCC { return true }
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/StringSwitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ internal func _createStringTableCache(_ cacheRawPtr: Builtin.RawPointer) {
let context = UnsafePointer<_StringSwitchContext>(cacheRawPtr).pointee
var cache = _StringSwitchCache()
cache.reserveCapacity(context.cases.count)
assert(MemoryLayout<_StringSwitchCache>.size <= MemoryLayout<Builtin.Word>.size)
_internalInvariant(
MemoryLayout<_StringSwitchCache>.size <= MemoryLayout<Builtin.Word>.size)

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