<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You’re “safe" here: in a library with resilience enabled, protocol extension methods are not emitted into the client unless they’re marked @inlinable (or however that ends up being spelled when we’re done with SE-0193).<div class=""><br class=""></div><div class="">That said, you can’t be sure someone didn’t just implement their own ‘contrive()' if you put it in the protocol; if you want to defend against that you’d have to <i class="">not</i>&nbsp;put it in the protocol (and just provide the extension method for convenience).</div><div class=""><br class=""></div><div class="">Since you mentioned Collection and the standard library, I’ll also point out that the stdlib team <i class="">is</i>&nbsp;planning to make a lot of these methods inlinable, since they can benefit a lot from specialization (and just normal inlining, especially the ones with callbacks). That doesn’t preclude changing the implementation later, but <i class="">both</i> implementations may end up being used at run time. Still, this seems totally fine for something like ‘reduce’ that’s a pure function.</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 10:25, Philippe Hausler 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=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Given the tentative ideas already being worked on for ABI stability what would be the place that code associated with a default implementation of a method on a protocol live?<div class=""><br class=""></div><div class="">e.g.</div><div class=""><br class=""></div><div class="">FooKit has some code that is similar to this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">struct</span> SomeOptions : <span style="color: #eedb04" class="">RawRepresentable</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(253, 67, 132); background-color: rgb(43, 43, 43);" class=""><span style="color: #ede8e5" class="">&nbsp; &nbsp; </span>public<span style="color: #ede8e5" class=""> </span>private(set)<span style="color: #ede8e5" class=""> </span>var<span style="color: #ede8e5" class=""> rawValue: </span><span style="color: #eedb04" class="">Int</span></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">init</span>(rawValue: <span style="color: #eedb04" class="">Int</span>) { <span style="color: #fd4384" class="">self</span>.<span style="color: #76e0f2" class="">rawValue</span> = rawValue }</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43); min-height: 20px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">static</span> <span style="color: #fd4384" class="">let</span> sensible = <span style="color: #eedb04" class="">SomeOptions</span>(rawValue: <span style="color: #f57fff" class="">1</span> &lt;&lt; <span style="color: #f57fff" class="">0</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">static</span> <span style="color: #fd4384" class="">let</span> maybeWillBeBetterLater = <span style="color: #eedb04" class="">SomeOptions</span>(rawValue: <span style="color: #f57fff" class="">1</span> &lt;&lt; <span style="color: #f57fff" class="">1</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(43, 43, 43); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">protocol</span> Somethingable {</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive()</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive(options: <span style="color: #eedb04" class="">SomeOptions</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(43, 43, 43); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(238, 219, 4); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">extension</span><span style="color: #ede8e5" class=""> </span>Somethingable<span style="color: #ede8e5" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive() { <span style="color: #ff7627" class="">contrive</span>(options: .<span style="color: #76e0f2" class="">sensible</span>) }</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div></div><div class=""><br class=""></div><div class="">Then later on in a newer version of FooKit&nbsp;maybeWillBeBetterLater is now MUCH better and should be the default option so the code is updated to look like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">struct</span> SomeOptions : <span style="color: #eedb04" class="">RawRepresentable</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(253, 67, 132); background-color: rgb(43, 43, 43);" class=""><span style="color: #ede8e5" class="">&nbsp; &nbsp; </span>public<span style="color: #ede8e5" class=""> </span>private(set)<span style="color: #ede8e5" class=""> </span>var<span style="color: #ede8e5" class=""> rawValue: </span><span style="color: #eedb04" class="">Int</span></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">init</span>(rawValue: <span style="color: #eedb04" class="">Int</span>) { <span style="color: #fd4384" class="">self</span>.<span style="color: #76e0f2" class="">rawValue</span> = rawValue }</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43); min-height: 20px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">static</span> <span style="color: #fd4384" class="">let</span> sensible = <span style="color: #eedb04" class="">SomeOptions</span>(rawValue: <span style="color: #f57fff" class="">1</span> &lt;&lt; <span style="color: #f57fff" class="">0</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">static</span> <span style="color: #fd4384" class="">let</span> maybeWillBeBetterLater = <span style="color: #eedb04" class="">SomeOptions</span>(rawValue: <span style="color: #f57fff" class="">1</span> &lt;&lt; <span style="color: #f57fff" class="">1</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(43, 43, 43); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">public</span> <span style="color: #fd4384" class="">protocol</span> Somethingable {</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive()</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive(options: <span style="color: #eedb04" class="">SomeOptions</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(43, 43, 43); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(238, 219, 4); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">extension</span><span style="color: #ede8e5" class=""> </span>Somethingable<span style="color: #ede8e5" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">&nbsp; &nbsp; <span style="color: #fd4384" class="">func</span> contrive() { <span style="color: #ff7627" class="">contrive</span>(options: .<span style="color: #76e0f2" class="">maybeWillBeBetterLater</span>) }</div><div style="margin: 0px; font-stretch: normal; font-size: 17px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class="">}</div></div><div class=""><br class=""></div><div class="">For apps compiled with FooKit when they are run with the new version of FooKit do they get the behavior of sensible or maybeWillBeBetterLater?&nbsp;</div><div class=""><br class=""></div><div class="">Basically this is a question of where will the code for protocol extensions that are adopted across module boundaries live?</div><div class=""><br class=""></div><div class="">This interestingly applies to things like Collection and other standard library protocols and has some potential drawbacks and benefits from either way of it possibly working.</div><div class=""><br class=""></div><div class="">Thanks in advance for indulging my curiosity.</div><div class="">Philippe</div></div>_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></div></body></html>