some more stuff

This commit is contained in:
Alejandro Alonso committed 2025-04-16 09:50:00 -07:00
1 parent 35da38de54
commit c42b4d1ebc
3 files changed
+35 -26

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ public struct Borrow<T: ~Copyable>: Copyable, ~Escapable {
unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value))
}
@lifetime(copy owner)
@lifetime(borrow owner)
@_alwaysEmitIntoClient
@_transparent
public init<Owner: ~Copyable & ~Escapable>(
+14
View File
@@ -61,6 +61,20 @@ extension Box where T: ~Copyable {
unsafe _pointer
}
}
@lifetime(borrow self)
@_alwaysEmitIntoClient
@_transparent
public func borrow() -> Borrow<T> {
unsafe Borrow(unsafeAddress: UnsafePointer(_pointer), owner: self)
}
@lifetime(&self)
@_alwaysEmitIntoClient
@_transparent
public mutating func mutate() -> Inout<T> {
unsafe Inout(unsafeAddress: _pointer, owner: &self)
}
}
extension Box where T: Copyable {
+20 -25
View File
@@ -15,33 +15,28 @@ extension Optional where Wrapped: ~Copyable {
@lifetime(borrow self)
@_addressableSelf
public func borrow() -> Borrow<Wrapped>? {
switch self {
case .some:
let pointer = unsafe UnsafePointer<Wrapped>(
Builtin.unprotectedAddressOfBorrow(self)
)
return unsafe Borrow(unsafeAddress: pointer, owner: self)
case .none:
if self == nil {
return nil
}
let pointer = unsafe UnsafePointer<Wrapped>(
Builtin.unprotectedAddressOfBorrow(self)
)
return unsafe Borrow(unsafeAddress: pointer, owner: self)
}
#if false // Compiler bug preventing this
@lifetime(&self)
public mutating func mutate() -> Inout<Wrapped>? {
switch self {
case .some:
let pointer = unsafe UnsafeMutablePointer<Wrapped>(
Builtin.unprotectedAddressOf(&self)
)
return unsafe Inout(unsafeAddress: pointer, owner: &self)
case .none:
return nil
}
}
#endif
// #if false // Compiler bug preventing this
// @lifetime(&self)
// public mutating func mutate() -> Inout<Wrapped>? {
// if self == nil {
// return nil
// }
//
// let pointer = unsafe UnsafeMutablePointer<Wrapped>(
// Builtin.unprotectedAddressOf(&self)
// )
//
// return unsafe Inout(unsafeAddress: pointer, owner: &self)
// }
}