Files

92 lines
2.8 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2026 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
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
/// Unsafely discard any lifetime dependency on the `dependent` argument.
/// Return a value identical to `dependent` with an immortal lifetime.
@_unsafeNonescapableResult
@_alwaysEmitIntoClient
@_transparent
@unsafe
@_lifetime(immortal)
package func _unsafeImmortalize<T: ~Copyable & ~Escapable>(
_ dependent: consuming T
) -> 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 borrow scope of the `source` argument.
@_unsafeNonescapableResult
@_alwaysEmitIntoClient
@_transparent
@unsafe
@_lifetime(borrow source)
package 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.
@_unsafeNonescapableResult
@_alwaysEmitIntoClient
@_transparent
@unsafe
@_lifetime(copy source)
package 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.
@_unsafeNonescapableResult
@_alwaysEmitIntoClient
@_transparent
@unsafe
@_lifetime(&source)
package func _overrideLifetime<
T: ~Copyable & ~Escapable,
U: ~Copyable & ~Escapable
>(
_ dependent: consuming T,
mutating source: inout U
) -> T {
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
// should be expressed by a builtin that is hidden within the function body.
dependent
}
/// Unsafely discard any lifetime dependency on the `dependent` inout
/// argument, replacing it with a lifetime dependency on the caller's borrow
/// scope of the `source` argument.
@_unsafeNonescapableResult
@_alwaysEmitIntoClient
@_transparent
@unsafe
@_lifetime(dependent: borrow source)
public func _overrideLifetime<
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
>(
_ dependent: inout T, borrowing source: borrowing U
) {}