Skip to content

Commit 47f5e90

Browse files
committed
Make _sanityCheck internal
1 parent 46a8390 commit 47f5e90

File tree

12 files changed

+57
-58
lines changed

12 files changed

+57
-58
lines changed

stdlib/public/SDK/Foundation/NSArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Array : _ObjectiveCBridgeable {
3131
/// The provided `NSArray` will be copied to ensure that the copy can
3232
/// not be mutated by other code.
3333
internal init(_cocoaArray: NSArray) {
34-
_sanityCheck(_isBridgedVerbatimToObjectiveC(Element.self),
34+
precondition(_isBridgedVerbatimToObjectiveC(Element.self),
3535
"Array can be backed by NSArray only when the element type can be bridged verbatim to Objective-C")
3636
// FIXME: We would like to call CFArrayCreateCopy() to avoid doing an
3737
// objc_msgSend() for instances of CoreFoundation types. We can't do that

stdlib/public/SDK/Foundation/NSDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension Dictionary {
3535
/// The provided `NSDictionary` will be copied to ensure that the copy can
3636
/// not be mutated by other code.
3737
public init(_cocoaDictionary: _NSDictionary) {
38-
_sanityCheck(
38+
precondition(
3939
_isBridgedVerbatimToObjectiveC(Key.self) &&
4040
_isBridgedVerbatimToObjectiveC(Value.self),
4141
"Dictionary can be backed by NSDictionary storage only when both key and value are bridged verbatim to Objective-C")
@@ -228,8 +228,8 @@ extension NSDictionary {
228228
let alignment = MemoryLayout<AnyObject>.alignment
229229
let singleSize = stride * numElems
230230
let totalSize = singleSize * 2
231-
_sanityCheck(stride == MemoryLayout<NSCopying>.stride)
232-
_sanityCheck(alignment == MemoryLayout<NSCopying>.alignment)
231+
precondition(stride == MemoryLayout<NSCopying>.stride)
232+
precondition(alignment == MemoryLayout<NSCopying>.alignment)
233233

234234
// Allocate a buffer containing both the keys and values.
235235
let buffer = UnsafeMutableRawPointer.allocate(

stdlib/public/SDK/Foundation/NSSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension Set {
1818
/// The provided `NSSet` will be copied to ensure that the copy can
1919
/// not be mutated by other code.
2020
public init(_cocoaSet: _NSSet) {
21-
_sanityCheck(_isBridgedVerbatimToObjectiveC(Element.self),
21+
precondition(_isBridgedVerbatimToObjectiveC(Element.self),
2222
"Set can be backed by NSSet _variantStorage only when the member type can be bridged verbatim to Objective-C")
2323
// FIXME: We would like to call CFSetCreateCopy() to avoid doing an
2424
// objc_msgSend() for instances of CoreFoundation types. We can't do that

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ extension StringProtocol where Index == String.Index {
16371637
public func contains<T : StringProtocol>(_ other: T) -> Bool {
16381638
let r = self.range(of: other) != nil
16391639
if #available(macOS 10.10, iOS 8.0, *) {
1640-
_sanityCheck(r == _ns.contains(other._ephemeralString))
1640+
precondition(r == _ns.contains(other._ephemeralString))
16411641
}
16421642
return r
16431643
}
@@ -1660,7 +1660,7 @@ extension StringProtocol where Index == String.Index {
16601660
of: other, options: .caseInsensitive, locale: Locale.current
16611661
) != nil
16621662
if #available(macOS 10.10, iOS 8.0, *) {
1663-
_sanityCheck(r ==
1663+
precondition(r ==
16641664
_ns.localizedCaseInsensitiveContains(other._ephemeralString))
16651665
}
16661666
return r

stdlib/public/SDK/SpriteKit/SpriteKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public typealias SKColor = UIColor
2525
// since that method only exists in a private header in SpriteKit, the lookup
2626
// mechanism by default fails to accept it as a valid AnyObject call
2727
@objc class _SpriteKitMethodProvider : NSObject {
28-
override init() { _sanityCheckFailure("don't touch me") }
28+
override init() { preconditionFailure("don't touch me") }
2929
@objc func _copyImageData() -> NSData! { return nil }
3030
}
3131

stdlib/public/core/Assert.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ public func _debugPreconditionFailure(
284284
/// standard library. They are only enable when the standard library is built
285285
/// with the build configuration INTERNAL_CHECKS_ENABLED enabled. Otherwise, the
286286
/// call to this function is a noop.
287-
@_transparent
288-
public func _sanityCheck(
287+
@usableFromInline @_transparent
288+
internal func _sanityCheck(
289289
_ condition: @autoclosure () -> Bool, _ message: StaticString = StaticString(),
290290
file: StaticString = #file, line: UInt = #line
291291
) {
@@ -297,8 +297,8 @@ public func _sanityCheck(
297297
#endif
298298
}
299299

300-
@_transparent
301-
public func _sanityCheckFailure(
300+
@usableFromInline @_transparent
301+
internal func _sanityCheckFailure(
302302
_ message: StaticString = StaticString(),
303303
file: StaticString = #file, line: UInt = #line
304304
) -> Never {

test/Prototypes/Algorithms.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ extension MutableCollection {
7373
internal mutating func _swapNonemptySubrangePrefixes(
7474
_ lhs: Range<Index>, _ rhs: Range<Index>
7575
) -> (Index, Index) {
76-
_sanityCheck(!lhs.isEmpty)
77-
_sanityCheck(!rhs.isEmpty)
76+
assert(!lhs.isEmpty)
77+
assert(!rhs.isEmpty)
7878

7979
var p = lhs.lowerBound
8080
var q = rhs.lowerBound
@@ -352,7 +352,7 @@ public struct Concatenation<C1 : Collection, C2: Collection>: Collection
352352
public func index(after i: Index) -> Index {
353353
switch i._position {
354354
case let .first(i):
355-
_sanityCheck(i != _base1.endIndex)
355+
assert(i != _base1.endIndex)
356356
let next = _base1.index(after: i)
357357
return next == _base1.endIndex
358358
? Index(second: _base2.startIndex)

test/Prototypes/BigInt.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
120120

121121
// FIXME: This is broken on 32-bit arch w/ Word = UInt64
122122
let wordRatio = UInt.bitWidth / Word.bitWidth
123-
_sanityCheck(wordRatio != 0)
123+
assert(wordRatio != 0)
124124
for var sourceWord in source.words {
125125
for _ in 0..<wordRatio {
126126
_data.append(Word(truncatingIfNeeded: sourceWord))
@@ -260,7 +260,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
260260
if carry == 0 { break }
261261
(carry, _data[i]) = _data[i].subtractingWithBorrow(carry)
262262
}
263-
_sanityCheck(carry == 0)
263+
assert(carry == 0)
264264

265265
_standardize()
266266
}
@@ -425,7 +425,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
425425
if carry == 0 { break }
426426
(carry, _data[i]) = _data[i].subtractingWithBorrow(carry)
427427
}
428-
_sanityCheck(carry == 0)
428+
assert(carry == 0)
429429

430430
_standardize()
431431
}
@@ -476,7 +476,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
476476
let (a, b) = lhs._data.count > rhs._data.count
477477
? (lhs._data, rhs._data)
478478
: (rhs._data, lhs._data)
479-
_sanityCheck(a.count >= b.count)
479+
assert(a.count >= b.count)
480480

481481
var carry: Word = 0
482482
for ai in 0..<a.count {
@@ -513,12 +513,12 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
513513
// 0b11111111 + (0b11111101_____00000010) + 0b11111111
514514
// (0b11111110_____00000001) + 0b11111111
515515
// (0b11111111_____00000000)
516-
_sanityCheck(!product.high.addingReportingOverflow(carry).overflow)
516+
assert(!product.high.addingReportingOverflow(carry).overflow)
517517
carry = product.high &+ carry
518518
}
519519

520520
// Leftover `carry` is inserted in new highest word.
521-
_sanityCheck(newData[ai + b.count] == 0)
521+
assert(newData[ai + b.count] == 0)
522522
newData[ai + b.count] = carry
523523
}
524524

@@ -659,7 +659,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
659659
}
660660

661661
public var words: [UInt] {
662-
_sanityCheck(UInt.bitWidth % Word.bitWidth == 0)
662+
assert(UInt.bitWidth % Word.bitWidth == 0)
663663
let twosComplementData = _dataAsTwosComplement()
664664
var words: [UInt] = []
665665
words.reserveCapacity((twosComplementData.count * Word.bitWidth
@@ -713,7 +713,7 @@ public struct _BigInt<Word: FixedWidthInteger & UnsignedInteger> :
713713
}
714714

715715
let i = _data.firstIndex(where: { $0 != 0 })!
716-
_sanityCheck(_data[i] != 0)
716+
assert(_data[i] != 0)
717717
return i * Word.bitWidth + _data[i].trailingZeroBitCount
718718
}
719719

test/Prototypes/DoubleWidth.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension DoubleWidth {
235235
}
236236
self._high = value._storage.high.words
237237
self._low = value._storage.low.words
238-
_sanityCheck(!_low.isEmpty)
238+
assert(!_low.isEmpty)
239239
}
240240
}
241241
}
@@ -299,7 +299,7 @@ extension DoubleWidth.Words: Collection {
299299
public subscript(_ i: Index) -> UInt {
300300
if Base.bitWidth < UInt.bitWidth {
301301
_precondition(i == Index(.low(_low.startIndex)), "Invalid index")
302-
_sanityCheck(2 * Base.bitWidth <= UInt.bitWidth)
302+
assert(2 * Base.bitWidth <= UInt.bitWidth)
303303
return _low.first! | (_high.first! &<< Base.bitWidth._lowWord)
304304
}
305305
switch i._value {
@@ -633,9 +633,9 @@ extension DoubleWidth : UnsignedInteger where Base : UnsignedInteger {
633633
) -> (quotient: Low, remainder: Magnitude) {
634634
// The following invariants are guaranteed to hold by dividingFullWidth or
635635
// quotientAndRemainder before this method is invoked:
636-
_sanityCheck(lhs.high != (0 as Low))
637-
_sanityCheck(rhs.leadingZeroBitCount == 0)
638-
_sanityCheck(Magnitude(lhs.high, lhs.mid) < rhs)
636+
assert(lhs.high != (0 as Low))
637+
assert(rhs.leadingZeroBitCount == 0)
638+
assert(Magnitude(lhs.high, lhs.mid) < rhs)
639639

640640
// Estimate the quotient.
641641
var quotient = lhs.high == rhs.high

test/SILOptimizer/access_marker_verify.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ extension UsesSelf {
960960
// --- autoclosure
961961
struct StructWithLayout {
962962
internal init() {
963-
_sanityCheck(MemoryLayout.size(ofValue: self) >= 0)
963+
assert(MemoryLayout.size(ofValue: self) >= 0)
964964
}
965965
}
966966
// CHECK-LABEL: sil hidden @$S20access_marker_verify16StructWithLayoutVACycfC : $@convention(method) (@thin StructWithLayout.Type) -> StructWithLayout {
@@ -975,7 +975,6 @@ struct StructWithLayout {
975975
// call UInt.init(_builtinIntegerLiteral:)
976976
// CHECK: apply
977977
// call default argument
978-
// CHECK: apply %{{.*}}() : $@convention(thin) () -> StaticString
979978
// call _sanityCheck(_:_:file:line:)
980979
// CHECK: apply %{{.*}}([[CLOSURE]], {{.*}})
981980
// CHECK: load [trivial] [[PROJ]] : $*StructWithLayout

validation-test/compiler_crashers_2_fixed/0109-sr4737.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ extension _UTFEncoding {
528528
}
529529
// Buffering mode.
530530
// Fill buffer back to 4 bytes (or as many as are left in the iterator).
531-
_sanityCheck(buffer._bitCount < BufferStorage.bitWidth)
531+
assert(buffer._bitCount < BufferStorage.bitWidth)
532532
repeat {
533533
if let codeUnit = input.next() {
534534
buffer.append(codeUnit)
@@ -588,7 +588,7 @@ extension Unicode.UTF8 : UnicodeEncoding {
588588
value |= (bits & 0b0________________________________0000_1111) &<< 12
589589
return UnicodeScalar(_unchecked: value)
590590
default:
591-
_sanityCheck(source.count == 4)
591+
assert(source.count == 4)
592592
var value = (bits & 0b0_11_1111__0000_0000__0000_0000__0000_0000) &>> 24
593593
value |= (bits & 0b0____________11_1111__0000_0000__0000_0000) &>> 10
594594
value |= (bits & 0b0_______________________11_1111__0000_0000) &<< 4
@@ -634,7 +634,7 @@ extension Unicode.UTF8.ReverseDecoder : _UTF8Decoder {
634634

635635
public // @testable
636636
func _parseMultipleCodeUnits() -> Unicode.ParseResult<EncodedScalar> {
637-
_sanityCheck(buffer._storage & 0x80 != 0) // this case handled elsewhere
637+
assert(buffer._storage & 0x80 != 0) // this case handled elsewhere
638638

639639
if buffer._storage & 0b0__1110_0000__1100_0000
640640
== 0b0__1100_0000__1000_0000 {
@@ -737,7 +737,7 @@ extension Unicode.UTF8.ForwardDecoder : _UTF8Decoder {
737737

738738
public // @testable
739739
func _parseMultipleCodeUnits() -> Unicode.ParseResult<EncodedScalar> {
740-
_sanityCheck(buffer._storage & 0x80 != 0) // this case handled elsewhere
740+
assert(buffer._storage & 0x80 != 0) // this case handled elsewhere
741741

742742
if buffer._storage & 0b0__1100_0000__1110_0000
743743
== 0b0__1000_0000__1100_0000 {
@@ -813,7 +813,7 @@ extension _UTF16Decoder {
813813
}
814814

815815
internal mutating func _consume(bitCount: UInt8) -> EncodedScalar {
816-
_sanityCheck(bitCount == 16)
816+
assert(bitCount == 16)
817817
let s = buffer._storage
818818
buffer._storage = 0
819819
buffer._bitCount = 0
@@ -822,7 +822,7 @@ extension _UTF16Decoder {
822822

823823
public // @testable
824824
func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
825-
_sanityCheck( // this case handled elsewhere
825+
assert( // this case handled elsewhere
826826
!Self._isScalar(UInt16(truncatingIfNeeded: buffer._storage)))
827827

828828
if _fastPath(buffer._storage & 0xFC00_FC00 == Self._surrogatePattern) {
@@ -855,7 +855,7 @@ extension Unicode.UTF16 : UnicodeEncoding {
855855
if _fastPath(source._bitCount == 16) {
856856
return UnicodeScalar(_unchecked: bits & 0xffff)
857857
}
858-
_sanityCheck(source._bitCount == 32)
858+
assert(source._bitCount == 32)
859859
let value = 0x10000 + (bits >> 16 & 0x03ff | (bits & 0x03ff) << 10)
860860
return UnicodeScalar(_unchecked: value)
861861
}

0 commit comments

Comments
 (0)