<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 Dec 16, 2015, at 10:34 AM, John McCall 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="" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;" class="">On Dec 16, 2015, at 12:12 AM, Dave Abrahams via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class="">On Dec 15, 2015, at 11:51 PM, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:<br class="">On Tue, Dec 15, 2015, at 11:25 PM, Dave Abrahams wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On Dec 15, 2015, at 6:46 PM, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:<br class=""><br class="">On Tue, Dec 15, 2015, at 06:39 PM, Dave Abrahams wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On Dec 15, 2015, at 6:33 PM, Kevin Ballard via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class="">On Tue, Dec 15, 2015, at 03:03 PM, Joe Groff via swift-dev wrote:<br class=""><blockquote type="cite" class=""><br class="">Yeah, it seems to me like a reasonable refinement for 'withUnsafePointer' to take an immutable parameter. Since this is a stdlib API change, you should suggest that on swift-evolution.<br class=""></blockquote><br class="">A change like that is going to break any code that relies on the inout optimization (where it uses call-by-reference instead of copy-in copy-out when possible). Yes, such code is in violation of Swift semantics today, but it does work.<br class=""></blockquote><br class="">Two questions:<br class=""><br class="">1. Don’t we want a withUnsafeMutablePointer for the mutating cases (where the inout optimization can take effect) anyway?<br class=""></blockquote><br class="">I'm thinking here of cases like passing a context pointer to KVO. You're not actually mutating it, you just need a pointer that's the same every time you call the code.<br class=""></blockquote><br class="">Well, it is not possible to code a version of withUnsafePointer that makes that guarantee in Swift.<br class=""></blockquote><br class="">Yeah but we want to move in the direction of making that more reliable, not less.<br class=""></blockquote><br class="">I am not sure I agree with you. &nbsp;I would defer to John McCall on this one, but my understanding is that it's an explicit non-goal to make that guarantee.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px; float: none; display: inline !important;" class="">I think it’s useful to be able to make this guarantee for some variables; I just don’t want it to be assumed for all variables. &nbsp;I’m okay with the idea that &amp;myGlobalStoredVar will consistently yield the same pointer.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;" class=""></div></div></blockquote></div><br class=""><div class="">I agree we can make that guarantee for globals, and maybe local stored properties as well. It's tricky to do that for potentially computed properties, which includes any class properties or properties outside your resilience domain, so though we can make a best effort not to wantonly change pointer identity across calls that take pointers to the same property, I don't think we can fully eliminate the need for an explicit withUnsafePointer form.</div><div class=""><br class=""></div><div class="">-Joe</div></body></html>