[stdlib] Introduce _invariantCheck_5_1 for 5.1 and later assertions.

Inlinable and non-inlinable code can cause 5.1 code to intermix with
5.0 code on older OSes. Some (weak) invariants for 5.1 should only be
checked when the OS's code is 5.1 or later, which is the purpose of
_invariantCheck_5_1.

Applied to String.Index._isScalarAligned, which is a new bit
introduced in 5.1 from one of the reserved bits from 5.0. The bit is
set when the index is proven to be scalar aligned, and we want to
assert on this liberally in contexts where we expect it to be
so. However, older OSes might not set this bit when doing scalar
aligning, depending on exactly what got inlined where/when.
This commit is contained in:
Michael Ilseman
2019-07-12 15:47:46 -07:00
parent 37db5872c3
commit e01a294da6
4 changed files with 23 additions and 7 deletions

View File

@@ -164,7 +164,7 @@ extension String.Index {
internal func _invariantCheck() {
_internalInvariant(_encodedOffset >= 0)
if self._isScalarAligned {
_internalInvariant(transcodedOffset == 0)
_internalInvariant_5_1(transcodedOffset == 0)
}
}
#endif // INTERNAL_CHECKS_ENABLED