<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 7:56 PM, Jordan Rose via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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—and (AFAICT) would make all values trivially movable, which is a great quality to have.<br class=""><div class=""><br class=""></div><div class="">… It <i class="">would</i>&nbsp;make having an array of weak references a little harder, but honestly we should have proper weak-supporting collections anyway; as I understand it the behavior you usually want is auto-compacting rather than leaving a hole. …</div></div></div></blockquote><br class=""></div><div>Well, this would certainly pour some cold water on Siesta. It might be able to get by with what you describe, but it’s hard to say without a more specific proposal on the weak-supporting collections. (Without such collections, this would be something of a disaster for the library.)</div><div><br class=""></div><div>On the one hand, almost all the weak properties in the whole project occur in structs.</div><div><br class=""></div><div>On the other hand, those structs are all meant to support weak collections of various kinds.</div><div><br class=""></div><div>On the other <i class="">other</i>&nbsp;hand, the behavior is more complex than what you outlined above:</div><div><br class=""></div><div><ul class="MailOutline"><li class="">there’s StrongOrWeakRef struct used by a cache that needs to be able to switch specific references from strong to weak (at which point auto-compaction of the weak ones would be desirable), and</li><li class="">a&nbsp;WeakRef that hangs on to referent’s&nbsp;ObjectIdentifier’s hash and identity, so that it can be a stable dictionary key.</li></ul><div class=""><br class=""></div><div class="">The second I imagine a dictionary with first-class support for weak keys would probably cover. The first seems pretty purpose-specific, however, and it’s less clear that general-purpose weak collections would cover it.</div><div class=""><br class=""></div><div class="">The&nbsp;StrongOrWeakRef usage suggests, I think, that weak collections may not quite be one size fits all, and having the ability to wrap a weak ref in a struct without incurring an additional allocation may be worth the trouble. At the very least, they’d need some serious thought.</div><div class=""><br class=""></div><div class="">You can see the relevant bits of the code in question here:</div></div><div><br class=""></div><div><a href="https://github.com/bustoutsolutions/siesta/blob/e29a5967e7c7e223377107ff2bdc53180f0d2951/Source/Support/ARC%2BSiesta.swift" class="">https://github.com/bustoutsolutions/siesta/blob/e29a5967e7c7e223377107ff2bdc53180f0d2951/Source/Support/ARC%2BSiesta.swift</a></div><div><br class=""></div><div>Cheers,</div><div><br class=""></div><div>Paul</div><div><br class=""></div></body></html>