From 0d4376d5cdd3160e175092f10ce0f7b9d81f3e7a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 29 Jul 2024 13:16:32 -0700 Subject: [PATCH 1/6] [_CollectionsUtilities] Delete obsolete compatibility definitions --- Package.swift | 4 - Sources/_CollectionsUtilities/CMakeLists.txt | 4 - ...safeMutableBufferPointer+SE-0370.swift.gyb | 424 --------- .../UnsafeMutablePointer+SE-0370.swift.gyb | 43 - .../UnsafeRawPointer extensions.swift.gyb | 89 -- .../UnsafeMutableBufferPointer+SE-0370.swift | 832 ------------------ .../UnsafeMutablePointer+SE-0370.swift | 72 -- .../UnsafeRawPointer extensions.swift | 164 ---- .../Specialize.swift.gyb | 34 - .../autogenerated/Specialize.swift | 54 -- 10 files changed, 1720 deletions(-) delete mode 100644 Sources/_CollectionsUtilities/Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb delete mode 100644 Sources/_CollectionsUtilities/Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb delete mode 100644 Sources/_CollectionsUtilities/Compatibility/UnsafeRawPointer extensions.swift.gyb delete mode 100644 Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift delete mode 100644 Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift delete mode 100644 Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeRawPointer extensions.swift delete mode 100644 Sources/_CollectionsUtilities/Specialize.swift.gyb delete mode 100644 Sources/_CollectionsUtilities/autogenerated/Specialize.swift diff --git a/Package.swift b/Package.swift index 846a3e43..639f4b99 100644 --- a/Package.swift +++ b/Package.swift @@ -194,9 +194,6 @@ let targets: [CustomTarget] = [ name: "_CollectionsUtilities", exclude: [ "CMakeLists.txt", - "Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb", - "Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb", - "Compatibility/UnsafeRawPointer extensions.swift.gyb", "Debugging.swift.gyb", "Descriptions.swift.gyb", "IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb", @@ -204,7 +201,6 @@ let targets: [CustomTarget] = [ "IntegerTricks/UInt+first and last set bit.swift.gyb", "IntegerTricks/UInt+reversed.swift.gyb", "RandomAccessCollection+Offsets.swift.gyb", - "Specialize.swift.gyb", "UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb", "UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb", "UnsafeBitSet/_UnsafeBitSet.swift.gyb", diff --git a/Sources/_CollectionsUtilities/CMakeLists.txt b/Sources/_CollectionsUtilities/CMakeLists.txt index 82c99206..5f3927a8 100644 --- a/Sources/_CollectionsUtilities/CMakeLists.txt +++ b/Sources/_CollectionsUtilities/CMakeLists.txt @@ -11,12 +11,8 @@ add_library(_CollectionsUtilities "autogenerated/Debugging.swift" "autogenerated/Descriptions.swift" "autogenerated/RandomAccessCollection+Offsets.swift" - "autogenerated/Specialize.swift" "autogenerated/UnsafeBufferPointer+Extras.swift" "autogenerated/UnsafeMutableBufferPointer+Extras.swift" - "Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift" - "Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift" - "Compatibility/autogenerated/UnsafeRawPointer extensions.swift" "IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift" "IntegerTricks/autogenerated/Integer rank.swift" "IntegerTricks/autogenerated/UInt+first and last set bit.swift" diff --git a/Sources/_CollectionsUtilities/Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb b/Sources/_CollectionsUtilities/Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb deleted file mode 100644 index 8e4f6deb..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb +++ /dev/null @@ -1,424 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -// Note: These are adapted from SE-0370 in the Swift 5.8 Standard Library. - -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Deinitializes every instance in this buffer. - /// - /// The region of memory underlying this buffer must be fully initialized. - /// After calling `deinitialize(count:)`, the memory is uninitialized, - /// but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - ${modifier} func deinitialize() -> UnsafeMutableRawBufferPointer { - guard let start = baseAddress else { return .init(start: nil, count: 0) } - start.deinitialize(count: count) - return .init(start: UnsafeMutableRawPointer(start), - count: count * MemoryLayout.stride) - } -} -#endif - -// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-( -extension UnsafeMutableBufferPointer { - /// Initializes the buffer's memory with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method on a buffer, - /// the memory referenced by the buffer must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer's storage. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - ${modifier} func initialize( - fromContentsOf source: C - ) -> Index - where C.Element == Element { - let count: Int? = source.withContiguousStorageIfAvailable { - guard let sourceAddress = $0.baseAddress, !$0.isEmpty else { - return 0 - } - precondition( - $0.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.initialize(from: sourceAddress, count: $0.count) - return $0.count - } - if let count = count { - return startIndex.advanced(by: count) - } - - var (iterator, copied) = source._copyContents(initializing: self) - precondition( - iterator.next() == nil, - "buffer cannot contain every element from source." - ) - return startIndex.advanced(by: copied) - } -} - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func moveInitialize(fromContentsOf source: Self) -> Index { - guard let sourceAddress = source.baseAddress, !source.isEmpty else { - return startIndex - } - precondition( - source.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.moveInitialize(from: sourceAddress, count: source.count) - return startIndex.advanced(by: source.count) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func moveInitialize(fromContentsOf source: Slice) -> Index { - return moveInitialize(fromContentsOf: Self(rebasing: source)) - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - ${modifier} func initializeElement(at index: Index, to value: Element) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.initialize(to: value) - } - - /// Retrieves and returns the element at `index`, - /// leaving that element's underlying memory uninitialized. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `moveElement(from:)`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to retrieve and deinitialize. - /// - Returns: The instance referenced by this index in this buffer. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func moveElement(from index: Index) -> Element { - assert(startIndex <= index && index < endIndex) - return baseAddress.unsafelyUnwrapped.advanced(by: index).move() - } - - /// Deinitializes the memory underlying the element at `index`. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `deinitializeElement()`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to deinitialize. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func deinitializeElement(at index: Index) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.deinitialize(count: 1) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Initializes the buffer slice's memory with with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method - /// on a buffer slice, the memory it references must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the index of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to - /// the buffer slice's `startIndex`. If `source` contains as many elements - /// as the buffer slice can hold, the returned index is equal to - /// to the slice's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer slice's storage. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func initialize( - fromContentsOf source: C - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.initialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func moveInitialize( - fromContentsOf source: UnsafeMutableBufferPointer - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer slice into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer slice containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func moveInitialize( - fromContentsOf source: Slice> - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Deinitializes every instance in this buffer slice. - /// - /// The region of memory underlying this buffer slice must be fully - /// initialized. After calling `deinitialize(count:)`, the memory - /// is uninitialized, but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - @_alwaysEmitIntoClient - ${modifier} func deinitialize() -> UnsafeMutableRawBufferPointer - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).deinitialize() - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer slice is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - ${modifier} func initializeElement(at index: Int, to value: Element) - where Base == UnsafeMutableBufferPointer { - assert(startIndex <= index && index < endIndex) - base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value) - } -} -#endif - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Updates every element of this buffer's initialized memory. - /// - /// The buffer’s memory must be initialized or its `Element` type - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - ${modifier} func update(repeating repeatedValue: Element) { - guard let dstBase = baseAddress else { return } - dstBase.update(repeating: repeatedValue, count: count) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Updates every element of this buffer slice's initialized memory. - /// - /// The buffer slice’s memory must be initialized or its `Element` - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - ${modifier} func update(repeating repeatedValue: Element) - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).update(repeating: repeatedValue) - } -} -#endif -% end -${visibility_boilerplate("end")} diff --git a/Sources/_CollectionsUtilities/Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb b/Sources/_CollectionsUtilities/Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb deleted file mode 100644 index d95199cf..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} -#if swift(<5.8) -extension UnsafeMutablePointer { - /// Update this pointer's initialized memory with the specified number of - /// consecutive copies of the given value. - /// - /// The region of memory starting at this pointer and covering `count` - /// instances of the pointer's `Pointee` type must be initialized or - /// `Pointee` must be a trivial type. After calling - /// `update(repeating:count:)`, the region is initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - /// - count: The number of consecutive elements to update. - /// `count` must not be negative. - @_alwaysEmitIntoClient - ${modifier} func update(repeating repeatedValue: Pointee, count: Int) { - assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count") - for i in 0 ..< count { - self[i] = repeatedValue - } - } -} -#endif -% end -${visibility_boilerplate("end")} diff --git a/Sources/_CollectionsUtilities/Compatibility/UnsafeRawPointer extensions.swift.gyb b/Sources/_CollectionsUtilities/Compatibility/UnsafeRawPointer extensions.swift.gyb deleted file mode 100644 index 68c2eedc..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/UnsafeRawPointer extensions.swift.gyb +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} -#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334 -extension UnsafeRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} - -extension UnsafeMutableRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - ${modifier} func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} -#endif -% end -${visibility_boilerplate("end")} diff --git a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift b/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift deleted file mode 100644 index 9068f8b9..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift +++ /dev/null @@ -1,832 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -// Note: These are adapted from SE-0370 in the Swift 5.8 Standard Library. - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Deinitializes every instance in this buffer. - /// - /// The region of memory underlying this buffer must be fully initialized. - /// After calling `deinitialize(count:)`, the memory is uninitialized, - /// but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - internal func deinitialize() -> UnsafeMutableRawBufferPointer { - guard let start = baseAddress else { return .init(start: nil, count: 0) } - start.deinitialize(count: count) - return .init(start: UnsafeMutableRawPointer(start), - count: count * MemoryLayout.stride) - } -} -#endif - -// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-( -extension UnsafeMutableBufferPointer { - /// Initializes the buffer's memory with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method on a buffer, - /// the memory referenced by the buffer must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer's storage. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - internal func initialize( - fromContentsOf source: C - ) -> Index - where C.Element == Element { - let count: Int? = source.withContiguousStorageIfAvailable { - guard let sourceAddress = $0.baseAddress, !$0.isEmpty else { - return 0 - } - precondition( - $0.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.initialize(from: sourceAddress, count: $0.count) - return $0.count - } - if let count = count { - return startIndex.advanced(by: count) - } - - var (iterator, copied) = source._copyContents(initializing: self) - precondition( - iterator.next() == nil, - "buffer cannot contain every element from source." - ) - return startIndex.advanced(by: copied) - } -} - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - internal func moveInitialize(fromContentsOf source: Self) -> Index { - guard let sourceAddress = source.baseAddress, !source.isEmpty else { - return startIndex - } - precondition( - source.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.moveInitialize(from: sourceAddress, count: source.count) - return startIndex.advanced(by: source.count) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - internal func moveInitialize(fromContentsOf source: Slice) -> Index { - return moveInitialize(fromContentsOf: Self(rebasing: source)) - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - internal func initializeElement(at index: Index, to value: Element) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.initialize(to: value) - } - - /// Retrieves and returns the element at `index`, - /// leaving that element's underlying memory uninitialized. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `moveElement(from:)`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to retrieve and deinitialize. - /// - Returns: The instance referenced by this index in this buffer. - @inlinable - @_alwaysEmitIntoClient - internal func moveElement(from index: Index) -> Element { - assert(startIndex <= index && index < endIndex) - return baseAddress.unsafelyUnwrapped.advanced(by: index).move() - } - - /// Deinitializes the memory underlying the element at `index`. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `deinitializeElement()`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to deinitialize. - @inlinable - @_alwaysEmitIntoClient - internal func deinitializeElement(at index: Index) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.deinitialize(count: 1) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Initializes the buffer slice's memory with with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method - /// on a buffer slice, the memory it references must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the index of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to - /// the buffer slice's `startIndex`. If `source` contains as many elements - /// as the buffer slice can hold, the returned index is equal to - /// to the slice's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer slice's storage. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - internal func initialize( - fromContentsOf source: C - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.initialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - internal func moveInitialize( - fromContentsOf source: UnsafeMutableBufferPointer - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer slice into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer slice containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - internal func moveInitialize( - fromContentsOf source: Slice> - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Deinitializes every instance in this buffer slice. - /// - /// The region of memory underlying this buffer slice must be fully - /// initialized. After calling `deinitialize(count:)`, the memory - /// is uninitialized, but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - @_alwaysEmitIntoClient - internal func deinitialize() -> UnsafeMutableRawBufferPointer - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).deinitialize() - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer slice is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - internal func initializeElement(at index: Int, to value: Element) - where Base == UnsafeMutableBufferPointer { - assert(startIndex <= index && index < endIndex) - base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value) - } -} -#endif - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Updates every element of this buffer's initialized memory. - /// - /// The buffer’s memory must be initialized or its `Element` type - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - internal func update(repeating repeatedValue: Element) { - guard let dstBase = baseAddress else { return } - dstBase.update(repeating: repeatedValue, count: count) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Updates every element of this buffer slice's initialized memory. - /// - /// The buffer slice’s memory must be initialized or its `Element` - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - internal func update(repeating repeatedValue: Element) - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).update(repeating: repeatedValue) - } -} -#endif -#else // !COLLECTIONS_SINGLE_MODULE -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Deinitializes every instance in this buffer. - /// - /// The region of memory underlying this buffer must be fully initialized. - /// After calling `deinitialize(count:)`, the memory is uninitialized, - /// but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - public func deinitialize() -> UnsafeMutableRawBufferPointer { - guard let start = baseAddress else { return .init(start: nil, count: 0) } - start.deinitialize(count: count) - return .init(start: UnsafeMutableRawPointer(start), - count: count * MemoryLayout.stride) - } -} -#endif - -// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-( -extension UnsafeMutableBufferPointer { - /// Initializes the buffer's memory with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method on a buffer, - /// the memory referenced by the buffer must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer's storage. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - public func initialize( - fromContentsOf source: C - ) -> Index - where C.Element == Element { - let count: Int? = source.withContiguousStorageIfAvailable { - guard let sourceAddress = $0.baseAddress, !$0.isEmpty else { - return 0 - } - precondition( - $0.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.initialize(from: sourceAddress, count: $0.count) - return $0.count - } - if let count = count { - return startIndex.advanced(by: count) - } - - var (iterator, copied) = source._copyContents(initializing: self) - precondition( - iterator.next() == nil, - "buffer cannot contain every element from source." - ) - return startIndex.advanced(by: copied) - } -} - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - public func moveInitialize(fromContentsOf source: Self) -> Index { - guard let sourceAddress = source.baseAddress, !source.isEmpty else { - return startIndex - } - precondition( - source.count <= self.count, - "buffer cannot contain every element from source." - ) - baseAddress?.moveInitialize(from: sourceAddress, count: source.count) - return startIndex.advanced(by: source.count) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer, leaving the source memory - /// uninitialized and this buffer's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer, - /// the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// buffer's `startIndex`. If `source` contains as many elements as the buffer - /// can hold, the returned index is equal to the buffer's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer - /// may overlap. - /// - /// - Parameter source: A buffer containing the values to copy. The memory - /// region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer initialized - /// by this function. - @inlinable - @_alwaysEmitIntoClient - public func moveInitialize(fromContentsOf source: Slice) -> Index { - return moveInitialize(fromContentsOf: Self(rebasing: source)) - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - public func initializeElement(at index: Index, to value: Element) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.initialize(to: value) - } - - /// Retrieves and returns the element at `index`, - /// leaving that element's underlying memory uninitialized. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `moveElement(from:)`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to retrieve and deinitialize. - /// - Returns: The instance referenced by this index in this buffer. - @inlinable - @_alwaysEmitIntoClient - public func moveElement(from index: Index) -> Element { - assert(startIndex <= index && index < endIndex) - return baseAddress.unsafelyUnwrapped.advanced(by: index).move() - } - - /// Deinitializes the memory underlying the element at `index`. - /// - /// The memory underlying the element at `index` must be initialized. - /// After calling `deinitializeElement()`, the memory underlying this element - /// of the buffer is uninitialized, and still bound to type `Element`. - /// - /// - Parameters: - /// - index: The index of the buffer element to deinitialize. - @inlinable - @_alwaysEmitIntoClient - public func deinitializeElement(at index: Index) { - assert(startIndex <= index && index < endIndex) - let p = baseAddress.unsafelyUnwrapped.advanced(by: index) - p.deinitialize(count: 1) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Initializes the buffer slice's memory with with - /// every element of the source. - /// - /// Prior to calling the `initialize(fromContentsOf:)` method - /// on a buffer slice, the memory it references must be uninitialized, - /// or the `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the index of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to - /// the buffer slice's `startIndex`. If `source` contains as many elements - /// as the buffer slice can hold, the returned index is equal to - /// to the slice's `endIndex`. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// must not overlap. - /// - /// - Parameter source: A collection of elements to be used to - /// initialize the buffer slice's storage. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - public func initialize( - fromContentsOf source: C - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.initialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - public func moveInitialize( - fromContentsOf source: UnsafeMutableBufferPointer - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Moves every element of an initialized source buffer slice into the - /// uninitialized memory referenced by this buffer slice, leaving the - /// source memory uninitialized and this buffer slice's memory initialized. - /// - /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a - /// buffer slice, the memory it references must be uninitialized, - /// or its `Element` type must be a trivial type. After the call, - /// the memory referenced by the buffer slice up to, but not including, - /// the returned index is initialized. The memory referenced by - /// `source` is uninitialized after the function returns. - /// The buffer slice must reference enough memory to accommodate - /// `source.count` elements. - /// - /// The returned index is the position of the next uninitialized element - /// in the buffer slice, one past the index of the last element written. - /// If `source` contains no elements, the returned index is equal to the - /// slice's `startIndex`. If `source` contains as many elements as the slice - /// can hold, the returned index is equal to the slice's `endIndex`. - /// - /// - Note: The memory regions referenced by `source` and this buffer slice - /// may overlap. - /// - /// - Precondition: `self.count` >= `source.count` - /// - /// - Parameter source: A buffer slice containing the values to copy. - /// The memory region underlying `source` must be initialized. - /// - Returns: The index one past the last element of the buffer slice - /// initialized by this function. - @inlinable - @_alwaysEmitIntoClient - public func moveInitialize( - fromContentsOf source: Slice> - ) -> Index where Base == UnsafeMutableBufferPointer { - let buffer = Base(rebasing: self) - let index = buffer.moveInitialize(fromContentsOf: source) - let distance = buffer.distance(from: buffer.startIndex, to: index) - return startIndex.advanced(by: distance) - } - - /// Deinitializes every instance in this buffer slice. - /// - /// The region of memory underlying this buffer slice must be fully - /// initialized. After calling `deinitialize(count:)`, the memory - /// is uninitialized, but still bound to the `Element` type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Returns: A raw buffer to the same range of memory as this buffer. - /// The range of memory is still bound to `Element`. - @discardableResult - @inlinable - @_alwaysEmitIntoClient - public func deinitialize() -> UnsafeMutableRawBufferPointer - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).deinitialize() - } - - /// Initializes the element at `index` to the given value. - /// - /// The memory underlying the destination element must be uninitialized, - /// or `Element` must be a trivial type. After a call to `initialize(to:)`, - /// the memory underlying this element of the buffer slice is initialized. - /// - /// - Parameters: - /// - value: The value used to initialize the buffer element's memory. - /// - index: The index of the element to initialize - @inlinable - @_alwaysEmitIntoClient - public func initializeElement(at index: Int, to value: Element) - where Base == UnsafeMutableBufferPointer { - assert(startIndex <= index && index < endIndex) - base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value) - } -} -#endif - -#if swift(<5.8) -extension UnsafeMutableBufferPointer { - /// Updates every element of this buffer's initialized memory. - /// - /// The buffer’s memory must be initialized or its `Element` type - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - public func update(repeating repeatedValue: Element) { - guard let dstBase = baseAddress else { return } - dstBase.update(repeating: repeatedValue, count: count) - } -} -#endif - -#if swift(<5.8) -extension Slice { - /// Updates every element of this buffer slice's initialized memory. - /// - /// The buffer slice’s memory must be initialized or its `Element` - /// must be a trivial type. - /// - /// - Note: All buffer elements must already be initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - @_alwaysEmitIntoClient - public func update(repeating repeatedValue: Element) - where Base == UnsafeMutableBufferPointer { - Base(rebasing: self).update(repeating: repeatedValue) - } -} -#endif -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift b/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift deleted file mode 100644 index 2e89d5aa..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -#if swift(<5.8) -extension UnsafeMutablePointer { - /// Update this pointer's initialized memory with the specified number of - /// consecutive copies of the given value. - /// - /// The region of memory starting at this pointer and covering `count` - /// instances of the pointer's `Pointee` type must be initialized or - /// `Pointee` must be a trivial type. After calling - /// `update(repeating:count:)`, the region is initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - /// - count: The number of consecutive elements to update. - /// `count` must not be negative. - @_alwaysEmitIntoClient - internal func update(repeating repeatedValue: Pointee, count: Int) { - assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count") - for i in 0 ..< count { - self[i] = repeatedValue - } - } -} -#endif -#else // !COLLECTIONS_SINGLE_MODULE -#if swift(<5.8) -extension UnsafeMutablePointer { - /// Update this pointer's initialized memory with the specified number of - /// consecutive copies of the given value. - /// - /// The region of memory starting at this pointer and covering `count` - /// instances of the pointer's `Pointee` type must be initialized or - /// `Pointee` must be a trivial type. After calling - /// `update(repeating:count:)`, the region is initialized. - /// - /// - Parameters: - /// - repeatedValue: The value used when updating this pointer's memory. - /// - count: The number of consecutive elements to update. - /// `count` must not be negative. - @_alwaysEmitIntoClient - public func update(repeating repeatedValue: Pointee, count: Int) { - assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count") - for i in 0 ..< count { - self[i] = repeatedValue - } - } -} -#endif -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeRawPointer extensions.swift b/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeRawPointer extensions.swift deleted file mode 100644 index c389967e..00000000 --- a/Sources/_CollectionsUtilities/Compatibility/autogenerated/UnsafeRawPointer extensions.swift +++ /dev/null @@ -1,164 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334 -extension UnsafeRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - internal func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - internal func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} - -extension UnsafeMutableRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - internal func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - internal func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} -#endif -#else // !COLLECTIONS_SINGLE_MODULE -#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334 -extension UnsafeRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - public func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - public func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} - -extension UnsafeMutableRawPointer { - /// Obtain the next pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - public func alignedUp(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = (UInt(bitPattern: self) &+ mask) & ~mask - return Self(bitPattern: bits)! - } - - /// Obtain the preceding pointer properly aligned to store a value of type `T`. - /// - /// If `self` is properly aligned for accessing `T`, - /// this function returns `self`. - /// - /// - Parameters: - /// - type: the type to be stored at the returned address. - /// - Returns: a pointer properly aligned to store a value of type `T`. - @inlinable - @_alwaysEmitIntoClient - public func alignedDown(for type: T.Type) -> Self { - let mask = UInt(MemoryLayout.alignment) &- 1 - let bits = UInt(bitPattern: self) & ~mask - return Self(bitPattern: bits)! - } -} -#endif -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/_CollectionsUtilities/Specialize.swift.gyb b/Sources/_CollectionsUtilities/Specialize.swift.gyb deleted file mode 100644 index c654d78c..00000000 --- a/Sources/_CollectionsUtilities/Specialize.swift.gyb +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} -/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different -/// concrete type. -/// -/// This cast can be useful for dispatching to specializations of generic -/// functions. -@_transparent -@inlinable -${modifier} func _specialize(_ x: T, for: U.Type) -> U? { - // Note: this was ported from recent versions of the Swift stdlib. - guard T.self == U.self else { - return nil - } - return _identityCast(x, to: U.self) -} -% end -${visibility_boilerplate("end")} diff --git a/Sources/_CollectionsUtilities/autogenerated/Specialize.swift b/Sources/_CollectionsUtilities/autogenerated/Specialize.swift deleted file mode 100644 index 07087af2..00000000 --- a/Sources/_CollectionsUtilities/autogenerated/Specialize.swift +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different -/// concrete type. -/// -/// This cast can be useful for dispatching to specializations of generic -/// functions. -@_transparent -@inlinable -internal func _specialize(_ x: T, for: U.Type) -> U? { - // Note: this was ported from recent versions of the Swift stdlib. - guard T.self == U.self else { - return nil - } - return _identityCast(x, to: U.self) -} -#else // !COLLECTIONS_SINGLE_MODULE -/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different -/// concrete type. -/// -/// This cast can be useful for dispatching to specializations of generic -/// functions. -@_transparent -@inlinable -public func _specialize(_ x: T, for: U.Type) -> U? { - // Note: this was ported from recent versions of the Swift stdlib. - guard T.self == U.self else { - return nil - } - return _identityCast(x, to: U.self) -} -#endif // COLLECTIONS_SINGLE_MODULE From c1dd7622c42ee7eb724dda04d19c4e9615171931 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 29 Jul 2024 13:19:41 -0700 Subject: [PATCH 2/6] [manifest] Bump to v6.0 toolchain and language mode - Enable SuppressedAssociatedTypes to allow experimentation with protocols - Mark _CollectionsTestSupport as a test dependency on FutureTests --- Package.swift | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index 639f4b99..197ac5b3 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.0 //===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project @@ -56,8 +56,9 @@ let _settings: [SwiftSetting] = defines.map { .define($0) } + [ .enableExperimentalFeature("BuiltinModule"), .enableExperimentalFeature("NonescapableTypes"), .enableExperimentalFeature("BitwiseCopyable"), - .enableExperimentalFeature("RawLayout") -// .swiftLanguageVersion(.v5) + .enableExperimentalFeature("RawLayout"), + .enableExperimentalFeature("SuppressedAssociatedTypes"), + .swiftLanguageMode(.v6) ] struct CustomTarget { @@ -209,14 +210,14 @@ let targets: [CustomTarget] = [ ]), .target( - kind: .exported, - name: "Future", - dependencies: ["_CollectionsUtilities"], - exclude: ["CMakeLists.txt"]), + kind: .exported, + name: "Future", + dependencies: ["_CollectionsUtilities"], + exclude: ["CMakeLists.txt"]), .target( - kind: .test, - name: "FutureTests", - dependencies: ["Future"]), + kind: .test, + name: "FutureTests", + dependencies: ["Future", "_CollectionsTestSupport"]), .target( kind: .exported, From 2359d9a09cb26561eda2571ea007ba442f32144a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 29 Jul 2024 13:22:44 -0700 Subject: [PATCH 3/6] [_CollectionsUtilities] Fix visibility modifiers in single module mode --- ...nsafeMutableBufferPointer+Extras.swift.gyb | 28 +++++++++---------- .../UnsafeMutableBufferPointer+Extras.swift | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Sources/_CollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb b/Sources/_CollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb index c7c6ee0f..4d7cdde7 100644 --- a/Sources/_CollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb +++ b/Sources/_CollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb @@ -18,7 +18,7 @@ ${autogenerated_warning()} ${visibility_boilerplate(modifier)} extension UnsafeMutableBufferPointer { @inlinable - public func initialize(fromContentsOf source: Self) -> Index { + ${modifier} func initialize(fromContentsOf source: Self) -> Index { guard source.count > 0 else { return 0 } precondition( source.count <= self.count, @@ -30,7 +30,7 @@ extension UnsafeMutableBufferPointer { } @inlinable - public func initialize(fromContentsOf source: Slice) -> Index { + ${modifier} func initialize(fromContentsOf source: Slice) -> Index { let sourceCount = source.count guard sourceCount > 0 else { return 0 } precondition( @@ -45,7 +45,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - public func initialize( + ${modifier} func initialize( fromContentsOf source: UnsafeMutableBufferPointer ) -> Index where Base == UnsafeMutableBufferPointer @@ -56,7 +56,7 @@ extension Slice { } @inlinable @inline(__always) - public func initialize( + ${modifier} func initialize( fromContentsOf source: Slice> ) -> Index where Base == UnsafeMutableBufferPointer @@ -69,7 +69,7 @@ extension Slice { extension UnsafeMutableBufferPointer { @inlinable @inline(__always) - public func initializeAll( + ${modifier} func initializeAll( fromContentsOf source: C ) where C.Element == Element { let i = self.initialize(fromContentsOf: source) @@ -77,25 +77,25 @@ extension UnsafeMutableBufferPointer { } @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Self) { + ${modifier} func initializeAll(fromContentsOf source: Self) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Slice) { + ${modifier} func initializeAll(fromContentsOf source: Slice) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Self) { + ${modifier} func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Slice) { + ${modifier} func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @@ -103,7 +103,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - public func initializeAll( + ${modifier} func initializeAll( fromContentsOf source: C ) where Base == UnsafeMutableBufferPointer { let i = self.initialize(fromContentsOf: source) @@ -111,7 +111,7 @@ extension Slice { } @inlinable @inline(__always) - public func initializeAll( + ${modifier} func initializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -119,7 +119,7 @@ extension Slice { } @inlinable @inline(__always) - public func initializeAll( + ${modifier} func initializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -127,7 +127,7 @@ extension Slice { } @inlinable @inline(__always) - public func moveInitializeAll( + ${modifier} func moveInitializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -135,7 +135,7 @@ extension Slice { } @inlinable @inline(__always) - public func moveInitializeAll( + ${modifier} func moveInitializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) diff --git a/Sources/_CollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift b/Sources/_CollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift index 2661d8ca..be578b23 100644 --- a/Sources/_CollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/_CollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift @@ -24,7 +24,7 @@ #if COLLECTIONS_SINGLE_MODULE extension UnsafeMutableBufferPointer { @inlinable - public func initialize(fromContentsOf source: Self) -> Index { + internal func initialize(fromContentsOf source: Self) -> Index { guard source.count > 0 else { return 0 } precondition( source.count <= self.count, @@ -36,7 +36,7 @@ extension UnsafeMutableBufferPointer { } @inlinable - public func initialize(fromContentsOf source: Slice) -> Index { + internal func initialize(fromContentsOf source: Slice) -> Index { let sourceCount = source.count guard sourceCount > 0 else { return 0 } precondition( @@ -51,7 +51,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - public func initialize( + internal func initialize( fromContentsOf source: UnsafeMutableBufferPointer ) -> Index where Base == UnsafeMutableBufferPointer @@ -62,7 +62,7 @@ extension Slice { } @inlinable @inline(__always) - public func initialize( + internal func initialize( fromContentsOf source: Slice> ) -> Index where Base == UnsafeMutableBufferPointer @@ -75,7 +75,7 @@ extension Slice { extension UnsafeMutableBufferPointer { @inlinable @inline(__always) - public func initializeAll( + internal func initializeAll( fromContentsOf source: C ) where C.Element == Element { let i = self.initialize(fromContentsOf: source) @@ -83,25 +83,25 @@ extension UnsafeMutableBufferPointer { } @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Self) { + internal func initializeAll(fromContentsOf source: Self) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Slice) { + internal func initializeAll(fromContentsOf source: Slice) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Self) { + internal func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Slice) { + internal func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @@ -109,7 +109,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - public func initializeAll( + internal func initializeAll( fromContentsOf source: C ) where Base == UnsafeMutableBufferPointer { let i = self.initialize(fromContentsOf: source) @@ -117,7 +117,7 @@ extension Slice { } @inlinable @inline(__always) - public func initializeAll( + internal func initializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -125,7 +125,7 @@ extension Slice { } @inlinable @inline(__always) - public func initializeAll( + internal func initializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -133,7 +133,7 @@ extension Slice { } @inlinable @inline(__always) - public func moveInitializeAll( + internal func moveInitializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -141,7 +141,7 @@ extension Slice { } @inlinable @inline(__always) - public func moveInitializeAll( + internal func moveInitializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) From f14a18d7a6b6b832228353f94ab99f86b2f201fc Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 30 Jul 2024 14:02:50 -0700 Subject: [PATCH 4/6] Mark empty singletons as nonisolated(unsafe) --- Sources/DequeModule/_DequeBuffer.swift | 12 ++++++------ .../HashNode/_HashNode+Storage.swift | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/DequeModule/_DequeBuffer.swift b/Sources/DequeModule/_DequeBuffer.swift index c7cd45bf..3751661e 100644 --- a/Sources/DequeModule/_DequeBuffer.swift +++ b/Sources/DequeModule/_DequeBuffer.swift @@ -41,9 +41,9 @@ extension _DequeBuffer: CustomStringConvertible { /// The type-punned empty singleton storage instance. @usableFromInline -internal let _emptyDequeStorage = _DequeBuffer.create( - minimumCapacity: 0, - makingHeaderWith: { _ in - _DequeBufferHeader(capacity: 0, count: 0, startSlot: .init(at: 0)) - }) - +nonisolated(unsafe) internal let _emptyDequeStorage + = _DequeBuffer.create( + minimumCapacity: 0, + makingHeaderWith: { _ in + _DequeBufferHeader(capacity: 0, count: 0, startSlot: .init(at: 0)) + }) diff --git a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift index c37e07ba..3f1cabfd 100644 --- a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift +++ b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift @@ -26,6 +26,7 @@ internal typealias _RawHashStorage = ManagedBuffer<_HashNodeHeader, _RawHashNode /// `_HashNode.Storage` subclass is to allow storage instances to properly /// clean up after themselves in their `deinit` method.) @usableFromInline +nonisolated(unsafe) internal let _emptySingleton: _RawHashStorage = _RawHashStorage.create( minimumCapacity: 0, makingHeaderWith: { _ in _HashNodeHeader(byteCapacity: 0) }) From a57ab2acec5621ff6a9ff61c8efe57e42cefc6de Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 5 Aug 2024 18:55:37 -0700 Subject: [PATCH 5/6] [manifest] Revert to Swift 5 for the test suite TestContext is not anywhere near concurrency ready --- Package.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 197ac5b3..e27845aa 100644 --- a/Package.swift +++ b/Package.swift @@ -52,13 +52,20 @@ var defines: [String] = [ // "COLLECTIONS_SINGLE_MODULE", ] -let _settings: [SwiftSetting] = defines.map { .define($0) } + [ +let _features: [SwiftSetting] = defines.map { .define($0) } + [ .enableExperimentalFeature("BuiltinModule"), .enableExperimentalFeature("NonescapableTypes"), .enableExperimentalFeature("BitwiseCopyable"), .enableExperimentalFeature("RawLayout"), .enableExperimentalFeature("SuppressedAssociatedTypes"), - .swiftLanguageMode(.v6) +] + +let _settings: [SwiftSetting] = _features + [ + .swiftLanguageVersion(.v6), +] + +let _testSettings: [SwiftSetting] = _features + [ + .swiftLanguageVersion(.v5), ] struct CustomTarget { @@ -121,7 +128,7 @@ extension CustomTarget { dependencies: dependencies, path: kind.path(for: directory), exclude: exclude, - swiftSettings: _settings, + swiftSettings: (kind == .testSupport ? _testSettings : _settings), linkerSettings: linkerSettings) case .test: return Target.testTarget( @@ -129,7 +136,7 @@ extension CustomTarget { dependencies: dependencies, path: kind.path(for: directory), exclude: exclude, - swiftSettings: _settings, + swiftSettings: _testSettings, linkerSettings: linkerSettings) } } @@ -176,7 +183,7 @@ extension Array where Element == CustomTarget { t.exclude.map { "\(t.name)/\($0)" } }, sources: targets.map { "\($0.name)" }, - swiftSettings: _settings, + swiftSettings: _testSettings, linkerSettings: linkerSettings) } } From e14970493019b12d03046f2fdd01b76fd4f9fa3c Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 5 Aug 2024 20:04:38 -0700 Subject: [PATCH 6/6] [RopeModule] Revert to Swift 5 mode --- Package.swift | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index e27845aa..4c000cc6 100644 --- a/Package.swift +++ b/Package.swift @@ -52,7 +52,7 @@ var defines: [String] = [ // "COLLECTIONS_SINGLE_MODULE", ] -let _features: [SwiftSetting] = defines.map { .define($0) } + [ +let _sharedSettings: [SwiftSetting] = defines.map { .define($0) } + [ .enableExperimentalFeature("BuiltinModule"), .enableExperimentalFeature("NonescapableTypes"), .enableExperimentalFeature("BitwiseCopyable"), @@ -60,11 +60,11 @@ let _features: [SwiftSetting] = defines.map { .define($0) } + [ .enableExperimentalFeature("SuppressedAssociatedTypes"), ] -let _settings: [SwiftSetting] = _features + [ +let _settings: [SwiftSetting] = _sharedSettings + [ .swiftLanguageVersion(.v6), ] -let _testSettings: [SwiftSetting] = _features + [ +let _testSettings: [SwiftSetting] = _sharedSettings + [ .swiftLanguageVersion(.v5), ] @@ -81,6 +81,7 @@ struct CustomTarget { var dependencies: [Target.Dependency] var directory: String var exclude: [String] + var settings: [SwiftSetting] } extension CustomTarget.Kind { @@ -105,14 +106,16 @@ extension CustomTarget { name: String, dependencies: [Target.Dependency] = [], directory: String? = nil, - exclude: [String] = [] + exclude: [String] = [], + settings: [SwiftSetting]? = nil ) -> CustomTarget { CustomTarget( kind: kind, name: name, dependencies: dependencies, directory: directory ?? name, - exclude: exclude) + exclude: exclude, + settings: settings ?? (kind.isTest ? _testSettings : _settings)) } func toTarget() -> Target { @@ -128,7 +131,7 @@ extension CustomTarget { dependencies: dependencies, path: kind.path(for: directory), exclude: exclude, - swiftSettings: (kind == .testSupport ? _testSettings : _settings), + swiftSettings: settings, linkerSettings: linkerSettings) case .test: return Target.testTarget( @@ -136,7 +139,7 @@ extension CustomTarget { dependencies: dependencies, path: kind.path(for: directory), exclude: exclude, - swiftSettings: _testSettings, + swiftSettings: settings, linkerSettings: linkerSettings) } } @@ -283,7 +286,9 @@ let targets: [CustomTarget] = [ name: "_RopeModule", dependencies: ["_CollectionsUtilities"], directory: "RopeModule", - exclude: ["CMakeLists.txt"]), + exclude: ["CMakeLists.txt"], + // FIXME: _modify accessors in RopeModule seem to be broken in Swift 6 mode + settings: _sharedSettings + [.swiftLanguageVersion(.v5)]), .target( kind: .test, name: "RopeModuleTests",