[Pre-Pitch] Disconnected Properties and Variables, and Opaque enums

I don't know why you want to merge optionality with disconnectedness; I don't think it's necessary.

My version of Disconnected looks like this:

public struct Disconnected<Value: ~Copyable>: ~Copyable, @unchecked Sendable {
    private nonisolated(unsafe) var value: Value

    public init(_ value: consuming sending Value) {
        self.value = value
    }

    public consuming func consume() -> sending Value {
        value
    }

    public mutating func swap(_ other: consuming sending Value) -> sending Value {
        let result = self.value
        self = Disconnected(other)
        return result
    }

    public mutating func take() -> sending Value where Value: ExpressibleByNilLiteral & SendableMetatype { // I think the need for `SendableMetatype` here is a bug, https://github.com/swiftlang/swift/issues/83253
        return swap(nil)
    }

    public mutating func withValue<R: ~Copyable, E: Error>(
        _ work: (inout sending Value) throws(E) -> sending R
    ) throws(E) -> sending R {
        try work(&self.value)
    }
}

(definitely not saying we shouldn't support ~Escapable too; that's just newer than I've had to deal with in practice)

2 Likes