<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=""><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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 6, 2017, at 12:36 PM, John McCall via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 6, 2017, at 1:11 PM, Félix Cloutier via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" 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-stroke-width: 0px;">Concern: `swap` is quoted a lot for a method that would break under this rule, but as it happens, `swap` with the same value on both sides is (should be) a no-op. Is there a way to not trip the static or dynamic checkers in well-defined cases like that one? Is there any way to check that two inout parameters refer to the same value?</div></div></blockquote></div><div class=""><div class=""><br class=""></div>The only reasonable way to do this is statically, and why would you call 'swap' statically with the same l-value for both arguments?</div></div></div></blockquote><div class=""><br class=""></div><div class="">When static analysis can determine that a swap is <i class="">always</i> a noop, I can’t see any reason not to flag it as an error.</div><div class=""><br class=""></div><div class="">But Félix’s question was also about the runtime case. And he has a good point.</div><div class=""><br class=""></div><div class="">Here’s a compelling example where allowing the noop swap would make sense:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(50, 62, 125);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">mutating</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> shuffle() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> i </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">indices</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> j = i + </span><span style="font-variant-ligatures: no-common-ligatures" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">arc4random_uniform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">UInt32</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">count</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> - i)))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">swap</span><span style="font-variant-ligatures: no-common-ligatures" class="">(&</span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[i], &</span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">[j])</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">In this code:</div><div class=""><br class=""></div><div class=""><ul class="MailOutline"><li class="">It’s necessary to allow j to sometimes equal i to get a uniform distribution of random permutations.</li><li class="">Static analysis can’t determine that the noop occurs sometimes but not always.</li><li class="">Adding a check for i == j adds a branch condition to a tight loop. More importantly, it’s easy to forget this check since static analysis won’t flag it. It’s just a hidden land mine, which seems contrary to Swift’s “safety first” aesthetic.</li></ul><div class=""><br class=""></div></div><div class="">Putting all that together, it would probably be more Swift-like to have swap() be safe, and if necessary add an unsafeSwap() func that fails on the noop case and thus avoids the cost of the check in optimized code.</div><div class=""><br class=""></div><div class=""><div class="">Note that the code above fails even under Swift 3, which explicitly disallows swapping with a runtime check (“fatal error: swapping a location with itself is not supported”). So nothing here to undermine the SE-0176; the proposal isn’t introducing a problem that doesn’t already exist.</div></div><div class=""><br class=""></div><div class="">Cheers, P</div></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">John.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><br class="" 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-stroke-width: 0px;"><div 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-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">Le 2 mai 2017 à 13:07, Ben Cohen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><p class="" style="-webkit-print-color-adjust: exact; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255); margin-top: 0px !important;">Hello Swift community,</p><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; background-color: rgb(255, 255, 255);"><span class="" style="font-family: -apple-system-body, Helvetica, arial, sans-serif;">The review of SE-0176: "</span><font face="-apple-system-body, Helvetica, arial, sans-serif" class="">Enforce Exclusive Access to Memory"</font><span class="" style="font-family: -apple-system-body, Helvetica, arial, sans-serif;"> begins now and runs through May 8, 2017.</span></p><div class=""><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">The proposal is available here:</p><div class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md</a></div></div><div class=""><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at:</p><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">or, if you would like to keep your feedback private, directly to the review manager. </p><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">When replying, please try to keep the proposal link at the top of the message:</p><blockquote class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; border-left-width: 4px; border-left-style: solid; border-left-color: rgb(221, 221, 221); padding: 0px 15px; background-color: rgb(255, 255, 255);"><h3 id="toc_0" class="" style="color: rgb(119, 119, 119); font-family: -apple-system-body, Helvetica, arial, sans-serif; -webkit-print-color-adjust: exact; margin: 0px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px;">Proposal link:</h3><div class=""><font color="#777777" face="-apple-system-body, Helvetica, arial, sans-serif" class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md</a></font></div><div class=""><h3 id="toc_1" class="" style="color: rgb(119, 119, 119); font-family: -apple-system-body, Helvetica, arial, sans-serif; -webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px;"><div class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px;">Reply text</div><div class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px;"><br class=""></div><blockquote class="" style="font-weight: normal; box-sizing: border-box; margin: 0px 0px 16px; padding: 0px 1em; color: rgb(106, 115, 125); border-left-width: 0.25em; border-left-style: solid; border-left-color: rgb(223, 226, 229); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px;"><div class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px;">Other replies</div></blockquote></h3><h5 class="" style="box-sizing: border-box; margin-top: 24px; margin-bottom: 16px; font-size: 0.875em; line-height: 1.25; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';"><a id="user-content-what-goes-into-a-review-1" class="anchor" href="https://github.com/apple/swift-evolution#what-goes-into-a-review-1" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(3, 102, 214); text-decoration: none; float: left; padding-right: 4px; margin-left: -20px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a></h5></div></blockquote></div><div class=""><h3 id="toc_2" class="" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 18px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">What goes into a review?</h3><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:</p><ul class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; padding-left: 30px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);"><li class="" style="-webkit-print-color-adjust: exact; margin: 0px;">What is your evaluation of the proposal?</li><li class="" style="-webkit-print-color-adjust: exact; margin: 0px;">Is the problem being addressed significant enough to warrant a change to Swift?</li><li class="" style="-webkit-print-color-adjust: exact; margin: 0px;">Does this proposal fit well with the feel and direction of Swift?</li><li class="" style="-webkit-print-color-adjust: exact; margin: 0px;">If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li><li class="" style="-webkit-print-color-adjust: exact; margin: 0px;">How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);">More information about the Swift evolution process is available at:</p><p class="" style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: -apple-system-body, Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);"><a href="https://github.com/apple/swift-evolution/blob/master/process.md" class="" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);">https://github.com/apple/swift-evolution/blob/master/process.md</a></p></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Ben Cohen</div><div class="">Review Manager</div><div class=""><br class=""></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="" 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-stroke-width: 0px;"><span 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-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br 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-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; 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="">swift-evolution mailing list</span><br 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-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></body></html>