mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #70446 from kubamracek/embedded-string
[embedded] Port Swift.String to embedded Swift
This commit is contained in:
@@ -41,14 +41,13 @@ func _allocateUninitializedArray<Element>(_ builtinCount: Builtin.Word)
|
||||
if count > 0 {
|
||||
// Doing the actual buffer allocation outside of the array.uninitialized
|
||||
// semantics function enables stack propagation of the buffer.
|
||||
let storageType: _ContiguousArrayStorage<Element>.Type
|
||||
#if !$Embedded
|
||||
storageType = getContiguousArrayStorageType(for: Element.self)
|
||||
#else
|
||||
storageType = _ContiguousArrayStorage<Element>.self
|
||||
#endif
|
||||
let bufferObject = Builtin.allocWithTailElems_1(
|
||||
storageType, builtinCount, Element.self)
|
||||
getContiguousArrayStorageType(for: Element.self), builtinCount, Element.self)
|
||||
#else
|
||||
let bufferObject = Builtin.allocWithTailElems_1(
|
||||
_ContiguousArrayStorage<Element>.self, builtinCount, Element.self)
|
||||
#endif
|
||||
|
||||
let (array, ptr) = Array<Element>._adoptStorage(bufferObject, count: count)
|
||||
return (array, ptr._rawValue)
|
||||
@@ -122,7 +121,11 @@ extension Collection {
|
||||
} else {
|
||||
result += ", "
|
||||
}
|
||||
#if !$Embedded
|
||||
debugPrint(item, terminator: "", to: &result)
|
||||
#else
|
||||
"(cannot print value in embedded Swift)".write(to: &result)
|
||||
#endif
|
||||
}
|
||||
result += type != nil ? "])" : "]"
|
||||
return result
|
||||
|
||||
@@ -413,8 +413,10 @@ internal func _internalInvariant_5_1(
|
||||
// FIXME: The below won't run the assert on 5.1 stdlib if testing on older
|
||||
// OSes, which means that testing may not test the assertion. We need a real
|
||||
// solution to this.
|
||||
#if !$Embedded
|
||||
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) //SwiftStdlib 5.1
|
||||
else { return }
|
||||
#endif
|
||||
_internalInvariant(condition(), message, file: file, line: line)
|
||||
#endif
|
||||
}
|
||||
@@ -427,7 +429,6 @@ internal func _internalInvariant_5_1(
|
||||
/// **and** the current executable was built with a Swift Standard Library
|
||||
/// version equal to or greater than the supplied version.
|
||||
@_transparent
|
||||
@_unavailableInEmbedded
|
||||
internal func _precondition(
|
||||
ifLinkedOnOrAfter version: _SwiftStdlibVersion,
|
||||
_ condition: @autoclosure () -> Bool,
|
||||
@@ -443,17 +444,22 @@ internal func _precondition(
|
||||
// unusual configuration.
|
||||
if _isDebugAssertConfiguration() {
|
||||
if _slowPath(!condition()) {
|
||||
#if !$Embedded
|
||||
guard _isExecutableLinkedOnOrAfter(version) else { return }
|
||||
#endif
|
||||
_assertionFailure("Fatal error", message, file: file, line: line,
|
||||
flags: _fatalErrorFlags())
|
||||
}
|
||||
} else if _isReleaseAssertConfiguration() {
|
||||
#if !$Embedded
|
||||
let error = (!condition() && _isExecutableLinkedOnOrAfter(version))
|
||||
#else
|
||||
let error = !condition()
|
||||
#endif
|
||||
Builtin.condfail_message(error._value, message.unsafeRawPointer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@usableFromInline @_transparent
|
||||
internal func _internalInvariantFailure(
|
||||
_ message: StaticString = StaticString(),
|
||||
|
||||
@@ -731,9 +731,9 @@ func _isUnique_native<T>(_ object: inout T) -> Bool {
|
||||
_internalInvariant(
|
||||
(_bitPattern(Builtin.reinterpretCast(object)) & _objectPointerSpareBits)
|
||||
== 0)
|
||||
#endif
|
||||
_internalInvariant(_usesNativeSwiftReferenceCounting(
|
||||
type(of: Builtin.reinterpretCast(object) as AnyObject)))
|
||||
#endif
|
||||
return Bool(Builtin.isUnique_native(&object))
|
||||
}
|
||||
|
||||
@@ -1093,7 +1093,6 @@ func __abi_openExistential<ExistentialType, ContainedType, ResultType>(
|
||||
/// in the function containing the call to this SPI.
|
||||
@_transparent
|
||||
@_alwaysEmitIntoClient
|
||||
@_unavailableInEmbedded
|
||||
public // @SPI(OSLog)
|
||||
func _getGlobalStringTablePointer(_ constant: String) -> UnsafePointer<CChar> {
|
||||
return UnsafePointer<CChar>(Builtin.globalStringTablePointer(constant));
|
||||
|
||||
@@ -34,12 +34,12 @@ split_embedded_sources(
|
||||
EMBEDDED ArrayBody.swift
|
||||
EMBEDDED ArrayBuffer.swift
|
||||
EMBEDDED ArrayBufferProtocol.swift
|
||||
NORMAL ArrayCast.swift
|
||||
EMBEDDED ArrayCast.swift
|
||||
EMBEDDED Array.swift
|
||||
EMBEDDED ArrayShared.swift
|
||||
EMBEDDED ArraySlice.swift
|
||||
EMBEDDED ArrayType.swift
|
||||
NORMAL ASCII.swift
|
||||
EMBEDDED ASCII.swift
|
||||
EMBEDDED Assert.swift
|
||||
EMBEDDED AssertCommon.swift
|
||||
EMBEDDED BidirectionalCollection.swift
|
||||
@@ -50,7 +50,7 @@ split_embedded_sources(
|
||||
NORMAL BridgingBuffer.swift
|
||||
EMBEDDED Builtin.swift
|
||||
EMBEDDED BuiltinMath.swift
|
||||
NORMAL Character.swift
|
||||
EMBEDDED Character.swift
|
||||
NORMAL CocoaArray.swift
|
||||
NORMAL Codable.swift
|
||||
EMBEDDED Collection.swift
|
||||
@@ -59,10 +59,10 @@ split_embedded_sources(
|
||||
EMBEDDED CompilerProtocols.swift
|
||||
EMBEDDED Sendable.swift
|
||||
EMBEDDED ContiguousArray.swift
|
||||
NORMAL ContiguouslyStored.swift
|
||||
EMBEDDED ContiguouslyStored.swift
|
||||
EMBEDDED ClosedRange.swift
|
||||
EMBEDDED ContiguousArrayBuffer.swift
|
||||
NORMAL CString.swift
|
||||
EMBEDDED CString.swift
|
||||
EMBEDDED CTypes.swift
|
||||
NORMAL DebuggerSupport.swift
|
||||
EMBEDDED Dictionary.swift
|
||||
@@ -93,7 +93,7 @@ split_embedded_sources(
|
||||
EMBEDDED HashTable.swift
|
||||
EMBEDDED Identifiable.swift
|
||||
EMBEDDED Indices.swift
|
||||
NORMAL InputStream.swift
|
||||
EMBEDDED InputStream.swift
|
||||
NORMAL IntegerParsing.swift
|
||||
EMBEDDED Integers.swift
|
||||
NORMAL Join.swift
|
||||
@@ -114,12 +114,12 @@ split_embedded_sources(
|
||||
EMBEDDED NativeDictionary.swift
|
||||
EMBEDDED NativeSet.swift
|
||||
NORMAL NewtypeWrapper.swift
|
||||
NORMAL NFC.swift
|
||||
NORMAL NFD.swift
|
||||
EMBEDDED NFC.swift
|
||||
EMBEDDED NFD.swift
|
||||
EMBEDDED ObjectIdentifier.swift
|
||||
EMBEDDED Optional.swift
|
||||
EMBEDDED OptionSet.swift
|
||||
NORMAL OutputStream.swift
|
||||
EMBEDDED OutputStream.swift
|
||||
EMBEDDED Pointer.swift
|
||||
EMBEDDED Policy.swift
|
||||
NORMAL PrefixWhile.swift
|
||||
@@ -153,68 +153,68 @@ split_embedded_sources(
|
||||
EMBEDDED ShadowProtocols.swift
|
||||
NORMAL Shims.swift
|
||||
EMBEDDED Slice.swift
|
||||
NORMAL SmallString.swift
|
||||
EMBEDDED SmallString.swift
|
||||
EMBEDDED Sort.swift
|
||||
EMBEDDED StaticString.swift
|
||||
NORMAL StaticPrint.swift
|
||||
EMBEDDED StaticPrint.swift
|
||||
EMBEDDED Stride.swift
|
||||
NORMAL StringHashable.swift # ORDER DEPENDENCY: Must precede String.swift
|
||||
NORMAL String.swift
|
||||
NORMAL StringBreadcrumbs.swift
|
||||
NORMAL StringBridge.swift
|
||||
NORMAL StringCharacterView.swift
|
||||
NORMAL StringComparable.swift
|
||||
NORMAL StringComparison.swift
|
||||
NORMAL StringCreate.swift
|
||||
NORMAL StringGuts.swift
|
||||
NORMAL StringGutsSlice.swift
|
||||
NORMAL StringGutsRangeReplaceable.swift
|
||||
NORMAL StringObject.swift
|
||||
NORMAL StringProtocol.swift
|
||||
NORMAL StringIndex.swift
|
||||
NORMAL StringIndexConversions.swift
|
||||
NORMAL StringIndexValidation.swift
|
||||
NORMAL StringInterpolation.swift
|
||||
NORMAL StringLegacy.swift
|
||||
NORMAL StringNormalization.swift
|
||||
NORMAL StringRangeReplaceableCollection.swift
|
||||
NORMAL StringStorage.swift
|
||||
NORMAL StringStorageBridge.swift
|
||||
EMBEDDED StringHashable.swift # ORDER DEPENDENCY: Must precede String.swift
|
||||
EMBEDDED String.swift
|
||||
EMBEDDED StringBreadcrumbs.swift
|
||||
EMBEDDED StringBridge.swift
|
||||
EMBEDDED StringCharacterView.swift
|
||||
EMBEDDED StringComparable.swift
|
||||
EMBEDDED StringComparison.swift
|
||||
EMBEDDED StringCreate.swift
|
||||
EMBEDDED StringGuts.swift
|
||||
EMBEDDED StringGutsSlice.swift
|
||||
EMBEDDED StringGutsRangeReplaceable.swift
|
||||
EMBEDDED StringObject.swift
|
||||
EMBEDDED StringProtocol.swift
|
||||
EMBEDDED StringIndex.swift
|
||||
EMBEDDED StringIndexConversions.swift
|
||||
EMBEDDED StringIndexValidation.swift
|
||||
EMBEDDED StringInterpolation.swift
|
||||
EMBEDDED StringLegacy.swift
|
||||
EMBEDDED StringNormalization.swift
|
||||
EMBEDDED StringRangeReplaceableCollection.swift
|
||||
EMBEDDED StringStorage.swift
|
||||
EMBEDDED StringStorageBridge.swift
|
||||
NORMAL StringSwitch.swift
|
||||
NORMAL StringTesting.swift
|
||||
NORMAL StringUnicodeScalarView.swift
|
||||
NORMAL StringUTF16View.swift
|
||||
NORMAL StringUTF8View.swift
|
||||
NORMAL StringUTF8Validation.swift
|
||||
NORMAL StringWordBreaking.swift
|
||||
NORMAL Substring.swift
|
||||
EMBEDDED StringTesting.swift
|
||||
EMBEDDED StringUnicodeScalarView.swift
|
||||
EMBEDDED StringUTF16View.swift
|
||||
EMBEDDED StringUTF8View.swift
|
||||
EMBEDDED StringUTF8Validation.swift
|
||||
EMBEDDED StringWordBreaking.swift
|
||||
EMBEDDED Substring.swift
|
||||
EMBEDDED SwiftNativeNSArray.swift
|
||||
EMBEDDED TemporaryAllocation.swift
|
||||
NORMAL ThreadLocalStorage.swift
|
||||
NORMAL UIntBuffer.swift
|
||||
NORMAL UnavailableStringAPIs.swift
|
||||
NORMAL UnicodeData.swift
|
||||
NORMAL UnicodeEncoding.swift
|
||||
NORMAL UnicodeBreakProperty.swift
|
||||
NORMAL UnicodeHelpers.swift
|
||||
NORMAL UnicodeParser.swift
|
||||
NORMAL UnicodeScalarProperties.swift
|
||||
NORMAL CharacterProperties.swift # ORDER DEPENDENCY: UnicodeScalarProperties.swift
|
||||
NORMAL UnicodeSPI.swift
|
||||
EMBEDDED UIntBuffer.swift
|
||||
EMBEDDED UnavailableStringAPIs.swift
|
||||
EMBEDDED UnicodeData.swift
|
||||
EMBEDDED UnicodeEncoding.swift
|
||||
EMBEDDED UnicodeBreakProperty.swift
|
||||
EMBEDDED UnicodeHelpers.swift
|
||||
EMBEDDED UnicodeParser.swift
|
||||
EMBEDDED UnicodeScalarProperties.swift
|
||||
EMBEDDED CharacterProperties.swift # ORDER DEPENDENCY: UnicodeScalarProperties.swift
|
||||
EMBEDDED UnicodeSPI.swift
|
||||
EMBEDDED Unmanaged.swift
|
||||
NORMAL UnmanagedOpaqueString.swift
|
||||
NORMAL UnmanagedString.swift
|
||||
EMBEDDED UnmanagedOpaqueString.swift
|
||||
EMBEDDED UnmanagedString.swift
|
||||
EMBEDDED UnsafePointer.swift
|
||||
EMBEDDED UnsafeRawPointer.swift
|
||||
NORMAL UTFEncoding.swift
|
||||
NORMAL UTF8.swift
|
||||
NORMAL UTF16.swift
|
||||
NORMAL UTF32.swift
|
||||
NORMAL Unicode.swift # ORDER DEPENDENCY: must follow new unicode support
|
||||
NORMAL StringGraphemeBreaking.swift # ORDER DEPENDENCY: Must follow UTF16.swift
|
||||
NORMAL ValidUTF8Buffer.swift
|
||||
EMBEDDED UTFEncoding.swift
|
||||
EMBEDDED UTF8.swift
|
||||
EMBEDDED UTF16.swift
|
||||
EMBEDDED UTF32.swift
|
||||
EMBEDDED Unicode.swift # ORDER DEPENDENCY: must follow new unicode support
|
||||
EMBEDDED StringGraphemeBreaking.swift # ORDER DEPENDENCY: Must follow UTF16.swift
|
||||
EMBEDDED ValidUTF8Buffer.swift
|
||||
EMBEDDED WriteBackMutableSlice.swift
|
||||
NORMAL MigrationSupport.swift
|
||||
EMBEDDED MigrationSupport.swift
|
||||
|
||||
### "NON-ESSENTIAL" SOURCES, LAYERED ON TOP OF THE "ESSENTIAL" ONES
|
||||
### -- PLEASE KEEP THIS LIST IN ALPHABETICAL ORDER ###
|
||||
@@ -234,7 +234,7 @@ split_embedded_sources(
|
||||
NORMAL StaticBigInt.swift
|
||||
EMBEDDED UInt128.swift
|
||||
NORMAL UnfoldSequence.swift
|
||||
NORMAL UnsafeBufferPointerSlice.swift
|
||||
EMBEDDED UnsafeBufferPointerSlice.swift
|
||||
NORMAL VarArgs.swift
|
||||
EMBEDDED Zip.swift
|
||||
NORMAL "${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"
|
||||
@@ -420,6 +420,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
|
||||
set(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT OFF)
|
||||
set(SWIFT_STDLIB_STABLE_ABI OFF)
|
||||
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP OFF)
|
||||
set(SWIFT_STDLIB_ENABLE_VECTOR_TYPES OFF)
|
||||
|
||||
foreach(entry ${EMBEDDED_STDLIB_TARGET_TRIPLES})
|
||||
string(REGEX REPLACE "[ \t]+" ";" list "${entry}")
|
||||
|
||||
@@ -792,7 +792,6 @@ public protocol ExpressibleByStringInterpolation
|
||||
init(stringInterpolation: StringInterpolation)
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
extension ExpressibleByStringInterpolation
|
||||
where StringInterpolation == DefaultStringInterpolation {
|
||||
|
||||
@@ -815,7 +814,6 @@ extension ExpressibleByStringInterpolation
|
||||
self.init(stringLiteral: stringInterpolation.make())
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Represents the contents of a string literal with interpolations while it's
|
||||
/// being built up.
|
||||
|
||||
@@ -1702,9 +1702,15 @@ extension Collection {
|
||||
} else {
|
||||
result += ", "
|
||||
}
|
||||
#if !$Embedded
|
||||
debugPrint(k, terminator: "", to: &result)
|
||||
result += ": "
|
||||
debugPrint(v, terminator: "", to: &result)
|
||||
#else
|
||||
"(cannot print value in embedded Swift)".write(to: &result)
|
||||
result += ": "
|
||||
"(cannot print value in embedded Swift)".write(to: &result)
|
||||
#endif
|
||||
}
|
||||
result += "]"
|
||||
return result
|
||||
|
||||
@@ -33,6 +33,36 @@ public func print(_ string: StaticString, terminator: StaticString = "\n") {
|
||||
}
|
||||
}
|
||||
|
||||
@_disfavoredOverload
|
||||
public func print(_ string: String, terminator: StaticString = "\n") {
|
||||
var string = string
|
||||
_ = string.withUTF8 { buf in
|
||||
for c in buf {
|
||||
putchar(CInt(c))
|
||||
}
|
||||
}
|
||||
var p = terminator.utf8Start
|
||||
while p.pointee != 0 {
|
||||
putchar(CInt(p.pointee))
|
||||
p += 1
|
||||
}
|
||||
}
|
||||
|
||||
@_disfavoredOverload
|
||||
public func print(_ object: some CustomStringConvertible, terminator: StaticString = "\n") {
|
||||
var string = object.description
|
||||
_ = string.withUTF8 { buf in
|
||||
for c in buf {
|
||||
putchar(CInt(c))
|
||||
}
|
||||
}
|
||||
var p = terminator.utf8Start
|
||||
while p.pointee != 0 {
|
||||
putchar(CInt(p.pointee))
|
||||
p += 1
|
||||
}
|
||||
}
|
||||
|
||||
func printCharacters(_ buf: UnsafeRawBufferPointer) {
|
||||
for c in buf {
|
||||
putchar(CInt(c))
|
||||
@@ -44,29 +74,30 @@ func printCharacters(_ buf: UnsafeBufferPointer<UInt8>) {
|
||||
}
|
||||
|
||||
extension BinaryInteger {
|
||||
func writeToStdout() {
|
||||
internal func _toStringImpl(
|
||||
_ buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
_ bufferLength: UInt,
|
||||
_ radix: Int,
|
||||
_ uppercase: Bool
|
||||
) -> Int {
|
||||
if self == (0 as Self) {
|
||||
print("0", terminator: "")
|
||||
return
|
||||
buffer[0] = UInt8(("0" as Unicode.Scalar).value)
|
||||
return 1
|
||||
}
|
||||
|
||||
func _ascii(_ digit: UInt8) -> UInt8 {
|
||||
UInt8(("0" as Unicode.Scalar).value) + digit
|
||||
|
||||
func _ascii(_ digit: UInt8) -> UTF8.CodeUnit {
|
||||
if digit < 10 {
|
||||
UInt8(("0" as Unicode.Scalar).value) + digit
|
||||
} else {
|
||||
UInt8(("a" as Unicode.Scalar).value) + (digit - 10)
|
||||
}
|
||||
}
|
||||
let isNegative = Self.isSigned && self < (0 as Self)
|
||||
var value = magnitude
|
||||
|
||||
// Avoid withUnsafeTemporaryAllocation which is not typed-throws ready yet
|
||||
let byteCount = 64
|
||||
let stackBuffer = Builtin.stackAlloc(byteCount._builtinWordValue,
|
||||
1._builtinWordValue, 1._builtinWordValue)
|
||||
let buffer = UnsafeMutableRawBufferPointer(start: .init(stackBuffer),
|
||||
count: byteCount)
|
||||
|
||||
var index = buffer.count - 1
|
||||
|
||||
var index = Int(bufferLength - 1)
|
||||
while value != 0 {
|
||||
let (quotient, remainder) =
|
||||
value.quotientAndRemainder(dividingBy: Magnitude(10))
|
||||
let (quotient, remainder) = value.quotientAndRemainder(dividingBy: Magnitude(radix))
|
||||
buffer[index] = _ascii(UInt8(truncatingIfNeeded: remainder))
|
||||
index -= 1
|
||||
value = quotient
|
||||
@@ -76,12 +107,27 @@ extension BinaryInteger {
|
||||
index -= 1
|
||||
}
|
||||
let start = index + 1
|
||||
let end = buffer.count - 1
|
||||
let end = Int(bufferLength - 1)
|
||||
let count = end - start + 1
|
||||
|
||||
let intermediate = UnsafeBufferPointer(start: buffer.advanced(by: start), count: count)
|
||||
let destination = UnsafeMutableRawBufferPointer(start: buffer, count: Int(bufferLength))
|
||||
destination.copyMemory(from: UnsafeRawBufferPointer(intermediate))
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
let pointerToPrint = buffer.baseAddress?.advanced(by: start)
|
||||
.assumingMemoryBound(to: UInt8.self)
|
||||
printCharacters(UnsafeBufferPointer(start: pointerToPrint, count: count))
|
||||
func writeToStdout() {
|
||||
// Avoid withUnsafeTemporaryAllocation which is not typed-throws ready yet
|
||||
let byteCount = 64
|
||||
let stackBuffer = Builtin.stackAlloc(byteCount._builtinWordValue,
|
||||
1._builtinWordValue, 1._builtinWordValue)
|
||||
let buffer = UnsafeMutableRawBufferPointer(start: .init(stackBuffer),
|
||||
count: byteCount).baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
let count = _toStringImpl(buffer, 64, 10, false)
|
||||
|
||||
printCharacters(UnsafeBufferPointer(start: buffer, count: count))
|
||||
|
||||
Builtin.stackDealloc(stackBuffer)
|
||||
}
|
||||
|
||||
@@ -48,6 +48,16 @@ public struct HeapObject {
|
||||
|
||||
// Note: The immortalRefCount value of -1 is also hard-coded in IRGen in `irgen::emitConstantObject`.
|
||||
static let immortalRefCount = -1
|
||||
|
||||
#if _pointerBitWidth(_64)
|
||||
static let immortalObjectPointerBit = UInt(0x8000_0000_0000_0000)
|
||||
#endif
|
||||
|
||||
#if _pointerBitWidth(_64)
|
||||
static let bridgeObjectToPlainObjectMask = UInt(0x8fff_ffff_ffff_fff8)
|
||||
#else
|
||||
static let bridgeObjectToPlainObjectMask = UInt(0xffff_ffff)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -162,13 +172,25 @@ func swift_initStackObject(metadata: UnsafeMutablePointer<ClassMetadata>, object
|
||||
|
||||
/// Refcounting
|
||||
|
||||
func isValidPointerForNativeRetain(object: Builtin.RawPointer) -> Bool {
|
||||
let objectBits = UInt(Builtin.ptrtoint_Word(object))
|
||||
if objectBits == 0 { return false }
|
||||
|
||||
#if _pointerBitWidth(_64)
|
||||
if (objectBits & HeapObject.immortalObjectPointerBit) != 0 { return false }
|
||||
#endif
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@_cdecl("swift_setDeallocating")
|
||||
public func swift_setDeallocating(object: Builtin.RawPointer) {
|
||||
}
|
||||
|
||||
@_cdecl("swift_isUniquelyReferenced_native")
|
||||
public func swift_isUniquelyReferenced_native(object: Builtin.RawPointer) -> Bool {
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return false }
|
||||
if !isValidPointerForNativeRetain(object: object) { return false }
|
||||
|
||||
return swift_isUniquelyReferenced_nonNull_native(object: UnsafeMutablePointer<HeapObject>(object))
|
||||
}
|
||||
|
||||
@@ -184,7 +206,8 @@ func swift_isUniquelyReferenced_nonNull_native(object: UnsafeMutablePointer<Heap
|
||||
|
||||
@_cdecl("swift_retain")
|
||||
public func swift_retain(object: Builtin.RawPointer) -> Builtin.RawPointer {
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return object }
|
||||
if !isValidPointerForNativeRetain(object: object) { return object }
|
||||
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
return swift_retain_n_(object: o, n: 1)._rawValue
|
||||
}
|
||||
@@ -192,7 +215,8 @@ public func swift_retain(object: Builtin.RawPointer) -> Builtin.RawPointer {
|
||||
// Cannot use UnsafeMutablePointer<HeapObject>? directly in the function argument or return value as it causes IRGen crashes
|
||||
@_cdecl("swift_retain_n")
|
||||
public func swift_retain_n(object: Builtin.RawPointer, n: UInt32) -> Builtin.RawPointer {
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return object }
|
||||
if !isValidPointerForNativeRetain(object: object) { return object }
|
||||
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
return swift_retain_n_(object: o, n: n)._rawValue
|
||||
}
|
||||
@@ -208,16 +232,30 @@ func swift_retain_n_(object: UnsafeMutablePointer<HeapObject>, n: UInt32) -> Uns
|
||||
return object
|
||||
}
|
||||
|
||||
@_cdecl("swift_bridgeObjectRetain")
|
||||
public func swift_bridgeObjectRetain(object: Builtin.RawPointer) -> Builtin.RawPointer {
|
||||
return swift_bridgeObjectRetain_n(object: object, n: 1)
|
||||
}
|
||||
|
||||
@_cdecl("swift_bridgeObjectRetain_n")
|
||||
public func swift_bridgeObjectRetain_n(object: Builtin.RawPointer, n: UInt32) -> Builtin.RawPointer {
|
||||
let objectBits = UInt(Builtin.ptrtoint_Word(object))
|
||||
let untaggedObject = Builtin.inttoptr_Word((objectBits & HeapObject.bridgeObjectToPlainObjectMask)._builtinWordValue)
|
||||
return swift_retain_n(object: untaggedObject, n: n)
|
||||
}
|
||||
|
||||
@_cdecl("swift_release")
|
||||
public func swift_release(object: Builtin.RawPointer) {
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return }
|
||||
if !isValidPointerForNativeRetain(object: object) { return }
|
||||
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
swift_release_n_(object: o, n: 1)
|
||||
}
|
||||
|
||||
@_cdecl("swift_release_n")
|
||||
public func swift_release_n(object: Builtin.RawPointer, n: UInt32) {
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return }
|
||||
if !isValidPointerForNativeRetain(object: object) { return }
|
||||
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
swift_release_n_(object: o, n: n)
|
||||
}
|
||||
@@ -240,6 +278,18 @@ func swift_release_n_(object: UnsafeMutablePointer<HeapObject>?, n: UInt32) {
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("swift_bridgeObjectRelease")
|
||||
public func swift_bridgeObjectRelease(object: Builtin.RawPointer) {
|
||||
swift_bridgeObjectRelease_n(object: object, n: 1)
|
||||
}
|
||||
|
||||
@_cdecl("swift_bridgeObjectRelease_n")
|
||||
public func swift_bridgeObjectRelease_n(object: Builtin.RawPointer, n: UInt32) {
|
||||
let objectBits = UInt(Builtin.ptrtoint_Word(object))
|
||||
let untaggedObject = Builtin.inttoptr_Word((objectBits & HeapObject.bridgeObjectToPlainObjectMask)._builtinWordValue)
|
||||
swift_release_n(object: untaggedObject, n: n)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Refcount helpers
|
||||
|
||||
@@ -14,169 +14,12 @@ import SwiftShims
|
||||
|
||||
/// String
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public struct String: Hashable {
|
||||
public var utf8CString: ContiguousArray<CChar> { fatalError() }
|
||||
public init() {}
|
||||
public init(validatingCString: UnsafePointer<CChar>) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
public init<Subject>(describing instance: Subject) { fatalError() }
|
||||
public init<Subject>(reflecting instance: Subject) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
public static func + (lhs: String, rhs: String) -> String { fatalError() }
|
||||
public static func += (lhs: inout String, rhs: String) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
public var isContiguousUTF8: Bool { fatalError() }
|
||||
public mutating func makeContiguousUTF8() { fatalError() }
|
||||
public mutating func withUTF8<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R { fatalError() }
|
||||
public var utf8: ContiguousArray<UInt8> { fatalError() }
|
||||
public var utf16: ContiguousArray<UInt16> { fatalError() }
|
||||
public var debugDescription: String { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public func debugPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { fatalError() }
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public func debugPrint<Target: TextOutputStream>(_ items: Any..., separator: String = " ", terminator: String = "\n", to output: inout Target) { fatalError() }
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: TextOutputStream {
|
||||
public mutating func write(_ other: String) { fatalError() }
|
||||
public mutating func _writeASCII(_ buffer: UnsafeBufferPointer<UInt8>) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: _ExpressibleByBuiltinUnicodeScalarLiteral {
|
||||
public init(_builtinUnicodeScalarLiteral value: Builtin.Int32) { fatalError() }
|
||||
public init(_ scalar: UInt32) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: _ExpressibleByBuiltinExtendedGraphemeClusterLiteral {
|
||||
public init(_builtinExtendedGraphemeClusterLiteral start: Builtin.RawPointer, utf8CodeUnitCount: Builtin.Word, isASCII: Builtin.Int1) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: _ExpressibleByBuiltinStringLiteral {
|
||||
public init(_builtinStringLiteral start: Builtin.RawPointer, utf8CodeUnitCount: Builtin.Word, isASCII: Builtin.Int1) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: ExpressibleByStringLiteral {
|
||||
public init(stringLiteral value: String) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public protocol CustomStringConvertible {
|
||||
var description: String { get }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public protocol CustomDebugStringConvertible {
|
||||
var debugDescription: String { get }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable {
|
||||
public typealias StringLiteralType = String
|
||||
|
||||
public init(literalCapacity: Int, interpolationCount: Int) { fatalError() }
|
||||
public mutating func appendLiteral(_ literal: StringLiteralType) { fatalError() }
|
||||
public mutating func appendInterpolation<T>(_: T) { fatalError() }
|
||||
|
||||
internal __consuming func make() -> String { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
@inlinable
|
||||
@_effects(readonly)
|
||||
public init(stringInterpolation: DefaultStringInterpolation) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String: ExpressibleByStringInterpolation { }
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public protocol LosslessStringConvertible: CustomStringConvertible {
|
||||
init?(_ description: String)
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public protocol TextOutputStream {
|
||||
mutating func _lock()
|
||||
mutating func _unlock()
|
||||
mutating func write(_ string: String)
|
||||
mutating func _writeASCII(_ buffer: UnsafeBufferPointer<UInt8>)
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension TextOutputStream {
|
||||
public mutating func _lock() {}
|
||||
public mutating func _unlock() {}
|
||||
public mutating func _writeASCII(_ buffer: UnsafeBufferPointer<UInt8>) {}
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public protocol TextOutputStreamable {
|
||||
func write<Target: TextOutputStream>(to target: inout Target)
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
internal static func _fromUTF8Repairing(_ input: UnsafeBufferPointer<UInt8>) -> (result: String, repairsMade: Bool) { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
internal static func _fromASCII(_ input: UnsafeBufferPointer<UInt8>) -> String { fatalError() }
|
||||
internal static func _uncheckedFromUTF8( _ input: UnsafeBufferPointer<UInt8>) -> String { fatalError() }
|
||||
internal static func _uncheckedFromUTF8(_ input: UnsafeBufferPointer<UInt8>, isASCII: Bool) -> String { fatalError() }
|
||||
internal static func _uncheckedFromUTF8(_ input: UnsafeBufferPointer<UInt8>, asciiPreScanResult: Bool) -> String { fatalError() }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
public init<T: BinaryInteger>(_ value: T, radix: Int = 10, uppercase: Bool = false) { fatalError() }
|
||||
}
|
||||
|
||||
/// Unicode
|
||||
|
||||
public enum Unicode {}
|
||||
|
||||
public typealias UTF8 = Unicode.UTF8
|
||||
public typealias UTF16 = Unicode.UTF16
|
||||
|
||||
extension Unicode {
|
||||
public enum UTF8 {
|
||||
}
|
||||
public enum UTF16 {
|
||||
}
|
||||
}
|
||||
|
||||
extension Unicode.UTF8 {
|
||||
public typealias CodeUnit = UInt8
|
||||
}
|
||||
|
||||
extension Unicode.UTF16 {
|
||||
public typealias CodeUnit = UInt16
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension String {
|
||||
public init(_ value: Unicode.Scalar) { fatalError() }
|
||||
}
|
||||
|
||||
/// Codable
|
||||
|
||||
@_unavailableInEmbedded
|
||||
|
||||
@@ -406,12 +406,6 @@ extension AdditiveArithmetic {
|
||||
}
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
public typealias _CustomStringConvertibleOrNone = CustomStringConvertible
|
||||
#else
|
||||
public typealias _CustomStringConvertibleOrNone = Any
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===--- BinaryInteger ----------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -573,7 +567,7 @@ public typealias _CustomStringConvertibleOrNone = Any
|
||||
/// }
|
||||
/// // Prints "23 is greater than -23."
|
||||
public protocol BinaryInteger :
|
||||
Hashable, Numeric, _CustomStringConvertibleOrNone, Strideable
|
||||
Hashable, Numeric, CustomStringConvertible, Strideable
|
||||
where Magnitude: BinaryInteger, Magnitude.Magnitude == Magnitude
|
||||
{
|
||||
/// A Boolean value indicating whether this type is a signed integer type.
|
||||
@@ -1499,7 +1493,6 @@ extension BinaryInteger {
|
||||
//===--- CustomStringConvertible conformance ------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension BinaryInteger {
|
||||
internal func _description(radix: Int, uppercase: Bool) -> String {
|
||||
_precondition(2...36 ~= radix, "Radix must be between 2 and 36")
|
||||
|
||||
@@ -51,14 +51,12 @@ internal struct _${U}Int128 {
|
||||
internal static var one: Self { Self(high: 0, low: 1) }
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension _${U}Int128: CustomStringConvertible {
|
||||
internal var description: String {
|
||||
String(self, radix: 10)
|
||||
}
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension _${U}Int128: CustomDebugStringConvertible {
|
||||
internal var debugDescription: String {
|
||||
description
|
||||
|
||||
@@ -242,7 +242,6 @@ public func _withUnprotectedUnsafePointer<
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
extension String {
|
||||
/// Calls the given closure with a pointer to the contents of the string,
|
||||
/// represented as a null-terminated sequence of UTF-8 code units.
|
||||
@@ -264,7 +263,6 @@ extension String {
|
||||
return try _guts.withCString(body)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@available(*, deprecated, message: "Use the copy operator")
|
||||
@_alwaysEmitIntoClient
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// This file contains only support for types deprecated from previous versions
|
||||
// of Swift
|
||||
|
||||
#if !$Embedded
|
||||
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "BidirectionalCollection")
|
||||
public typealias BidirectionalIndexable = BidirectionalCollection
|
||||
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "Collection")
|
||||
@@ -142,6 +143,7 @@ public typealias _FileReferenceLiteralConvertible = _ExpressibleByFileReferenceL
|
||||
|
||||
@available(swift, deprecated: 4.2, obsoleted: 5.0, renamed: "ClosedRange.Index")
|
||||
public typealias ClosedRangeIndex<T> = ClosedRange<T>.Index where T: Strideable, T.Stride: SignedInteger
|
||||
#endif
|
||||
|
||||
/// An optional type that allows implicit member access.
|
||||
///
|
||||
@@ -177,9 +179,12 @@ extension ClosedRange where Bound: Strideable, Bound.Stride: SignedInteger {
|
||||
}
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
@available(swift, deprecated: 5.0, renamed: "KeyValuePairs")
|
||||
public typealias DictionaryLiteral<Key, Value> = KeyValuePairs<Key, Value>
|
||||
#endif
|
||||
|
||||
#if !$Embedded
|
||||
extension LazySequenceProtocol {
|
||||
/// Returns the non-`nil` results of mapping the given transformation over
|
||||
/// this sequence.
|
||||
@@ -202,6 +207,7 @@ extension LazySequenceProtocol {
|
||||
return self.compactMap(transform)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension String {
|
||||
/// A view of a string's contents as a collection of characters.
|
||||
|
||||
@@ -434,7 +434,11 @@ extension Optional: CustomDebugStringConvertible {
|
||||
case .some(let value):
|
||||
#if !SWIFT_STDLIB_STATIC_PRINT
|
||||
var result = "Optional("
|
||||
#if !$Embedded
|
||||
debugPrint(value, terminator: "", to: &result)
|
||||
#else
|
||||
"(cannot print value in embedded Swift)".write(to: &result)
|
||||
#endif
|
||||
result += ")"
|
||||
return result
|
||||
#else
|
||||
|
||||
@@ -401,6 +401,7 @@ internal func _adHocPrint_unlocked<T, TargetStream: TextOutputStream>(
|
||||
|
||||
@usableFromInline
|
||||
@_semantics("optimize.sil.specialize.generic.never")
|
||||
@_unavailableInEmbedded
|
||||
internal func _print_unlocked<T, TargetStream: TextOutputStream>(
|
||||
_ value: T, _ target: inout TargetStream
|
||||
) {
|
||||
@@ -451,6 +452,7 @@ internal func _print_unlocked<T, TargetStream: TextOutputStream>(
|
||||
|
||||
@_semantics("optimize.sil.specialize.generic.never")
|
||||
@inline(never)
|
||||
@_unavailableInEmbedded
|
||||
public func _debugPrint_unlocked<T, TargetStream: TextOutputStream>(
|
||||
_ value: T, _ target: inout TargetStream
|
||||
) {
|
||||
|
||||
@@ -1039,7 +1039,6 @@ extension PartialRangeThrough: Sendable where Bound: Sendable { }
|
||||
extension PartialRangeFrom: Sendable where Bound: Sendable { }
|
||||
extension PartialRangeFrom.Iterator: Sendable where Bound: Sendable { }
|
||||
|
||||
#if !$Embedded
|
||||
extension Range where Bound == String.Index {
|
||||
@_alwaysEmitIntoClient // Swift 5.7
|
||||
internal var _encodedOffsetRange: Range<Int> {
|
||||
@@ -1050,4 +1049,3 @@ extension Range where Bound == String.Index {
|
||||
_uncheckedBounds: (lowerBound._encodedOffset, upperBound._encodedOffset))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -176,7 +176,6 @@ func _stdlib_atomicLoadARCRef(
|
||||
@_transparent
|
||||
@_alwaysEmitIntoClient
|
||||
@discardableResult
|
||||
@_unavailableInEmbedded
|
||||
public func _stdlib_atomicAcquiringInitializeARCRef<T: AnyObject>(
|
||||
object target: UnsafeMutablePointer<T?>,
|
||||
desired: __owned T
|
||||
@@ -203,7 +202,6 @@ public func _stdlib_atomicAcquiringInitializeARCRef<T: AnyObject>(
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@_unavailableInEmbedded
|
||||
public func _stdlib_atomicAcquiringLoadARCRef<T: AnyObject>(
|
||||
object target: UnsafeMutablePointer<T?>
|
||||
) -> Unmanaged<T>? {
|
||||
@@ -370,7 +368,6 @@ internal func _float16ToStringImpl(
|
||||
) -> Int
|
||||
|
||||
@available(SwiftStdlib 5.3, *)
|
||||
@_unavailableInEmbedded
|
||||
internal func _float16ToString(
|
||||
_ value: Float16,
|
||||
debug: Bool
|
||||
@@ -396,7 +393,6 @@ internal func _float32ToStringImpl(
|
||||
_ debug: Bool
|
||||
) -> UInt64
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal func _float32ToString(
|
||||
_ value: Float32,
|
||||
debug: Bool
|
||||
@@ -421,7 +417,6 @@ internal func _float64ToStringImpl(
|
||||
_ debug: Bool
|
||||
) -> UInt64
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal func _float64ToString(
|
||||
_ value: Float64,
|
||||
debug: Bool
|
||||
@@ -449,7 +444,6 @@ internal func _float80ToStringImpl(
|
||||
_ debug: Bool
|
||||
) -> UInt64
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal func _float80ToString(
|
||||
_ value: Float80,
|
||||
debug: Bool
|
||||
@@ -463,6 +457,7 @@ internal func _float80ToString(
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !$Embedded
|
||||
// Returns a UInt64, but that value is the length of the string, so it's
|
||||
// guaranteed to fit into an Int. This is part of the ABI, so we can't
|
||||
// trivially change it to Int. Callers can safely convert the result
|
||||
@@ -475,8 +470,18 @@ internal func _int64ToStringImpl(
|
||||
_ radix: Int64,
|
||||
_ uppercase: Bool
|
||||
) -> UInt64
|
||||
#else
|
||||
internal func _int64ToStringImpl(
|
||||
_ buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
_ bufferLength: UInt,
|
||||
_ value: Int64,
|
||||
_ radix: Int64,
|
||||
_ uppercase: Bool
|
||||
) -> UInt64 {
|
||||
return UInt64(value._toStringImpl(buffer, bufferLength, Int(radix), uppercase))
|
||||
}
|
||||
#endif
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal func _int64ToString(
|
||||
_ value: Int64,
|
||||
radix: Int64 = 10,
|
||||
@@ -501,6 +506,7 @@ internal func _int64ToString(
|
||||
}
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
// Returns a UInt64, but that value is the length of the string, so it's
|
||||
// guaranteed to fit into an Int. This is part of the ABI, so we can't
|
||||
// trivially change it to Int. Callers can safely convert the result
|
||||
@@ -513,8 +519,18 @@ internal func _uint64ToStringImpl(
|
||||
_ radix: Int64,
|
||||
_ uppercase: Bool
|
||||
) -> UInt64
|
||||
#else
|
||||
internal func _uint64ToStringImpl(
|
||||
_ buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
|
||||
_ bufferLength: UInt,
|
||||
_ value: UInt64,
|
||||
_ radix: Int64,
|
||||
_ uppercase: Bool
|
||||
) -> UInt64 {
|
||||
return UInt64(value._toStringImpl(buffer, bufferLength, Int(radix), uppercase))
|
||||
}
|
||||
#endif
|
||||
|
||||
@_unavailableInEmbedded
|
||||
public // @testable
|
||||
func _uint64ToString(
|
||||
_ value: UInt64,
|
||||
@@ -541,7 +557,6 @@ func _uint64ToString(
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_unavailableInEmbedded
|
||||
internal func _rawPointerToString(_ value: Builtin.RawPointer) -> String {
|
||||
var result = _uint64ToString(
|
||||
UInt64(
|
||||
|
||||
@@ -476,6 +476,7 @@ extension String {
|
||||
return
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
// Fast path for untyped raw storage and known stdlib types
|
||||
if let contigBytes = codeUnits as? _HasContiguousBytes,
|
||||
contigBytes._providesContiguousBytesNoCopy
|
||||
@@ -489,6 +490,7 @@ extension String {
|
||||
}
|
||||
return
|
||||
}
|
||||
#endif
|
||||
|
||||
self = String._fromNonContiguousUnsafeBitcastUTF8Repairing(codeUnits).0
|
||||
}
|
||||
|
||||
@@ -566,6 +566,7 @@ private func getConstantTaggedCocoaContents(_ cocoaString: _CocoaString) ->
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
@usableFromInline
|
||||
@_effects(releasenone) // @opaque
|
||||
internal func _bridgeCocoaString(_ cocoaString: _CocoaString) -> _StringGuts {
|
||||
@@ -639,6 +640,7 @@ extension String {
|
||||
self._guts = _bridgeCocoaString(_cocoaString)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@_effects(releasenone)
|
||||
private func _createNSString(
|
||||
@@ -664,6 +666,7 @@ private func _createCFString(
|
||||
)
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
extension String {
|
||||
@_effects(releasenone)
|
||||
public // SPI(Foundation)
|
||||
@@ -766,6 +769,7 @@ internal func _NSStringFromUTF8(_ s: UnsafePointer<UInt8>, _ len: Int)
|
||||
as: UTF8.self
|
||||
)._bridgeToObjectiveCImpl()
|
||||
}
|
||||
#endif
|
||||
|
||||
#else // !_runtime(_ObjC)
|
||||
|
||||
|
||||
@@ -257,6 +257,7 @@ extension String {
|
||||
return (result, repairsMade: false)
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
// Fast path for untyped raw storage and known stdlib types
|
||||
if let contigBytes = input as? _HasContiguousBytes,
|
||||
contigBytes._providesContiguousBytesNoCopy {
|
||||
@@ -267,6 +268,7 @@ extension String {
|
||||
return String._fromASCIIValidating(buffer)
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
// Fast path for user-defined Collections
|
||||
if let strOpt = input.withContiguousStorageIfAvailable({
|
||||
|
||||
@@ -64,6 +64,7 @@ extension _StringGuts {
|
||||
self.init(_StringObject(storage))
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
internal init(
|
||||
cocoa: AnyObject, providesFastUTF8: Bool, isASCII: Bool, length: Int
|
||||
) {
|
||||
@@ -73,6 +74,7 @@ extension _StringGuts {
|
||||
isASCII: isASCII,
|
||||
length: length))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Queries
|
||||
|
||||
@@ -176,10 +176,15 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
|
||||
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
|
||||
@inlinable
|
||||
public mutating func appendInterpolation<T>(_ value: T) {
|
||||
#if !$Embedded
|
||||
_print_unlocked(value, &self)
|
||||
#else
|
||||
"(cannot print value in embedded Swift)".write(to: &self)
|
||||
#endif
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_unavailableInEmbedded
|
||||
public mutating func appendInterpolation(_ value: Any.Type) {
|
||||
_typeName(value, qualified: false).write(to: &self)
|
||||
}
|
||||
|
||||
@@ -82,6 +82,10 @@ internal struct _StringObject {
|
||||
internal init(zero: ()) { self._storage = 0 }
|
||||
}
|
||||
|
||||
#if $Embedded
|
||||
public typealias AnyObject = Builtin.NativeObject
|
||||
#endif
|
||||
|
||||
#if _pointerBitWidth(_64)
|
||||
|
||||
//
|
||||
@@ -102,7 +106,7 @@ internal struct _StringObject {
|
||||
}
|
||||
|
||||
#elseif _pointerBitWidth(_32)
|
||||
|
||||
|
||||
@usableFromInline @frozen
|
||||
internal enum Variant {
|
||||
case immortal(UInt)
|
||||
@@ -976,7 +980,11 @@ extension _StringObject {
|
||||
guard case .native(let storage) = _variant else {
|
||||
_internalInvariantFailure()
|
||||
}
|
||||
#if !$Embedded
|
||||
return _unsafeUncheckedDowncast(storage, to: __StringStorage.self)
|
||||
#else
|
||||
return Builtin.castFromNativeObject(storage)
|
||||
#endif
|
||||
#else
|
||||
#error("Unknown platform")
|
||||
#endif
|
||||
@@ -1011,7 +1019,11 @@ extension _StringObject {
|
||||
guard case .native(let storage) = _variant else {
|
||||
_internalInvariantFailure()
|
||||
}
|
||||
#if !$Embedded
|
||||
return _unsafeUncheckedDowncast(storage, to: __SharedStringStorage.self)
|
||||
#else
|
||||
return Builtin.castFromNativeObject(storage)
|
||||
#endif
|
||||
#else
|
||||
#error("Unknown platform")
|
||||
#endif
|
||||
@@ -1035,8 +1047,11 @@ extension _StringObject {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@_unavailableInEmbedded
|
||||
internal var cocoaObject: AnyObject {
|
||||
#if _pointerBitWidth(_64)
|
||||
#if $Embedded
|
||||
fatalError("unreachable in embedded Swift")
|
||||
#elseif _pointerBitWidth(_64)
|
||||
_internalInvariant(largeIsCocoa && !isImmortal)
|
||||
let unmanaged = Unmanaged<AnyObject>.fromOpaque(largeAddress)
|
||||
return unmanaged.takeUnretainedValue()
|
||||
@@ -1053,10 +1068,13 @@ extension _StringObject {
|
||||
/// Call `body` with the bridged Cocoa object in `self`, without retaining
|
||||
/// it.
|
||||
@inline(__always)
|
||||
@_unavailableInEmbedded
|
||||
internal func withCocoaObject<R>(
|
||||
_ body: (AnyObject) -> R
|
||||
) -> R {
|
||||
#if _pointerBitWidth(_64)
|
||||
#if $Embedded
|
||||
fatalError("unreachable in embedded Swift")
|
||||
#elseif _pointerBitWidth(_64)
|
||||
_internalInvariant(largeIsCocoa && !isImmortal)
|
||||
let unmanaged = Unmanaged<AnyObject>.fromOpaque(largeAddress)
|
||||
return unmanaged._withUnsafeGuaranteedRef { body($0) }
|
||||
@@ -1071,10 +1089,15 @@ extension _StringObject {
|
||||
@_alwaysEmitIntoClient
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
@_unavailableInEmbedded
|
||||
internal var owner: AnyObject? {
|
||||
guard self.isMortal else { return nil }
|
||||
#if !$Embedded
|
||||
let unmanaged = Unmanaged<AnyObject>.fromOpaque(largeAddress)
|
||||
return unmanaged.takeUnretainedValue()
|
||||
#else
|
||||
fatalError("unreachable in embedded Swift")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1151,10 +1174,15 @@ extension _StringObject {
|
||||
|
||||
// Fetch the stored subclass of NSString for bridging
|
||||
@inline(__always)
|
||||
@_unavailableInEmbedded
|
||||
internal var objCBridgeableObject: AnyObject {
|
||||
#if $Embedded
|
||||
fatalError("unreachable in embedded Swift")
|
||||
#else
|
||||
_internalInvariant(hasObjCBridgeableObject)
|
||||
let unmanaged = Unmanaged<AnyObject>.fromOpaque(largeAddress)
|
||||
return unmanaged.takeUnretainedValue()
|
||||
#endif
|
||||
}
|
||||
|
||||
// Whether the object provides fast UTF-8 contents that are nul-terminated
|
||||
@@ -1201,14 +1229,19 @@ extension _StringObject {
|
||||
|
||||
@inline(__always)
|
||||
internal init(_ storage: __StringStorage) {
|
||||
#if $Embedded
|
||||
let castStorage = Builtin.unsafeCastToNativeObject(storage)
|
||||
#else
|
||||
let castStorage = storage
|
||||
#endif
|
||||
#if _pointerBitWidth(_64)
|
||||
self.init(
|
||||
object: storage,
|
||||
object: castStorage,
|
||||
discriminator: Nibbles.largeMortal(),
|
||||
countAndFlags: storage._countAndFlags)
|
||||
#elseif _pointerBitWidth(_32)
|
||||
self.init(
|
||||
variant: .native(storage),
|
||||
variant: .native(castStorage),
|
||||
discriminator: Nibbles.largeMortal(),
|
||||
countAndFlags: storage._countAndFlags)
|
||||
#else
|
||||
@@ -1217,14 +1250,19 @@ extension _StringObject {
|
||||
}
|
||||
|
||||
internal init(_ storage: __SharedStringStorage) {
|
||||
#if $Embedded
|
||||
let castStorage = Builtin.unsafeCastToNativeObject(storage)
|
||||
#else
|
||||
let castStorage = storage
|
||||
#endif
|
||||
#if _pointerBitWidth(_64)
|
||||
self.init(
|
||||
object: storage,
|
||||
object: castStorage,
|
||||
discriminator: Nibbles.largeMortal(),
|
||||
countAndFlags: storage._countAndFlags)
|
||||
#elseif _pointerBitWidth(_32)
|
||||
self.init(
|
||||
variant: .native(storage),
|
||||
variant: .native(castStorage),
|
||||
discriminator: Nibbles.largeMortal(),
|
||||
countAndFlags: storage._countAndFlags)
|
||||
#else
|
||||
@@ -1232,12 +1270,15 @@ extension _StringObject {
|
||||
#endif
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal init(
|
||||
cocoa: AnyObject, providesFastUTF8: Bool, isASCII: Bool, length: Int
|
||||
) {
|
||||
let countAndFlags = CountAndFlags(sharedCount: length, isASCII: isASCII)
|
||||
let discriminator = Nibbles.largeCocoa(providesFastUTF8: providesFastUTF8)
|
||||
#if _pointerBitWidth(_64)
|
||||
#if $Embedded
|
||||
fatalError("unreachable in embedded Swift")
|
||||
#elseif _pointerBitWidth(_64)
|
||||
self.init(
|
||||
object: cocoa, discriminator: discriminator, countAndFlags: countAndFlags)
|
||||
_internalInvariant(self.largeAddressBits == Builtin.reinterpretCast(cocoa))
|
||||
@@ -1327,9 +1368,11 @@ extension _StringObject {
|
||||
}
|
||||
}
|
||||
if _countAndFlags.isNativelyStored {
|
||||
#if !$Embedded
|
||||
let unmanaged = Unmanaged<AnyObject>.fromOpaque(largeAddress)
|
||||
let anyObj = unmanaged.takeUnretainedValue()
|
||||
_internalInvariant(anyObj is __StringStorage)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,9 @@ fileprivate func _allocate<T: AnyObject>(
|
||||
growthFactor: Float? = nil, // Exponential growth factor for large allocs
|
||||
tailAllocator: (_ numTailBytes: Int) -> T // Do the actual tail allocation
|
||||
) -> (T, realNumTailBytes: Int) {
|
||||
#if !$Embedded
|
||||
_internalInvariant(getSwiftClassInstanceExtents(T.self).1 == numHeaderBytes)
|
||||
#endif
|
||||
|
||||
func roundUp(_ x: Int) -> Int { (x + 15) & ~15 }
|
||||
|
||||
@@ -206,8 +208,14 @@ fileprivate func _allocate<T: AnyObject>(
|
||||
let totalTailBytes = total - numHeaderBytes
|
||||
|
||||
let object = tailAllocator(totalTailBytes)
|
||||
if let allocSize = _mallocSize(ofAllocation:
|
||||
UnsafeRawPointer(Builtin.bridgeToRawPointer(object))) {
|
||||
|
||||
let allocSize: Int?
|
||||
#if !$Embedded
|
||||
allocSize = _mallocSize(ofAllocation: UnsafeRawPointer(Builtin.bridgeToRawPointer(object)))
|
||||
#else
|
||||
allocSize = nil
|
||||
#endif
|
||||
if let allocSize {
|
||||
_internalInvariant(allocSize % MemoryLayout<Int>.stride == 0)
|
||||
|
||||
let realNumTailBytes = allocSize - numHeaderBytes
|
||||
|
||||
@@ -18,6 +18,10 @@ struct _StringRepresentation {
|
||||
public var _count: Int
|
||||
public var _capacity: Int
|
||||
|
||||
#if $Embedded
|
||||
public typealias AnyObject = Builtin.NativeObject
|
||||
#endif
|
||||
|
||||
public enum _Form {
|
||||
case _small
|
||||
case _cocoa(object: AnyObject)
|
||||
@@ -29,8 +33,18 @@ struct _StringRepresentation {
|
||||
|
||||
public var _objectIdentifier: ObjectIdentifier? {
|
||||
switch _form {
|
||||
case ._cocoa(let object): return ObjectIdentifier(object)
|
||||
case ._native(let object): return ObjectIdentifier(object)
|
||||
case ._cocoa(let object):
|
||||
#if !$Embedded
|
||||
return ObjectIdentifier(object)
|
||||
#else
|
||||
return ObjectIdentifier(_nativeObject(toNative: object))
|
||||
#endif
|
||||
case ._native(let object):
|
||||
#if !$Embedded
|
||||
return ObjectIdentifier(object)
|
||||
#else
|
||||
return ObjectIdentifier(_nativeObject(toNative: object))
|
||||
#endif
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
@@ -46,6 +60,7 @@ extension String {
|
||||
public // @testable
|
||||
func _classify() -> _StringRepresentation { return _guts._classify() }
|
||||
|
||||
#if !$Embedded
|
||||
@_alwaysEmitIntoClient
|
||||
public // @testable
|
||||
func _deconstructUTF8<ToPointer: _Pointer>(
|
||||
@@ -59,6 +74,7 @@ extension String {
|
||||
) {
|
||||
_guts._deconstructUTF8(scratch: scratch)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extension _StringGuts {
|
||||
@@ -73,10 +89,12 @@ extension _StringGuts {
|
||||
result._capacity = _SmallString.capacity
|
||||
return result
|
||||
}
|
||||
#if !$Embedded
|
||||
if _object.largeIsCocoa {
|
||||
result._form = ._cocoa(object: _object.cocoaObject)
|
||||
return result
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: shared native
|
||||
_internalInvariant(_object.providesFastUTF8)
|
||||
@@ -87,12 +105,17 @@ extension _StringGuts {
|
||||
}
|
||||
if _object.hasNativeStorage {
|
||||
_internalInvariant(_object.largeFastIsTailAllocated)
|
||||
#if !$Embedded
|
||||
result._form = ._native(object: _object.nativeStorage)
|
||||
#else
|
||||
result._form = ._native(object: Builtin.unsafeCastToNativeObject(_object.nativeStorage))
|
||||
#endif
|
||||
return result
|
||||
}
|
||||
fatalError()
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
|
||||
/*
|
||||
|
||||
@@ -180,4 +203,7 @@ extension _StringGuts {
|
||||
// Array's owner cannot be nil, even though it is declared optional...
|
||||
return (owner: owner!, ptr, length: utf8.count - 1)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ internal func validateUTF8(_ buf: UnsafeBufferPointer<UInt8>) -> UTF8ValidationR
|
||||
var iter = buf.makeIterator()
|
||||
var lastValidIndex = buf.startIndex
|
||||
|
||||
@inline(__always) func guaranteeIn(_ f: (UInt8) -> Bool) throws {
|
||||
@inline(__always) func guaranteeIn(_ f: (UInt8) -> Bool) throws(UTF8ValidationError) {
|
||||
guard let cu = iter.next() else { throw UTF8ValidationError() }
|
||||
guard f(cu) else { throw UTF8ValidationError() }
|
||||
}
|
||||
@inline(__always) func guaranteeContinuation() throws {
|
||||
@inline(__always) func guaranteeContinuation() throws(UTF8ValidationError) {
|
||||
try guaranteeIn(UTF8.isContinuation)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ internal func validateUTF8(_ buf: UnsafeBufferPointer<UInt8>) -> UTF8ValidationR
|
||||
if UTF8.isASCII(cu) { lastValidIndex &+= 1; continue }
|
||||
isASCII = false
|
||||
if _slowPath(!_isUTF8MultiByteLeading(cu)) {
|
||||
throw UTF8ValidationError()
|
||||
func fail() throws(UTF8ValidationError) { throw UTF8ValidationError() }
|
||||
try fail()
|
||||
}
|
||||
switch cu {
|
||||
case 0xC2...0xDF:
|
||||
|
||||
@@ -191,12 +191,10 @@ extension Unicode.Scalar :
|
||||
/// - Parameter forceASCII: Pass `true` if you need the result to use only
|
||||
/// ASCII characters; otherwise, pass `false`.
|
||||
/// - Returns: A string representation of the scalar.
|
||||
@_unavailableInEmbedded
|
||||
public func escaped(asASCII forceASCII: Bool) -> String {
|
||||
_escaped(asASCII: forceASCII) ?? String(self)
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
internal func _escaped(asASCII forceASCII: Bool) -> String? {
|
||||
func lowNibbleAsHex(_ v: UInt32) -> String {
|
||||
let nibble = v & 15
|
||||
@@ -280,7 +278,6 @@ extension Unicode.Scalar :
|
||||
}
|
||||
}
|
||||
|
||||
@_unavailableInEmbedded
|
||||
extension Unicode.Scalar: CustomStringConvertible, CustomDebugStringConvertible {
|
||||
/// A textual representation of the Unicode scalar.
|
||||
@inlinable
|
||||
@@ -295,7 +292,6 @@ extension Unicode.Scalar: CustomStringConvertible, CustomDebugStringConvertible
|
||||
}
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
extension Unicode.Scalar: LosslessStringConvertible {
|
||||
@inlinable
|
||||
public init?(_ description: String) {
|
||||
@@ -306,7 +302,6 @@ extension Unicode.Scalar: LosslessStringConvertible {
|
||||
self = v
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension Unicode.Scalar: Hashable {
|
||||
/// Hashes the essential components of this value by feeding them into the
|
||||
@@ -412,8 +407,6 @@ extension Unicode.Scalar {
|
||||
}
|
||||
}
|
||||
|
||||
#if !$Embedded
|
||||
|
||||
extension Unicode.Scalar.UTF16View: RandomAccessCollection {
|
||||
|
||||
public typealias Indices = Range<Int>
|
||||
@@ -550,5 +543,3 @@ extension Unicode.Scalar {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1115,7 +1115,7 @@ extension Unicode {
|
||||
case 27: self = .surrogate
|
||||
case 28: self = .privateUse
|
||||
case 29: self = .unassigned
|
||||
default: fatalError("Unknown general category \(rawValue)")
|
||||
default: fatalError("Unknown general category")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1485,7 +1485,7 @@ extension Unicode {
|
||||
case 2:
|
||||
self = .decimal
|
||||
default:
|
||||
fatalError("Unknown numeric type \(rawValue)")
|
||||
fatalError("Unknown numeric type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
// DEP: _fprintf
|
||||
// DEP: _free
|
||||
// DEP: _malloc
|
||||
// DEP: _memmove
|
||||
// DEP: _memset
|
||||
// DEP: _memset_s
|
||||
// DEP: _nanosleep
|
||||
// DEP: _posix_memalign
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
// DEP: ___stack_chk_fail
|
||||
// DEP: ___stack_chk_guard
|
||||
// DEP: _memmove
|
||||
// DEP: _memset
|
||||
// DEP: _putchar
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// DEP: ___stack_chk_guard
|
||||
// DEP: ___divti3
|
||||
// DEP: ___modti3
|
||||
// DEP: _memmove
|
||||
// DEP: _memset
|
||||
// DEP: _putchar
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// DEP: ___stack_chk_guard
|
||||
// DEP: _arc4random_buf
|
||||
// DEP: _free
|
||||
// DEP: _memmove
|
||||
// DEP: _memset
|
||||
// DEP: _putchar
|
||||
// DEP: _posix_memalign
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// DEP: ___stack_chk_fail
|
||||
// DEP: ___stack_chk_guard
|
||||
// DEP: _free
|
||||
// DEP: _memmove
|
||||
// DEP: _memset
|
||||
// DEP: _putchar
|
||||
// DEP: _posix_memalign
|
||||
|
||||
17
test/embedded/stdlib-strings-append.swift
Normal file
17
test/embedded/stdlib-strings-append.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
var str = "hello "
|
||||
for _ in 0 ..< 4 { str = str + str }
|
||||
print(str)
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello
|
||||
25
test/embedded/stdlib-strings-datatables.swift
Normal file
25
test/embedded/stdlib-strings-datatables.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
// Test String operations that require unicode data tables. This is not an executable test yet, because the data tables
|
||||
// are not available for linking yet.
|
||||
|
||||
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature Embedded
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
public func test1() {
|
||||
let string = "string"
|
||||
let other = "other"
|
||||
let appended = string + other
|
||||
_ = appended
|
||||
|
||||
let _ = "aa" == "bb"
|
||||
let dict: [String:Int] = [:]
|
||||
_ = dict
|
||||
|
||||
let _ = "aaa".uppercased()
|
||||
|
||||
let space: Character = " "
|
||||
let split = appended.split(separator: space)
|
||||
_ = split
|
||||
}
|
||||
34
test/embedded/stdlib-strings-interpolation.swift
Normal file
34
test/embedded/stdlib-strings-interpolation.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
// RUN: %target-run-simple-swift(-Osize -swift-version 5 -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
let n = 42
|
||||
let m = -42
|
||||
let s = "str"
|
||||
let str = "Hello \(s) \(n) \(s) \(m)"
|
||||
print(str)
|
||||
|
||||
print("hex: \(hex: 42)")
|
||||
print("ptr: \(UnsafeRawPointer(bitPattern: UInt(0xffff0000))!)")
|
||||
}
|
||||
}
|
||||
|
||||
extension DefaultStringInterpolation {
|
||||
mutating func appendInterpolation(hex value: Int) {
|
||||
appendInterpolation("0x" + String(value, radix: 16))
|
||||
}
|
||||
|
||||
mutating func appendInterpolation(_ value: UnsafeRawPointer) {
|
||||
appendInterpolation("0x" + String(UInt(bitPattern: value), radix: 16))
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: Hello str 42 str -42
|
||||
// CHECK: hex: 0x2a
|
||||
// CHECK: ptr: 0xffff0000
|
||||
36
test/embedded/stdlib-strings-interpolation2.swift
Normal file
36
test/embedded/stdlib-strings-interpolation2.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
// RUN: %target-run-simple-swift(-swift-version 5 -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
struct Event {
|
||||
var id: String
|
||||
var n: Int
|
||||
}
|
||||
|
||||
extension Event: CustomStringConvertible {
|
||||
var description: String {
|
||||
return "id: \(id), n: \(n)"
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
var events: [Event] = []
|
||||
for i in 0 ..< 5 {
|
||||
events.append(Event(id: "event\(i)", n: i))
|
||||
}
|
||||
for event in events {
|
||||
print(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: id: event0, n: 0
|
||||
// CHECK: id: event1, n: 1
|
||||
// CHECK: id: event2, n: 2
|
||||
// CHECK: id: event3, n: 3
|
||||
// CHECK: id: event4, n: 4
|
||||
31
test/embedded/stdlib-strings-interpolation3.swift
Normal file
31
test/embedded/stdlib-strings-interpolation3.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded
|
||||
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded -O
|
||||
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded -Osize
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
// REQUIRES: CODEGENERATOR=ARM
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
let n = 42
|
||||
let m = -42
|
||||
let s = "str"
|
||||
let str = "Hello \(s) \(n) \(s) \(m)"
|
||||
print(str)
|
||||
|
||||
print("hex: \(hex: 42)")
|
||||
print("ptr: \(UnsafeRawPointer(bitPattern: UInt(0xffff0000))!)")
|
||||
}
|
||||
}
|
||||
|
||||
extension DefaultStringInterpolation {
|
||||
mutating func appendInterpolation(hex value: Int) {
|
||||
appendInterpolation("0x" + String(value, radix: 16))
|
||||
}
|
||||
|
||||
mutating func appendInterpolation(_ value: UnsafeRawPointer) {
|
||||
appendInterpolation("0x" + String(UInt(bitPattern: value), radix: 16))
|
||||
}
|
||||
}
|
||||
16
test/embedded/stdlib-strings-osize.swift
Normal file
16
test/embedded/stdlib-strings-osize.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %target-run-simple-swift(-Osize -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
let str = "Hello Hello This Is A Long String"
|
||||
print(str)
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: Hello Hello This Is A Long String
|
||||
16
test/embedded/stdlib-strings-print.swift
Normal file
16
test/embedded/stdlib-strings-print.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: OS=macosx || OS=linux-gnu
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
let str = "Hello Hello This Is A Long String"
|
||||
print(str)
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: Hello Hello This Is A Long String
|
||||
Reference in New Issue
Block a user