From 89c7e027ecbb6e586ee24ce3e116ebe6fed7f7a6 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 26 Sep 2025 17:20:40 -0700 Subject: [PATCH] =?UTF-8?q?struct=20Inout=20=E2=86=92=20struct=20Mut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ContainersPreview/Box.swift | 8 ++++---- .../ContainersPreview/{Inout.swift => Mut.swift} | 16 ++++++++-------- Sources/ContainersPreview/Shared.swift | 4 ++-- .../{InoutTests.swift => MutTests.swift} | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) rename Sources/ContainersPreview/{Inout.swift => Mut.swift} (82%) rename Tests/ContainersTests/{InoutTests.swift => MutTests.swift} (93%) diff --git a/Sources/ContainersPreview/Box.swift b/Sources/ContainersPreview/Box.swift index 7567e0ac..3ff38888 100644 --- a/Sources/ContainersPreview/Box.swift +++ b/Sources/ContainersPreview/Box.swift @@ -79,8 +79,8 @@ extension Box where T: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(immortal) - public consuming func leak() -> Inout { - let result = unsafe Inout(unsafeImmortalAddress: _pointer) + public consuming func leak() -> Mut { + let result = unsafe Mut(unsafeImmortalAddress: _pointer) discard self return result } @@ -99,8 +99,8 @@ extension Box where T: ~Copyable { @_alwaysEmitIntoClient @_transparent @_lifetime(&self) - public mutating func mutate() -> Inout { - unsafe Inout(unsafeAddress: _pointer, mutating: &self) + public mutating func mutate() -> Mut { + unsafe Mut(unsafeAddress: _pointer, mutating: &self) } #endif } diff --git a/Sources/ContainersPreview/Inout.swift b/Sources/ContainersPreview/Mut.swift similarity index 82% rename from Sources/ContainersPreview/Inout.swift rename to Sources/ContainersPreview/Mut.swift index bf759e6d..983b6314 100644 --- a/Sources/ContainersPreview/Inout.swift +++ b/Sources/ContainersPreview/Mut.swift @@ -16,15 +16,15 @@ import Builtin /// A safe mutable reference allowing in-place mutation to an exclusive value. /// -/// In order to get an instance of an `Inout`, one must have exclusive access +/// In order to get an instance of a `Mut`, one must have exclusive access /// to the instance of `T`. This is achieved through the 'inout' operator, '&'. @frozen @safe -public struct Inout: ~Copyable, ~Escapable { +public struct Mut: ~Copyable, ~Escapable { @usableFromInline package let _pointer: UnsafeMutablePointer - /// Initializes an instance of 'Inout' extending the exclusive access of the + /// Initializes an instance of 'Mut' extending the exclusive access of the /// passed instance. /// /// - Parameter instance: The desired instance to get a mutable reference to. @@ -34,13 +34,13 @@ public struct Inout: ~Copyable, ~Escapable { unsafe _pointer = UnsafeMutablePointer(Builtin.unprotectedAddressOf(&instance)) } - /// Unsafely initializes an instance of 'Inout' using the given 'unsafeAddress' + /// Unsafely initializes an instance of 'Mut' using the given 'unsafeAddress' /// as the mutable reference based on the lifetime of the given 'owner' /// argument. /// /// - Parameter unsafeAddress: The address to use to mutably reference an /// instance of type 'T'. - /// - Parameter owner: The owning instance that this 'Inout' instance's + /// - Parameter owner: The owning instance that this 'Mut' instance's /// lifetime is based on. @unsafe @_alwaysEmitIntoClient @@ -53,7 +53,7 @@ public struct Inout: ~Copyable, ~Escapable { unsafe _pointer = unsafeAddress } - /// Unsafely initializes an instance of 'Inout' using the given + /// Unsafely initializes an instance of 'Mut' using the given /// 'unsafeImmortalAddress' as the mutable reference acting as though its /// lifetime is immortal. /// @@ -70,7 +70,7 @@ public struct Inout: ~Copyable, ~Escapable { } } -extension Inout where T: ~Copyable { +extension Mut where T: ~Copyable { /// Dereferences the mutable reference allowing for in-place reads and writes /// to the underlying instance. @_alwaysEmitIntoClient @@ -80,8 +80,8 @@ extension Inout where T: ~Copyable { unsafe UnsafePointer(_pointer) } - @_lifetime(copy self) @_transparent + @_lifetime(self: copy self) unsafeMutableAddress { unsafe _pointer } diff --git a/Sources/ContainersPreview/Shared.swift b/Sources/ContainersPreview/Shared.swift index 67b4e1fa..423d978b 100644 --- a/Sources/ContainersPreview/Shared.swift +++ b/Sources/ContainersPreview/Shared.swift @@ -139,11 +139,11 @@ extension Shared where Storage: ~Copyable { @inlinable @_lifetime(&self) - public mutating func mutate() -> Inout { + public mutating func mutate() -> Mut { // This is gloriously (and very explicitly) unsafe, as it should be. // `Shared` is carefully constructed to guarantee that // lifetime(self) == lifetime(_box.storage). - unsafe Inout(unsafeAddress: _mutableAddress, mutating: &self) + unsafe Mut(unsafeAddress: _mutableAddress, mutating: &self) } } diff --git a/Tests/ContainersTests/InoutTests.swift b/Tests/ContainersTests/MutTests.swift similarity index 93% rename from Tests/ContainersTests/InoutTests.swift rename to Tests/ContainersTests/MutTests.swift index 6bd2f0b7..a31b204d 100644 --- a/Tests/ContainersTests/InoutTests.swift +++ b/Tests/ContainersTests/MutTests.swift @@ -18,10 +18,10 @@ import ContainersPreview #endif #if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -final class InoutTests: XCTestCase { +final class MutTests: XCTestCase { func test_basic() { var x = 0 - var y = Inout(&x) + var y = Mut(&x) var v = y[] XCTAssertEqual(v, 0)