<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 20, 2017, at 2:56 PM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On Feb 20, 2017, at 2:50 PM, Michel Fortin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Le 20 févr. 2017 à 14:45, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; a écrit :<br class=""><br class=""><blockquote type="cite" class=""><br class="">On Feb 20, 2017, at 1:42 PM, Michel Fortin &lt;<a href="mailto:michel.fortin@michelf.ca" class="">michel.fortin@michelf.ca</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Le 20 févr. 2017 à 14:23, Charles Srstka &lt;<a href="mailto:cocoadev@charlessoft.com" class="">cocoadev@charlessoft.com</a>&gt; a écrit :<br class=""><br class="">I’m not sure how I feel about that, since it hamstrings the ability to improve APIs in a lot of ways without breaking backwards compatibility. A quick example off the top of my head would be all the Cocoa APIs that started out having ivars representing paths backed by simple getter methods, and were later refactored to be URL-based, but with the original path properties become computed properties pointing to the URL’s “path” property. With this, properties would not be able to be refactored in this way unless the library developer had previously declared the “path” property as private(set), which is unlikely for a property that was not intended to be changed after the class was initialized.<br class=""></blockquote><br class="">Version 1:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>public class A {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>public let path: String<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<br class=""><br class="">Version 2:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>public class A {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>public pure var path: String { return url.path }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span>public let path: URL<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<br class=""><br class="">This is assuming `let` is implicitly pure. It probably should not be. Or at least it should not when crossing module boundaries. Note that internal to the module it wouldn't violate any contract to allow pure code access to `let` variables.<br class=""><br class="">Which makes me think of an idea: internal to the module, `pure` could be inferred for everything. Only the published APIs would require the annotations, and only if you want `pure` to be part of the API contract. Attaching `pure` to an internal function could still be useful for your own reasoning though.<br class=""></blockquote><br class="">That’s a very interesting approach that could lighten the syntactic load. &nbsp;We could strategically annotate our code where we want purity verified, but otherwise omit the annotation for members that don’t need to be visible outside the module. &nbsp;This approach works especially well for closures. &nbsp;I like it a lot!<br class=""></blockquote><br class="">There is an important limitation to this though: a class method that mutate something in the class is never going to be implicitly pure (per the rules of purity for instance methods). For that the compiler would have to prove the method is only called from unique references, and that'd be a bit weird (add a method call somewhere and suddenly the function becomes impure).<br class=""><br class="">There's also an issue with diagnostics: say you have func1 that calls func2 that calls func3. Func1 is `pure`, the other two are pure only implicitly. Then you change something in func3, and suddenly func1 complains that it can't call impure func2 and you are left wondering why because you haven't changed anything in func2. Perhaps the compiler could dig in the call tree to find the impure operation and tell you, but that's starting to look like the awful diagnostic messages for C++ templates.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Could we only infer purity for one “level”? As a technical limitation rather than part of the language spec, to be removed at some later date when we have time to implement the diagnostic logic? So in your example, the purity of func2 or func3 could be inferred, but the other would have to be annotated.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">- Dave Sweeris</span></div></blockquote><br class=""></div><div>It seems like there's a parallel to 'throws' here, where the unknown throwy-ness of a function has to be dealt with for closures with 'rethrows'. Pie in the sky, perhaps, but it'd be interesting to see what a generalized effects system would look like for Swift, ideally subsuming both of those and allowing for many others.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>David</div><br class=""></body></html>