Skip to content

Commit 1939d16

Browse files
committed
Make corelibs-foundation build
Expose the old SPIs again so corelibs-foundation can build. We'll want to wean them off of these and establish proper APIs soon.
1 parent c04dcf3 commit 1939d16

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

stdlib/public/core/String.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ internal func unimplemented_utf8_32bit(
350350
/// [equivalence]: http://www.unicode.org/glossary/#canonical_equivalent
351351
@_fixed_layout
352352
public struct String {
353-
@usableFromInline
354-
internal var _guts: _StringGuts
353+
public // @SPI(Foundation)
354+
var _guts: _StringGuts
355355

356356
@inlinable @inline(__always)
357357
internal init(_ _guts: _StringGuts) {

stdlib/public/core/StringGuts.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import SwiftShims
1616
// StringGuts is a parameterization over String's representations. It provides
1717
// functionality and guidance for efficiently working with Strings.
1818
//
19-
@_fixed_layout @usableFromInline
20-
internal struct _StringGuts {
19+
@_fixed_layout
20+
public // SPI(corelibs-foundation)
21+
struct _StringGuts {
2122
@usableFromInline
2223
internal var _object: _StringObject
2324

@@ -287,3 +288,43 @@ extension _StringGuts {
287288
@inline(__always) get { return Index(encodedOffset: self.count) }
288289
}
289290
}
291+
292+
// Old SPI(corelibs-foundation)
293+
extension _StringGuts {
294+
@available(*, deprecated)
295+
public // SPI(corelibs-foundation)
296+
var _isContiguousASCII: Bool {
297+
return !isSmall && isFastUTF8 && isASCII
298+
}
299+
300+
@available(*, deprecated)
301+
public // SPI(corelibs-foundation)
302+
var _isContiguousUTF16: Bool {
303+
return false
304+
}
305+
306+
// FIXME: Remove. Still used by swift-corelibs-foundation
307+
@available(*, deprecated)
308+
public var startASCII: UnsafeMutablePointer<UInt8> {
309+
return UnsafeMutablePointer(mutating: _object.fastUTF8.baseAddress!)
310+
}
311+
312+
// FIXME: Remove. Still used by swift-corelibs-foundation
313+
@available(*, deprecated)
314+
public var startUTF16: UnsafeMutablePointer<UTF16.CodeUnit> {
315+
fatalError("Not contiguous UTF-16")
316+
}
317+
}
318+
319+
@available(*, deprecated)
320+
public // SPI(corelibs-foundation)
321+
func _persistCString(_ p: UnsafePointer<CChar>?) -> [CChar]? {
322+
guard let s = p else { return nil }
323+
let count = Int(_swift_stdlib_strlen(s))
324+
var result = [CChar](repeating: 0, count: count + 1)
325+
for i in 0..<count {
326+
result[i] = s[i]
327+
}
328+
return result
329+
}
330+

stdlib/public/core/StringUTF16View.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension String.UTF16View {
497497

498498
return _guts.withFastUTF8 { utf8 in
499499
var readIdx = crumb.encodedOffset
500-
var readEnd = utf8.count
500+
let readEnd = utf8.count
501501
_sanityCheck(readIdx < readEnd)
502502

503503
var utf16I = 0

0 commit comments

Comments
 (0)