[swift-dev] Disallowing weak struct properties
jordan_rose at apple.com
Fri Jan 29 20:31:54 CST 2016
> On Jan 29, 2016, at 18:22 , John McCall <rjmccall at apple.com> wrote:
>> On Jan 29, 2016, at 5:56 PM, Jordan Rose via swift-dev <swift-dev at swift.org> wrote:
>> Hi, everyone. What do you think about dropping support for 'weak' in struct properties? This would fix a semantic issue—'let' structs containing weak properties won't change out from under you
> Is there a formalizable notion of “change” here that doesn’t include changes in mutable referents and that isn’t just restating bit-equivalence?
If you treat the "value" of a reference as its referent's identity rather than contents, then the "value" of a struct is fully captured by the "values" of its members (which happens to be bitwise equality). The struct value has no identity.
The particular benefit we'd get here is that existential boxes could be passed in registers, but Slava pointed out that we could just force values containing weak references to be stored out of line even if they'd otherwise fit in the box.
>> —and (AFAICT) would make all values trivially movable, which is a great quality to have.
> If you sweep “unowned" up with “weak”, yes, this is true of the current language. It’s not an obvious restriction that we want to adopt forever, though.
I thought unowned was ref-counted (and therefore forwardable) as well, or are we dropping that implementation because we couldn't get it to work with objc?
More information about the swift-dev