Skip to content

[embedded] Port Swift.String to embedded Swift #70446

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 4 commits into from
May 26, 2024
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
13 changes: 8 additions & 5 deletions stdlib/public/core/ArrayShared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
let bufferObject = Builtin.allocWithTailElems_1(
getContiguousArrayStorageType(for: Element.self), builtinCount, Element.self)
#else
storageType = _ContiguousArrayStorage<Element>.self
#endif
let bufferObject = Builtin.allocWithTailElems_1(
storageType, builtinCount, Element.self)
_ContiguousArrayStorage<Element>.self, builtinCount, Element.self)
#endif

let (array, ptr) = Array<Element>._adoptStorage(bufferObject, count: count)
return (array, ptr._rawValue)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions stdlib/public/core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
Expand All @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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));
Expand Down
123 changes: 62 additions & 61 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ###
Expand All @@ -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"
Expand Down Expand Up @@ -422,6 +422,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}")
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/core/CompilerProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ public protocol ExpressibleByStringInterpolation
init(stringInterpolation: StringInterpolation)
}

#if !$Embedded
extension ExpressibleByStringInterpolation
where StringInterpolation == DefaultStringInterpolation {

Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/core/Dictionary.swift
Original file line number Diff line number Diff line change
Expand 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
Expand Down
Loading