Skip to content

Commit 83ed42a

Browse files
milsemanairspeedswift
authored andcommitted
[5.0] Cherry-pick important bug fix and ABI expunges (#20844)
* [String] Drop spurious @inlinable * [String] Bug fix for empty-range getCharacters * [String] Expunge _StringGutsSlice from ABI _StringGutsSlice is an implementation helper that's no longer needed from inlinable code. Internalize it.
1 parent 953d5e8 commit 83ed42a

File tree

7 files changed

+37
-14
lines changed

7 files changed

+37
-14
lines changed

stdlib/public/core/StringGutsSlice.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616

1717
// A sliced _StringGuts, convenient for unifying String/Substring comparison,
1818
// hashing, and RRC.
19-
@_fixed_layout
20-
@usableFromInline
2119
internal struct _StringGutsSlice {
22-
@usableFromInline
2320
internal var _guts: _StringGuts
2421

25-
@usableFromInline
2622
internal var _offsetRange: Range<Int>
2723

28-
@inlinable @inline(__always)
24+
@inline(__always)
2925
internal init(_ guts: _StringGuts) {
3026
self._guts = guts
3127
self._offsetRange = 0..<self._guts.count
3228
}
3329

34-
@inlinable @inline(__always)
30+
@inline(__always)
3531
internal init(_ guts: _StringGuts, _ offsetRange: Range<Int>) {
3632
self._guts = guts
3733
self._offsetRange = offsetRange
@@ -83,7 +79,7 @@ internal struct _StringGutsSlice {
8379
}
8480
}
8581

86-
@inlinable @inline(__always)
82+
@inline(__always)
8783
internal func withFastUTF8<R>(
8884
_ f: (UnsafeBufferPointer<UInt8>) throws -> R
8985
) rethrows -> R {

stdlib/public/core/StringHashable.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ extension StringProtocol {
4545
}
4646

4747
extension _StringGutsSlice {
48-
@usableFromInline // @opaque
4948
@inline(never) // slow-path
5049
internal func _normalizedHash(into hasher: inout Hasher) {
5150
if self.isNFCFastUTF8 {

stdlib/public/core/StringProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ extension StringProtocol {
132132
get { return String(self) }
133133
}
134134

135-
@inlinable // Eliminate for String, Substring
136135
internal var _gutsSlice: _StringGutsSlice {
137136
@_specialize(where Self == String)
138137
@_specialize(where Self == Substring)
@@ -152,7 +151,8 @@ extension StringProtocol {
152151
@inline(__always) get {
153152
let start = startIndex
154153
let end = endIndex
155-
_internalInvariant(start.transcodedOffset == 0 && end.transcodedOffset == 0)
154+
_internalInvariant(
155+
start.transcodedOffset == 0 && end.transcodedOffset == 0)
156156
return Range(uncheckedBounds: (start.encodedOffset, end.encodedOffset))
157157
}
158158
}

stdlib/public/core/StringStorage.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ final internal class _StringStorage: _AbstractStringStorage {
189189

190190
internal var _reserved: UInt16
191191

192-
@inlinable
193192
override internal var count: Int {
194193
@inline(__always) get { return _count }
195194
@inline(__always) set { _count = newValue }

stdlib/public/core/StringUTF16View.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ extension String {
537537
) {
538538
_internalInvariant(_guts.isFastUTF8)
539539

540+
if _slowPath(range.isEmpty) { return }
541+
540542
return _guts.withFastUTF8 { utf8 in
541543
var writeIdx = 0
542544
let writeEnd = buffer.count

test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ Protocol _NSEnumerator has been removed
483483
Protocol _NSFastEnumeration has been removed
484484
Protocol _ShadowProtocol has been removed
485485

486+
Constructor _StringGutsSlice.init(_:) has been removed
487+
Constructor _StringGutsSlice.init(_:_:) has been removed
488+
Func _StringGutsSlice._normalizedHash(into:) has been removed
489+
Func _StringGutsSlice.compare(with:expecting:) has been removed
490+
Func _StringGutsSlice.withFastUTF8(_:) has been removed
491+
Struct _StringGutsSlice is now without @_fixed_layout
492+
Var StringProtocol._gutsSlice has been removed
493+
Var _StringGutsSlice._guts has been removed
494+
Var _StringGutsSlice._offsetRange has been removed
495+
Var _StringGutsSlice.count has been removed
496+
Var _StringGutsSlice.end has been removed
497+
Var _StringGutsSlice.isASCII has been removed
498+
Var _StringGutsSlice.isFastUTF8 has been removed
499+
Var _StringGutsSlice.isNFCFastUTF8 has been removed
500+
Var _StringGutsSlice.range has been removed
501+
Var _StringGutsSlice.start has been removed
502+
486503
Func ManagedBufferPointer._sanityCheckValidBufferClass(_:creating:) has been removed
487504
Func _sanityCheck(_:_:file:line:) has been removed
488505
Func _sanityCheckFailure(_:file:line:) has been removed

validation-test/stdlib/StringBreadcrumbs.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ let StringBreadcrumbsTests = TestSuite("StringBreadcrumbsTests")
3838

3939
func validateBreadcrumbs(_ str: String) {
4040
var utf16CodeUnits = Array(str.utf16)
41-
var utf16Indices = Array(str.utf16.indices)
4241
var outputBuffer = Array<UInt16>(repeating: 0, count: utf16CodeUnits.count)
4342

44-
for i in 0..<(utf16CodeUnits.count-1) {
45-
for j in (i+1)..<utf16CodeUnits.count {
43+
// Include the endIndex, so we can test end conversions
44+
var utf16Indices = Array(str.utf16.indices) + [str.utf16.endIndex]
45+
46+
for i in 0...utf16CodeUnits.count {
47+
for j in i...utf16CodeUnits.count {
4648
let range = Range(uncheckedBounds: (i, j))
4749

4850
let indexRange = str._toUTF16Indices(range)
51+
4952
// Range<String.Index> <=> Range<Int>
5053
expectEqual(utf16Indices[i], indexRange.lowerBound)
5154
expectEqual(utf16Indices[j], indexRange.upperBound)
@@ -69,6 +72,13 @@ func validateBreadcrumbs(_ str: String) {
6972
}
7073
}
7174

75+
StringBreadcrumbsTests.test("uniform strings") {
76+
validateBreadcrumbs(smallASCII)
77+
validateBreadcrumbs(largeASCII)
78+
validateBreadcrumbs(smallUnicode)
79+
validateBreadcrumbs(largeUnicode)
80+
}
81+
7282
StringBreadcrumbsTests.test("largeString") {
7383
validateBreadcrumbs(largeString)
7484
}

0 commit comments

Comments
 (0)