[Pitch] Weak let

Yeah, good point. And that does bring up the question of why computed properties are declared with var instead of let. A computed property without a setter or with a nonmutating setter is guaranteed to never formally mutate whatever backing storage it relies on, but it still has to be declared with var because (I assume) it communicates that the returned value can still vary, even though the backing storage is formally immutable. All the ways that the semantics of weak are being spelled out in this thread require the use of a computed property, which in my opinion shows that weak has the semantics of a property wrapper.

I guess var has a bit of a double meaning. For stored properties, it communicates the possibility of formal (exclusive) mutation. For computed properties and property wrappers, it communicates the possibility of any kind of mutation at all, including shared mutation; only the presence of a mutating setter creates the possibility of formal mutation. For example, Atomic has to be declared with let, despite the value being mutable, because the mutability is shared, not formal. But a hypothetical Atomic property wrapper would have to be declared as @Atomic var a, because the returned value can change, even though the backing storage is never formally mutated.

1 Like