From c0802bd93fadffcd9f9d6160faeb54ce7dee58e1 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 19 Aug 2024 18:48:24 -0700 Subject: [PATCH] [Future] Add unsafelyOverrideLifetime(of:to:) --- Sources/Future/CMakeLists.txt | 1 + Sources/Future/LifetimeOverride.swift | 23 +++++++++++++++++++++ Xcode/Collections.xcodeproj/project.pbxproj | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 Sources/Future/LifetimeOverride.swift diff --git a/Sources/Future/CMakeLists.txt b/Sources/Future/CMakeLists.txt index 63b1192f..285c45f2 100644 --- a/Sources/Future/CMakeLists.txt +++ b/Sources/Future/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(Future "Cell.swift" "ContiguousStorage.swift" "Inout.swift" + "LifetimeOverride.swift" "RawSpan.swift" "Span.swift" "Containers/Container.swift" diff --git a/Sources/Future/LifetimeOverride.swift b/Sources/Future/LifetimeOverride.swift new file mode 100644 index 00000000..e7b8d8da --- /dev/null +++ b/Sources/Future/LifetimeOverride.swift @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 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 +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import Builtin + +@_unsafeNonescapableResult +public func unsafelyOverrideLifetime< + T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable +>( + of dependent: consuming T, + to source: borrowing U +) -> dependsOn(source) T { + dependent +} diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 49f9630c..61d92c79 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 7D380E072C6BFB9B00AD8F58 /* LifetimeOverride.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D380E062C6BFB9500AD8F58 /* LifetimeOverride.swift */; }; 7D9B859729E4F74400B291CD /* BitArray+Shifts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859129E4F74400B291CD /* BitArray+Shifts.swift */; }; 7D9B859829E4F74400B291CD /* BitArray+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859229E4F74400B291CD /* BitArray+Descriptions.swift */; }; 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859329E4F74400B291CD /* BitArray+LosslessStringConvertible.swift */; }; @@ -437,6 +438,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7D380E062C6BFB9500AD8F58 /* LifetimeOverride.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifetimeOverride.swift; sourceTree = ""; }; 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D429CCEF1500CB2595 /* generate-sources.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "generate-sources.sh"; sourceTree = ""; }; @@ -1808,6 +1810,7 @@ children = ( 7DEBEC1B2C5AE43C00A1BF15 /* Containers */, 7DEBEC1C2C5AE43C00A1BF15 /* Box.swift */, + 7D380E062C6BFB9500AD8F58 /* LifetimeOverride.swift */, 7DEBEC1D2C5AE43C00A1BF15 /* Cell.swift */, 7DEBEC1E2C5AE43C00A1BF15 /* CMakeLists.txt */, 7DEBEC1F2C5AE43C00A1BF15 /* ContiguousStorage.swift */, @@ -1959,6 +1962,7 @@ 7DE9213629CA70F4004483EB /* TreeSet+SetAlgebra basics.swift in Sources */, 7DE9202C29CA70F3004483EB /* OrderedSet+Initializers.swift in Sources */, 7DE9213229CA70F4004483EB /* TreeSet+SetAlgebra formSymmetricDifference.swift in Sources */, + 7D380E072C6BFB9B00AD8F58 /* LifetimeOverride.swift in Sources */, 7DE9203429CA70F3004483EB /* OrderedSet+Partial SetAlgebra formUnion.swift in Sources */, 7DE9214A29CA70F4004483EB /* _HashNode+Subtree Insertions.swift in Sources */, 7DE9215829CA70F4004483EB /* _HashNode+Structural union.swift in Sources */,