mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into next
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
|
||||
add_subdirectory(SwiftPrivate)
|
||||
endif()
|
||||
|
||||
if(SWIFT_BUILD_SDK_OVERLAY)
|
||||
# SwiftPrivateThreadExtras makes use of Darwin/Glibc, which is part of the
|
||||
# SDK overlay. It can't be built separately from the SDK overlay.
|
||||
@@ -11,6 +7,7 @@ if(SWIFT_BUILD_SDK_OVERLAY)
|
||||
endif()
|
||||
|
||||
if(SWIFT_BUILD_SDK_OVERLAY OR SWIFT_BUILD_TEST_SUPPORT_MODULES)
|
||||
add_subdirectory(SwiftPrivate)
|
||||
add_subdirectory(RuntimeUnittest)
|
||||
add_subdirectory(StdlibUnicodeUnittest)
|
||||
add_subdirectory(StdlibCollectionUnittest)
|
||||
|
||||
@@ -15,6 +15,16 @@ add_swift_target_library(swiftSwiftPrivate ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
|
||||
GYB_SOURCES
|
||||
AtomicInt.swift.gyb
|
||||
|
||||
SWIFT_MODULE_DEPENDS_OSX Darwin
|
||||
SWIFT_MODULE_DEPENDS_IOS Darwin
|
||||
SWIFT_MODULE_DEPENDS_TVOS Darwin
|
||||
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
|
||||
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
|
||||
SWIFT_MODULE_DEPENDS_LINUX Glibc
|
||||
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
|
||||
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
|
||||
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
|
||||
SWIFT_MODULE_DEPENDS_HAIKU Glibc
|
||||
SWIFT_MODULE_DEPENDS_WINDOWS CRT WinSDK
|
||||
SWIFT_COMPILE_FLAGS ${swift_swiftprivate_compile_flags} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
|
||||
INSTALL_IN_COMPONENT stdlib-experimental
|
||||
|
||||
@@ -13,7 +13,13 @@
|
||||
import Swift
|
||||
import SwiftShims
|
||||
|
||||
#if os(Windows)
|
||||
#if canImport(Darwin)
|
||||
import Darwin
|
||||
let (platform_read, platform_write, platform_close) = (read, write, close)
|
||||
#elseif canImport(Glibc)
|
||||
import Glibc
|
||||
let (platform_read, platform_write, platform_close) = (read, write, close)
|
||||
#elseif os(Windows)
|
||||
import CRT
|
||||
import WinSDK
|
||||
#endif
|
||||
@@ -119,11 +125,11 @@ public struct _FDInputStream {
|
||||
}
|
||||
}
|
||||
let fd = self.fd
|
||||
let readResult: __swift_ssize_t = _buffer.withUnsafeMutableBufferPointer {
|
||||
let readResult: Int = _buffer.withUnsafeMutableBufferPointer {
|
||||
(_buffer) in
|
||||
let addr = _buffer.baseAddress! + self._bufferUsed
|
||||
let size = bufferFree
|
||||
return _swift_stdlib_read(fd, addr, size)
|
||||
return platform_read(fd, addr, size)
|
||||
}
|
||||
if readResult == 0 {
|
||||
isEOF = true
|
||||
@@ -139,7 +145,7 @@ public struct _FDInputStream {
|
||||
if isClosed {
|
||||
return
|
||||
}
|
||||
let result = _swift_stdlib_close(fd)
|
||||
let result = platform_close(fd)
|
||||
if result < 0 {
|
||||
fatalError("close() returned an error")
|
||||
}
|
||||
@@ -207,7 +213,7 @@ public struct _FDOutputStream : TextOutputStream {
|
||||
var writtenBytes = 0
|
||||
let bufferSize = utf8CStr.count - 1
|
||||
while writtenBytes != bufferSize {
|
||||
let result = _swift_stdlib_write(
|
||||
let result = platform_write(
|
||||
self.fd, UnsafeRawPointer(utf8CStr.baseAddress! + Int(writtenBytes)),
|
||||
bufferSize - writtenBytes)
|
||||
if result < 0 {
|
||||
@@ -222,7 +228,7 @@ public struct _FDOutputStream : TextOutputStream {
|
||||
if isClosed {
|
||||
return
|
||||
}
|
||||
let result = _swift_stdlib_close(fd)
|
||||
let result = platform_close(fd)
|
||||
if result < 0 {
|
||||
fatalError("close() returned an error")
|
||||
}
|
||||
|
||||
@@ -45,14 +45,6 @@ static inline void _swift_stdlib_free(void *_Nullable ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
// <unistd.h>
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
__swift_ssize_t _swift_stdlib_read(int fd, void *buf, __swift_size_t nbyte);
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
__swift_ssize_t _swift_stdlib_write(int fd, const void *buf, __swift_size_t nbyte);
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
int _swift_stdlib_close(int fd);
|
||||
|
||||
// String handling <string.h>
|
||||
SWIFT_READONLY
|
||||
static inline __swift_size_t _swift_stdlib_strlen(const char *s) {
|
||||
|
||||
@@ -329,9 +329,13 @@ extension MutableCollection where Self: BidirectionalCollection {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(ABI): unused return value
|
||||
/// Merges the elements in the ranges `lo..<mid` and `mid..<hi` using `buffer`
|
||||
/// as out-of-place storage. Stable.
|
||||
///
|
||||
/// The unused return value is legacy ABI. It was originally added as a
|
||||
/// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
///
|
||||
/// - Precondition: `lo..<mid` and `mid..<hi` must already be sorted according
|
||||
/// to `areInIncreasingOrder`.
|
||||
/// - Precondition: `buffer` must point to a region of memory at least as large
|
||||
@@ -506,15 +510,19 @@ internal func _findNextRun<C: RandomAccessCollection>(
|
||||
}
|
||||
|
||||
extension UnsafeMutableBufferPointer {
|
||||
// FIXME(ABI): unused return value
|
||||
/// Merges the elements at `runs[i]` and `runs[i - 1]`, using `buffer` as
|
||||
/// out-of-place storage.
|
||||
///
|
||||
/// The unused return value is legacy ABI. It was originally added as a
|
||||
/// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
///
|
||||
/// - Precondition: `runs.count > 1` and `i > 0`
|
||||
/// - Precondition: `buffer` must have at least
|
||||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public mutating func _mergeRuns(
|
||||
internal mutating func _mergeRuns(
|
||||
_ runs: inout [Range<Index>],
|
||||
at i: Int,
|
||||
buffer: UnsafeMutablePointer<Element>,
|
||||
@@ -537,17 +545,21 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
// FIXME(ABI): unused return value
|
||||
/// Merges upper elements of `runs` until the required invariants are
|
||||
/// satisfied.
|
||||
///
|
||||
/// The unused return value is legacy ABI. It was originally added as a
|
||||
/// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
///
|
||||
/// - Precondition: `buffer` must have at least
|
||||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
|
||||
/// - Precondition: The ranges in `runs` must be consecutive, such that for
|
||||
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public mutating func _mergeTopRuns(
|
||||
internal mutating func _mergeTopRuns(
|
||||
_ runs: inout [Range<Index>],
|
||||
buffer: UnsafeMutablePointer<Element>,
|
||||
by areInIncreasingOrder: (Element, Element) throws -> Bool
|
||||
@@ -611,16 +623,20 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
// FIXME(ABI): unused return value
|
||||
/// Merges elements of `runs` until only one run remains.
|
||||
///
|
||||
/// The unused return value is legacy ABI. It was originally added as a
|
||||
/// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
///
|
||||
/// - Precondition: `buffer` must have at least
|
||||
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
|
||||
/// - Precondition: The ranges in `runs` must be consecutive, such that for
|
||||
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public mutating func _finalizeRuns(
|
||||
internal mutating func _finalizeRuns(
|
||||
_ runs: inout [Range<Index>],
|
||||
buffer: UnsafeMutablePointer<Element>,
|
||||
by areInIncreasingOrder: (Element, Element) throws -> Bool
|
||||
|
||||
@@ -22,12 +22,6 @@
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "SwiftShims/LibcShims.h"
|
||||
|
||||
@@ -46,32 +40,3 @@ __swift_size_t _swift_stdlib_fwrite_stdout(const void *ptr,
|
||||
__swift_size_t nitems) {
|
||||
return fwrite(ptr, size, nitems, stdout);
|
||||
}
|
||||
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
__swift_ssize_t
|
||||
_swift_stdlib_read(int fd, void *buf, __swift_size_t nbyte) {
|
||||
#if defined(_WIN32)
|
||||
return _read(fd, buf, nbyte);
|
||||
#else
|
||||
return read(fd, buf, nbyte);
|
||||
#endif
|
||||
}
|
||||
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
__swift_ssize_t
|
||||
_swift_stdlib_write(int fd, const void *buf, __swift_size_t nbyte) {
|
||||
#if defined(_WIN32)
|
||||
return _write(fd, buf, nbyte);
|
||||
#else
|
||||
return write(fd, buf, nbyte);
|
||||
#endif
|
||||
}
|
||||
|
||||
SWIFT_RUNTIME_STDLIB_SPI
|
||||
int _swift_stdlib_close(int fd) {
|
||||
#if defined(_WIN32)
|
||||
return _close(fd);
|
||||
#else
|
||||
return close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
76
validation-test/stdlib/Sort-ABI.swift
Normal file
76
validation-test/stdlib/Sort-ABI.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
// RUN: %target-run-stdlib-swift
|
||||
// REQUIRES: executable_test
|
||||
|
||||
import StdlibUnittest
|
||||
|
||||
var SortABITestSuite = TestSuite("SortABI")
|
||||
|
||||
SortABITestSuite.test("_merge-ABI") {
|
||||
let result = withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
buffer -> Bool in
|
||||
_ = buffer.initialize(from: 0..<10)
|
||||
return withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
_merge(
|
||||
low: buffer.baseAddress! + 5,
|
||||
mid: buffer.baseAddress! + 8,
|
||||
high: buffer.baseAddress! + 9,
|
||||
buffer: $0.baseAddress!,
|
||||
by: <
|
||||
)
|
||||
}
|
||||
}
|
||||
// The return value is legacy ABI. It was originally added as a
|
||||
// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
// `_merge` always returns `true`
|
||||
expectEqual(result, true)
|
||||
}
|
||||
|
||||
SortABITestSuite.test("_mergeRuns-ABI") {
|
||||
let result = withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
temp -> Bool in
|
||||
_ = temp.initialize(from: 0..<10)
|
||||
var buffer = temp
|
||||
var runs = [5..<8, 8..<9]
|
||||
return withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
buffer._mergeRuns(&runs, at: 1, buffer: $0.baseAddress!, by: <)
|
||||
}
|
||||
}
|
||||
// The return value is legacy ABI. It was originally added as a
|
||||
// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
// `_mergeRuns` always returns `true`
|
||||
expectEqual(result, true)
|
||||
}
|
||||
|
||||
SortABITestSuite.test("_mergeTopRuns-ABI") {
|
||||
let result = withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
temp -> Bool in
|
||||
_ = temp.initialize(from: 0..<10)
|
||||
var buffer = temp
|
||||
var runs = [5..<8, 8..<9]
|
||||
return withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
buffer._mergeTopRuns(&runs, buffer: $0.baseAddress!, by: <)
|
||||
}
|
||||
}
|
||||
// The return value is legacy ABI. It was originally added as a
|
||||
// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
// `_mergeTopRuns` always returns `true`
|
||||
expectEqual(result, true)
|
||||
}
|
||||
|
||||
SortABITestSuite.test("_finalizeRuns-ABI") {
|
||||
let result = withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
temp -> Bool in
|
||||
_ = temp.initialize(from: 0..<10)
|
||||
var buffer = temp
|
||||
var runs = [5..<8, 8..<9]
|
||||
return withUnsafeTemporaryAllocation(of: Int.self, capacity: 10) {
|
||||
buffer._finalizeRuns(&runs, buffer: $0.baseAddress!, by: <)
|
||||
}
|
||||
}
|
||||
// The return value is legacy ABI. It was originally added as a
|
||||
// workaround for a compiler bug (now fixed). See SR-14750 (rdar://45044610).
|
||||
// `_finalizeRuns` always returns `true`
|
||||
expectEqual(result, true)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
Reference in New Issue
Block a user