From ad56b1c8c475ad67196bf0d2e9a8ce4e2ba190e6 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Mon, 8 Sep 2025 18:52:47 -0700 Subject: [PATCH] [TrailingElementsModule] Underscore internal, ABI-exposed stored properties --- .../IntrusiveManagedBuffer.swift | 42 +++++++++---------- .../PaddedStorage.swift | 20 ++++----- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Sources/TrailingElementsModule/IntrusiveManagedBuffer.swift b/Sources/TrailingElementsModule/IntrusiveManagedBuffer.swift index 99dca9e1..9aed5313 100644 --- a/Sources/TrailingElementsModule/IntrusiveManagedBuffer.swift +++ b/Sources/TrailingElementsModule/IntrusiveManagedBuffer.swift @@ -12,7 +12,7 @@ public struct IntrusiveManagedBuffer: ~Copyable { /// The underlying storage. @usableFromInline - var pointer: UnsafeMutablePointer
+ var _pointer: UnsafeMutablePointer
/// The element type stored within the buffer. public typealias Element = Header.Element @@ -22,14 +22,14 @@ public struct IntrusiveManagedBuffer: ~Copyable /// memory safety. @_alwaysEmitIntoClient private init(_headerOnly header: consuming Header) { - pointer = UnsafeMutableRawPointer.allocate( + _pointer = UnsafeMutableRawPointer.allocate( byteCount: Self.allocationSize( header: header ), alignment: MemoryLayout
.alignment ).assumingMemoryBound(to: Header.self) - pointer.initialize(to: header) + _pointer.initialize(to: header) } @available(SwiftStdlib 5.1, *) @@ -68,8 +68,8 @@ public struct IntrusiveManagedBuffer: ~Copyable @_alwaysEmitIntoClient deinit { rawElements.deinitialize() - pointer.deinitialize(count: 1) - pointer.deallocate() + _pointer.deinitialize(count: 1) + _pointer.deallocate() } /// Take ownership over a pointer to memory containing the header followed @@ -79,7 +79,7 @@ public struct IntrusiveManagedBuffer: ~Copyable /// be freed. @_alwaysEmitIntoClient public init(consuming pointer: UnsafeMutablePointer
) { - self.pointer = pointer + self._pointer = pointer } /// Return the pointer to the underlying memory, including ownership over @@ -87,7 +87,7 @@ public struct IntrusiveManagedBuffer: ~Copyable /// it is the responsibility of the caller. @_alwaysEmitIntoClient public consuming func takePointer() -> UnsafeMutablePointer
{ - let pointer = self.pointer + let pointer = self._pointer discard self return pointer } @@ -96,11 +96,11 @@ public struct IntrusiveManagedBuffer: ~Copyable @_alwaysEmitIntoClient public var header: Header { unsafeAddress { - UnsafePointer(pointer) + UnsafePointer(_pointer) } unsafeMutableAddress { - pointer + _pointer } } @@ -138,7 +138,7 @@ public struct IntrusiveManagedBuffer: ~Copyable @_alwaysEmitIntoClient var rawElements: UnsafeMutableBufferPointer { UnsafeMutableBufferPointer( - start: UnsafeMutableRawPointer(pointer.advanced(by: 1)) + start: UnsafeMutableRawPointer(_pointer.advanced(by: 1)) .assumingMemoryBound(to: Element.self), count: header.trailingCount ) @@ -170,7 +170,7 @@ public struct IntrusiveManagedBuffer: ~Copyable /// referencing the header. @_alwaysEmitIntoClient public mutating func withUnsafeMutablePointerToHeader(_ body: (UnsafeMutablePointer
) throws(E) -> R) throws(E) -> R { - return try body(pointer) + return try body(_pointer) } /// Execute the given closure, providing it with an unsafe buffer pointer @@ -186,7 +186,7 @@ public struct IntrusiveManagedBuffer: ~Copyable public mutating func withUnsafeMutablePointers( _ body: (UnsafeMutablePointer
, UnsafeMutableBufferPointer) throws(E) -> R ) throws(E) -> R { - return try body(pointer, rawElements) + return try body(_pointer, rawElements) } /// Determine the allocation size needed for the given header value. @@ -223,7 +223,7 @@ extension IntrusiveManagedBuffer where Header: Copyable { totalSize: allocationSize(header: header) ) { (storage) throws(E) in /// Create a managed buffer over that temporary storage. - var managedBuffer = IntrusiveManagedBuffer(consuming: storage.pointer) + var managedBuffer = IntrusiveManagedBuffer(consuming: storage._pointer) managedBuffer.rawElements.initialize(repeating: element) do throws(E) { @@ -231,13 +231,13 @@ extension IntrusiveManagedBuffer where Header: Copyable { // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) return result } catch { // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) throw error } @@ -261,7 +261,7 @@ extension IntrusiveManagedBuffer where Header: Copyable { totalSize: allocationSize(header: header) ) { (storage) throws(E) in /// Create a managed buffer over that temporary storage. - var managedBuffer = IntrusiveManagedBuffer(consuming: storage.pointer) + var managedBuffer = IntrusiveManagedBuffer(consuming: storage._pointer) try managedBuffer._initializeTrailingElements(initializer: initializer) do throws(E) { @@ -269,13 +269,13 @@ extension IntrusiveManagedBuffer where Header: Copyable { // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) return result } catch { // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) throw error } @@ -301,20 +301,20 @@ extension IntrusiveManagedBuffer where Header.Element: BitwiseCopyable { totalSize: allocationSize(header: header) ) { (storage) throws(E) in /// Create a managed buffer over that temporary storage. - var managedBuffer = IntrusiveManagedBuffer(consuming: storage.pointer) + var managedBuffer = IntrusiveManagedBuffer(consuming: storage._pointer) do throws(E) { let result = try body(&managedBuffer) // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) return result } catch { // Tell the managed buffer not to free the storage. let finalPointer = managedBuffer.takePointer() - precondition(finalPointer == storage.pointer) + precondition(finalPointer == storage._pointer) throw error } diff --git a/Sources/TrailingElementsModule/PaddedStorage.swift b/Sources/TrailingElementsModule/PaddedStorage.swift index d8474015..b5c3c6e2 100644 --- a/Sources/TrailingElementsModule/PaddedStorage.swift +++ b/Sources/TrailingElementsModule/PaddedStorage.swift @@ -17,7 +17,7 @@ public struct PaddedStorage: ~Copyable { /// Pointer to the header, followed by the padding. @usableFromInline - let pointer: UnsafeMutablePointer
+ let _pointer: UnsafeMutablePointer
/// Create a new instance with the given header and total size. The total /// size includes the storage for the header itself, so it must be at least @@ -26,9 +26,9 @@ public struct PaddedStorage: ~Copyable { public init(header: consuming Header, totalSize size: Int) { precondition(size >= MemoryLayout
.size, "must allocate enough storage for the underlying stored type") - pointer = UnsafeMutableRawPointer.allocate(byteCount: size, alignment: MemoryLayout
.alignment) + _pointer = UnsafeMutableRawPointer.allocate(byteCount: size, alignment: MemoryLayout
.alignment) .assumingMemoryBound(to: Header.self) - pointer.initialize(to: header) + _pointer.initialize(to: header) } /// Take ownership over a pointer to memory containing the header followed @@ -38,32 +38,32 @@ public struct PaddedStorage: ~Copyable { /// deinitialized and freed. @_alwaysEmitIntoClient public init(consuming pointer: UnsafeMutablePointer
) { - self.pointer = pointer + self._pointer = pointer } /// Deinitializes the header, then deallocates the underlying memory. @_alwaysEmitIntoClient deinit { - pointer.deinitialize(count: 1) - pointer.deallocate() + _pointer.deinitialize(count: 1) + _pointer.deallocate() } /// Access the header portion of the value. @_alwaysEmitIntoClient public var header: Header { unsafeAddress { - UnsafePointer(pointer) + UnsafePointer(_pointer) } unsafeMutableAddress { - pointer + _pointer } } /// Executes the given closure with the pointer to the header itself. @_alwaysEmitIntoClient public func withUnsafeMutablePointerToHeader(_ body: (UnsafeMutablePointer
) throws(E) -> R) throws(E) -> R { - return try body(pointer) + return try body(_pointer) } /// Take ownership over the stored memory, returning its pointer. The @@ -71,7 +71,7 @@ public struct PaddedStorage: ~Copyable { /// as it is the responsibility of the caller. @_alwaysEmitIntoClient public consuming func takePointer() -> UnsafeMutablePointer
{ - let pointer = self.pointer + let pointer = self._pointer discard self return pointer }