mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
Drop unused Optional._borrow, ._mutate and _insert definitions
This commit is contained in:
4 files changed
-181
No files matched your search
@@ -41,7 +41,6 @@ target_sources(${module_name} PRIVATE
|
||||
"LifetimeOverride.swift"
|
||||
"MutableSpan+Extras.swift"
|
||||
"MutableRef.swift"
|
||||
"Optional+Extras.swift"
|
||||
"OutputSpan+Extras.swift"
|
||||
"RandomAccessCollection+Offsets.swift"
|
||||
"Span+Extras.swift"
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2025 - 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if compiler(>=6.4)
|
||||
import Builtin
|
||||
|
||||
extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_lifetime(borrow self)
|
||||
@_addressableSelf
|
||||
package func _borrow() -> Ref<Wrapped>? {
|
||||
if self == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FIXME: This assumes that `Optional<T>.some` is guaranteed to have
|
||||
// `T` at the beginning of its layout. Is that true?
|
||||
let pointer = unsafe UnsafePointer<Wrapped>(
|
||||
Builtin.unprotectedAddressOfBorrow(self)
|
||||
)
|
||||
|
||||
return unsafe Ref(unsafeAddress: pointer, borrowing: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: ~Copyable /* FIXME: ~Escapable */ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_lifetime(&self)
|
||||
@_alwaysEmitIntoClient
|
||||
package mutating func _mutate() -> MutableRef<Wrapped>? {
|
||||
if self == nil {
|
||||
return nil
|
||||
}
|
||||
let pointer = unsafe UnsafeMutablePointer<Wrapped>(
|
||||
Builtin.unprotectedAddressOf(&self))
|
||||
return unsafe MutableRef(unsafeAddress: pointer, mutating: &self)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_lifetime(&self)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
package mutating func _insert(_ value: consuming Wrapped) -> MutableRef<Wrapped> {
|
||||
self = .some(value)
|
||||
return _mutate()._consumingUnsafelyUnwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -150,75 +150,5 @@ final class MutableRefTests: CollectionTestCase {
|
||||
expectEqual(ref.value, 3)
|
||||
expectEqual(x, 3)
|
||||
}
|
||||
|
||||
// MARK: Optional.mutate()
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_mutate_some() {
|
||||
var x: Int? = 77
|
||||
if var ref = x._mutate() {
|
||||
expectEqual(ref.value, 77)
|
||||
ref.value = 88
|
||||
} else {
|
||||
expectTrue(false, "Expected non-nil _MutableRef from .some optional")
|
||||
}
|
||||
expectEqual(x, 88)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_mutate_none() {
|
||||
var x: Int? = nil
|
||||
let ref = x._mutate()
|
||||
expectNil(ref)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_mutate_noncopyable() {
|
||||
var x: NoncopyablePayload? = NoncopyablePayload(33)
|
||||
if var ref = x._mutate() {
|
||||
expectEqual(ref.value.value, 33)
|
||||
ref.value.value = 44
|
||||
} else {
|
||||
expectTrue(false, "Expected non-nil _MutableRef from .some optional")
|
||||
}
|
||||
expectEqual(x!.value, 44)
|
||||
}
|
||||
|
||||
// MARK: Optional.insert(_:)
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_insert_into_nil() {
|
||||
var x: Int? = nil
|
||||
do {
|
||||
var ref = x._insert(42)
|
||||
expectEqual(ref.value, 42)
|
||||
ref.value = 99
|
||||
}
|
||||
expectEqual(x, 99)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_insert_into_some() {
|
||||
var x: Int? = 10
|
||||
do {
|
||||
var ref = x._insert(20)
|
||||
expectEqual(ref.value, 20)
|
||||
ref.value = 30
|
||||
}
|
||||
expectEqual(x, 30)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_insert_noncopyable() {
|
||||
var x: NoncopyablePayload? = nil
|
||||
do {
|
||||
var ref = x._insert(NoncopyablePayload(55))
|
||||
expectEqual(ref.value.value, 55)
|
||||
ref.value.value = 66
|
||||
}
|
||||
expectEqual(x!.value, 66)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -89,56 +89,5 @@ final class RefTests: CollectionTestCase {
|
||||
expectEqual(ref2.value, 42)
|
||||
}
|
||||
|
||||
// MARK: Optional.borrow()
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_borrow_some() {
|
||||
let x: Int? = 77
|
||||
if let ref = x._borrow() {
|
||||
expectEqual(ref.value, 77)
|
||||
} else {
|
||||
expectFailure("Expected non-nil Ref from .some optional")
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_borrow_none() {
|
||||
let x: Int? = nil
|
||||
let ref = x._borrow()
|
||||
expectNil(ref)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_borrow_string() {
|
||||
let x: String? = "world"
|
||||
if let ref = x._borrow() {
|
||||
expectEqual(ref.value, "world")
|
||||
} else {
|
||||
expectFailure("Expected non-nil Ref from .some optional")
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_borrow_noncopyable() {
|
||||
let x: NoncopyablePayload? = NoncopyablePayload(33)
|
||||
if let ref = x._borrow() {
|
||||
expectEqual(ref.value.value, 33)
|
||||
} else {
|
||||
expectFailure("Expected non-nil Ref from .some optional")
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
func test_optional_borrow_reference_type() {
|
||||
let tracker = LifetimeTracker()
|
||||
let obj = tracker.instance(for: 5)
|
||||
let x: LifetimeTracked<Int>? = obj
|
||||
if let ref = x._borrow() {
|
||||
expectTrue(ref.value === obj)
|
||||
expectEqual(ref.value.payload, 5)
|
||||
} else {
|
||||
expectFailure("Expected non-nil Ref from .some optional")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user