Skip to content

Replace some precondition with _precondition in the stdlib. (#82641) #82656

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
10 changes: 5 additions & 5 deletions stdlib/public/core/Integers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3089,9 +3089,9 @@ extension UnsignedInteger where Self: FixedWidthInteger {
_ dividend: (high: Self, low: Magnitude)
) -> (quotient: Self, remainder: Self) {
// Validate preconditions to guarantee that the quotient is representable.
precondition(self != .zero, "Division by zero")
precondition(dividend.high < self,
"Dividend.high must be smaller than divisor")
_precondition(self != .zero, "Division by zero")
_precondition(dividend.high < self,
"Dividend.high must be smaller than divisor")
// UnsignedInteger should have a Magnitude = Self constraint, but does not,
// so we have to do this conversion (we can't easily add the constraint
// because it changes how generic signatures constrained to
Expand Down Expand Up @@ -3336,8 +3336,8 @@ extension SignedInteger where Self: FixedWidthInteger {
// It is possible that the quotient is representable but its magnitude
// is not representable as Self (if quotient is Self.min), so we have
// to handle that case carefully here.
precondition(unsignedQuotient <= Self.min.magnitude,
"Quotient is not representable.")
_precondition(unsignedQuotient <= Self.min.magnitude,
"Quotient is not representable.")
quotient = Self(truncatingIfNeeded: 0 &- unsignedQuotient)
} else {
quotient = Self(unsignedQuotient)
Expand Down
26 changes: 13 additions & 13 deletions stdlib/public/core/UTF8SpanFundamentals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension UTF8Span {
///
/// `i` must be scalar-aligned.
internal func _previousScalarStart(_ i: Int) -> Int {
precondition(_boundsCheck(i&-1))
_precondition(_boundsCheck(i&-1))
return _previousScalarStart(unchecked: i)
}

Expand All @@ -31,7 +31,7 @@ extension UTF8Span {
/// this is an unsafe operation.
internal func _previousScalarStart(unchecked i: Int) -> Int {
_internalInvariant(_boundsCheck(i&-1))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _previousScalarStart(uncheckedAssumingAligned: i)
}

Expand Down Expand Up @@ -81,7 +81,7 @@ extension UTF8Span {
internal func _decodePreviousScalar(
_ i: Int
) -> (Unicode.Scalar, previousScalarStart: Int) {
precondition(_boundsCheck(i &- 1))
_precondition(_boundsCheck(i &- 1))
return _decodePreviousScalar(unchecked: i)
}

Expand All @@ -96,7 +96,7 @@ extension UTF8Span {
unchecked i: Int
) -> (Unicode.Scalar, previousScalarStart: Int) {
_internalInvariant(_boundsCheck(i &- 1))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _decodePreviousScalar(uncheckedAssumingAligned: i)
}

Expand Down Expand Up @@ -127,7 +127,7 @@ extension UTF8Span {
internal func _scalarAlignBackwards(_ i: Int) -> Int {
if i == count || i == 0 { return i }

precondition(_boundsCheck(i))
_precondition(_boundsCheck(i))
return unsafe _start()._scalarAlign(i)
}

Expand Down Expand Up @@ -169,7 +169,7 @@ extension UTF8Span {
///
/// `i` must be `Character`-aligned.
internal func _nextCharacterStart(_ i: Int) -> Int {
precondition(_boundsCheck(i))
_precondition(_boundsCheck(i))
return _nextCharacterStart(unchecked: i)
}

Expand All @@ -183,7 +183,7 @@ extension UTF8Span {
/// this is an unsafe operation.
internal func _nextCharacterStart(unchecked i: Int) -> Int {
_internalInvariant(_boundsCheck(i))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _nextCharacterStart(uncheckedAssumingAligned: i)
}

Expand Down Expand Up @@ -212,7 +212,7 @@ extension UTF8Span {
///
/// `i` must be `Character`-aligned.
internal func _previousCharacterStart(_ i: Int) -> Int {
precondition(_boundsCheck(i&-1))
_precondition(_boundsCheck(i&-1))
return _previousCharacterStart(unchecked: i)
}

Expand All @@ -226,7 +226,7 @@ extension UTF8Span {
/// this is an unsafe operation.
internal func _previousCharacterStart(unchecked i: Int) -> Int {
_internalInvariant(_boundsCheck(i&-1))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _previousCharacterStart(uncheckedAssumingAligned: i)
}

Expand Down Expand Up @@ -256,7 +256,7 @@ extension UTF8Span {
internal func _decodeNextCharacter(
_ i: Int
) -> (Character, nextCharacterStart: Int) {
precondition(_boundsCheck(i))
_precondition(_boundsCheck(i))
return _decodeNextCharacter(unchecked: i)
}

Expand All @@ -271,7 +271,7 @@ extension UTF8Span {
unchecked i: Int
) -> (Character, nextCharacterStart: Int) {
_internalInvariant(_boundsCheck(i))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _decodeNextCharacter(uncheckedAssumingAligned: i)
}

Expand Down Expand Up @@ -299,7 +299,7 @@ extension UTF8Span {
///
/// `i` must be `Character`-aligned.
internal func _decodePreviousCharacter(_ i: Int) -> (Character, Int) {
precondition(_boundsCheck(i &- 1))
_precondition(_boundsCheck(i &- 1))
return _decodePreviousCharacter(unchecked: i)
}

Expand All @@ -314,7 +314,7 @@ extension UTF8Span {
unchecked i: Int
) -> (Character, Int) {
_internalInvariant(_boundsCheck(i &- 1))
precondition(_isScalarAligned(unchecked: i))
_precondition(_isScalarAligned(unchecked: i))
return _decodePreviousCharacter(uncheckedAssumingAligned: i)
}

Expand Down