<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="">Seems to me that we can find similar information just from walking over a class's fields to build an ownership graph, and cause warnings/errors when you find a strong cycle.<div class=""><br class=""></div><div class="">How do you deal with type erasure?<div class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">protocol Foo {}</div><div class="">class A {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var foo: Foo</div><div class="">}</div><div class="">class B: Foo {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var a: A</div><div class="">}</div></blockquote><blockquote type="cite" class="">// A and B can have a cycle through the Foo protocol</blockquote><div class=""><br class=""></div>Also, how do you encode that your example's "addCallback" closure parameter can't have a strong reference to `self`?<br class=""><div class=""><br class=""></div><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 29 juil. 2016 à 18:42:11, Andrew Bennett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I'd like an <b class="">opt-in</b> way to verify and prevent&nbsp;<b class="">unintentional strong references</b> in Swift.</div><div class=""><br class=""></div><div class="">This can be used to verify ownership structures, and ultimately avoid retain cycles.<br class=""></div><div class=""><br class=""></div><div class="">Read a draft proposal here:</div><div class=""><a href="https://github.com/therealbnut/swift-evolution/blob/therealbnut-explicit-ownership/proposals/NNNN-explicit-ownership-type-attribute.md" class="">https://github.com/therealbnut/swift-evolution/blob/therealbnut-explicit-ownership/proposals/NNNN-explicit-ownership-type-attribute.md</a><br class=""></div><div class=""><br class=""></div><div class=""><div class="">TL;DR:</div><div class=""><br class=""></div><div class=""><div class="">If you have any questions please read the proposal before asking here.</div></div><div class=""><br class=""></div><div class=""><div class="">It's an opt-in attribute that defines a whitelist of types something can own. For example:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="color:rgb(187,44,162)" class="">@owns</span>(TypeA, TypeB)&nbsp;<span style="color:rgb(187,44,162)" class="">struct&nbsp;</span>TypeC { ... }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><br class=""></div></div></div></div><div class="">I wrote this a few months ago, but we weren't accepting additive proposals. Now we're explicitly looking for something like this:</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="white-space: pre-wrap;" class="">Memory ownership model: Adding an (opt-in) Cyclone/Rust inspired memory ownership model to Swift is highly desired by systems programmers and folks who want predictable and deterministic performance (for example, in real time audio processing code).  More pertinent to the goals of Swift 4, this feature is important because it fundamentally shapes the ABI.  It informs code generation for “inout", how low-level “addressors” work in the ABI, impacts the Swift runtime, and will have a significant impact on the type system and name mangling.</span>&nbsp;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br class=""></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">&nbsp;-&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160725/025676.html" class="">Chris</a></blockquote><div class=""><br class=""></div><div class="">----</div><div class=""><br class=""></div><div class="">Here's a link to the version of the&nbsp;<a href="https://github.com/therealbnut/swift-evolution/commit/6ab167825d802c7826804e1957eb515d3009743a" class="">proposal</a>&nbsp;when I sent this email.</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></div></div></div></div></div></div></div></body></html>