Skip to content

[5.0] Cherry-pick important bug fix and ABI expunges #20844

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 3 commits into from
Nov 29, 2018
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: 3 additions & 7 deletions stdlib/public/core/StringGutsSlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@

// A sliced _StringGuts, convenient for unifying String/Substring comparison,
// hashing, and RRC.
@_fixed_layout
@usableFromInline
internal struct _StringGutsSlice {
@usableFromInline
internal var _guts: _StringGuts

@usableFromInline
internal var _offsetRange: Range<Int>

@inlinable @inline(__always)
@inline(__always)
internal init(_ guts: _StringGuts) {
self._guts = guts
self._offsetRange = 0..<self._guts.count
}

@inlinable @inline(__always)
@inline(__always)
internal init(_ guts: _StringGuts, _ offsetRange: Range<Int>) {
self._guts = guts
self._offsetRange = offsetRange
Expand Down Expand Up @@ -83,7 +79,7 @@ internal struct _StringGutsSlice {
}
}

@inlinable @inline(__always)
@inline(__always)
internal func withFastUTF8<R>(
_ f: (UnsafeBufferPointer<UInt8>) throws -> R
) rethrows -> R {
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/core/StringHashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ extension StringProtocol {
}

extension _StringGutsSlice {
@usableFromInline // @opaque
@inline(never) // slow-path
internal func _normalizedHash(into hasher: inout Hasher) {
if self.isNFCFastUTF8 {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/StringProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ extension StringProtocol {
get { return String(self) }
}

@inlinable // Eliminate for String, Substring
internal var _gutsSlice: _StringGutsSlice {
@_specialize(where Self == String)
@_specialize(where Self == Substring)
Expand All @@ -152,7 +151,8 @@ extension StringProtocol {
@inline(__always) get {
let start = startIndex
let end = endIndex
_internalInvariant(start.transcodedOffset == 0 && end.transcodedOffset == 0)
_internalInvariant(
start.transcodedOffset == 0 && end.transcodedOffset == 0)
return Range(uncheckedBounds: (start.encodedOffset, end.encodedOffset))
}
}
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/core/StringStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ final internal class _StringStorage: _AbstractStringStorage {

internal var _reserved: UInt16

@inlinable
override internal var count: Int {
@inline(__always) get { return _count }
@inline(__always) set { _count = newValue }
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/StringUTF16View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ extension String {
) {
_internalInvariant(_guts.isFastUTF8)

if _slowPath(range.isEmpty) { return }

return _guts.withFastUTF8 { utf8 in
var writeIdx = 0
let writeEnd = buffer.count
Expand Down
17 changes: 17 additions & 0 deletions test/api-digester/Outputs/stability-stdlib-abi.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,23 @@ Protocol _NSEnumerator has been removed
Protocol _NSFastEnumeration has been removed
Protocol _ShadowProtocol has been removed

Constructor _StringGutsSlice.init(_:) has been removed
Constructor _StringGutsSlice.init(_:_:) has been removed
Func _StringGutsSlice._normalizedHash(into:) has been removed
Func _StringGutsSlice.compare(with:expecting:) has been removed
Func _StringGutsSlice.withFastUTF8(_:) has been removed
Struct _StringGutsSlice is now without @_fixed_layout
Var StringProtocol._gutsSlice has been removed
Var _StringGutsSlice._guts has been removed
Var _StringGutsSlice._offsetRange has been removed
Var _StringGutsSlice.count has been removed
Var _StringGutsSlice.end has been removed
Var _StringGutsSlice.isASCII has been removed
Var _StringGutsSlice.isFastUTF8 has been removed
Var _StringGutsSlice.isNFCFastUTF8 has been removed
Var _StringGutsSlice.range has been removed
Var _StringGutsSlice.start has been removed

Func ManagedBufferPointer._sanityCheckValidBufferClass(_:creating:) has been removed
Func _sanityCheck(_:_:file:line:) has been removed
Func _sanityCheckFailure(_:file:line:) has been removed
Expand Down
16 changes: 13 additions & 3 deletions validation-test/stdlib/StringBreadcrumbs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ let StringBreadcrumbsTests = TestSuite("StringBreadcrumbsTests")

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

for i in 0..<(utf16CodeUnits.count-1) {
for j in (i+1)..<utf16CodeUnits.count {
// Include the endIndex, so we can test end conversions
var utf16Indices = Array(str.utf16.indices) + [str.utf16.endIndex]

for i in 0...utf16CodeUnits.count {
for j in i...utf16CodeUnits.count {
let range = Range(uncheckedBounds: (i, j))

let indexRange = str._toUTF16Indices(range)

// Range<String.Index> <=> Range<Int>
expectEqual(utf16Indices[i], indexRange.lowerBound)
expectEqual(utf16Indices[j], indexRange.upperBound)
Expand All @@ -69,6 +72,13 @@ func validateBreadcrumbs(_ str: String) {
}
}

StringBreadcrumbsTests.test("uniform strings") {
validateBreadcrumbs(smallASCII)
validateBreadcrumbs(largeASCII)
validateBreadcrumbs(smallUnicode)
validateBreadcrumbs(largeUnicode)
}

StringBreadcrumbsTests.test("largeString") {
validateBreadcrumbs(largeString)
}
Expand Down