From aed6836f132d6cee7d695332d6686ad21c0e500b Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Wed, 16 Jul 2025 08:35:32 -0700 Subject: [PATCH] Reinstate local definitions of `_overrideLifetime()` This partially reverts https://github.com/swiftlang/swift-foundation/pull/1400 --- Sources/FoundationEssentials/Data/Data.swift | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Sources/FoundationEssentials/Data/Data.swift b/Sources/FoundationEssentials/Data/Data.swift index 1f684186e..d4956cf73 100644 --- a/Sources/FoundationEssentials/Data/Data.swift +++ b/Sources/FoundationEssentials/Data/Data.swift @@ -2974,3 +2974,53 @@ extension Data : Codable { } } } + +// TODO: remove once _overrideLifetime is public in the standard library +/// Unsafely discard any lifetime dependency on the `dependent` argument. Return +/// a value identical to `dependent` with a lifetime dependency on the caller's +/// borrow scope of the `source` argument. +@unsafe +@_unsafeNonescapableResult +@_alwaysEmitIntoClient +@_transparent +@lifetime(borrow source) +internal func _overrideLifetime< + T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable +>( + _ dependent: consuming T, borrowing source: borrowing U +) -> T { + dependent +} + +/// Unsafely discard any lifetime dependency on the `dependent` argument. Return +/// a value identical to `dependent` that inherits all lifetime dependencies from +/// the `source` argument. +@unsafe +@_unsafeNonescapableResult +@_alwaysEmitIntoClient +@_transparent +@lifetime(copy source) +internal func _overrideLifetime< + T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable +>( + _ dependent: consuming T, copying source: borrowing U +) -> T { + dependent +} + +/// Unsafely discard any lifetime dependency on the `dependent` argument. +/// Return a value identical to `dependent` with a lifetime dependency +/// on the caller's exclusive borrow scope of the `source` argument. +@unsafe +@_unsafeNonescapableResult +@_alwaysEmitIntoClient +@_transparent +@lifetime(&source) +internal func _overrideLifetime< + T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable +>( + _ dependent: consuming T, + mutating source: inout U +) -> T { + dependent +}