<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 Jul 28, 2017, at 12:06 AM, David Hart via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@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="">Hello,<div class=""><br class=""></div><div class="">Indeed, I had reduced the code too much. John McCall was kind enough to have a look and here’s the offending code:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">func layoutHorizontally(leftRect: inout CGRect, rightRect: inout CGRect) {<br class=""> let totalWidth = imageRect.size.width + titleRect.size.width + contentSpacing<br class=""> rightRect.origin.x = leftRect.maxX + contentSpacing<br class="">}</font></div><div class=""><br class=""></div><div class="">The problem is that <font face="Menlo" class="">imageRect</font> and <font face="Menlo" class="">titleRect</font> are referenced both directly and in the inout parameters.</div><div class=""><br class=""></div><div class="">But there’s something I’m not understanding. I went back to the ownership manifesto and re-read the law of exclusivity to make sure I understand it:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><i class="">If a storage reference expression evaluates to a storage reference that is implemented by a variable, then the formal access duration of that access may not overlap the formal access duration of any other access to the same variable unless both accesses are reads.</i></div></blockquote><div class=""><br class=""></div><div class="">So I tried to write a test to trigger the runtime error, but was unsuccessful:</div><div class=""><br class=""></div><font face="Menlo" class="">class MyClass {<br class=""> var p: CGRect = .zero<br class="">}<br class=""><br class="">func trigger(a: MyClass, b: MyClass) {<br class=""> a.p = b.p<br class="">}<br class=""><br class="">let m = MyClass()<br class=""></font><div class=""><font face="Menlo" class="">trigger(a: m, b: m)</font></div><div class=""><br class=""></div><div class="">Here, a storage reference expression (a.p) evaluates to a storage reference that is implemented by a variable (the p property of an instance m of MyClass) and its formal access duration (the trigger function) overlaps the formal access duration of another access to the same variable (through the b.p storage reference expression) and both accesses are not reads (a.p is on the LHS of an assignment).</div><div class=""><br class=""></div><div class="">Why does this not trigger the Law of Exclusivity?</div></div></div></blockquote><br class=""></div><div>`b.p` is loaded before `a.p` is written to, so the accesses do not overlap even when a === b. Something like swap(&a.p, &b.p) (using the Swift 3 global definition of 'swap') would trigger an exclusivity trap when a === b, since the access to storage passed as an inout argument needs to last for the duration of the call.</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>