<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="">Is is possible that the compiler optimized away the call to trigger because it reasoned that you were not really changing any state at all? Because the trigger function is making an assignment of input to output, and the call instance is asking to make a copy of itself, the compiler could reason that after the call to trigger nothing really changes and there are no side effects, thus, no need to generate the function call instance.<div class=""><br class=""></div><div class="">Jonathan<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 28, 2017, at 3: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 class=""><br class=""></div><div class="">Regards,</div><div class="">David.</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 27 Jul 2017, at 21:33, Kyle Murray <<a href="mailto:kyle_murray@apple.com" class="">kyle_murray@apple.com</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; line-break: after-white-space;" class="">Hi David,<div class=""><br class=""></div><div class="">Are <font face="Menlo" class="">padding</font> or <font face="Menlo" class="">spacing</font> computed properties that access either rectangle? They aren't defined in your stripped down code. For example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "SF Mono"; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">var</span> spacing: <span style="color: #703daa" class="">CGFloat</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "SF Mono"; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">return</span> imageRect.maxX</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "SF Mono"; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">Without doing something like that, I don't see the same access conflicts that you're seeing.</div><div class=""><br class=""></div><div class="">-Kyle</div><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jul 27, 2017, at 5:04 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="">In Xcode 9 beta 4, Swift 4, I’m getting runtime errors popping up for Simultaneous accesses and I think they may be false negatives. Here’s a stripped down version of my code:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">class MyButton: UIButton {</font></div><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>fileprivate var imageRect: CGRect = .zero<br class=""></font><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fileprivate var titleRect: CGRect = .zero</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""> func updateRects() {</font></div><div class=""><font face="Menlo" class=""> if imageBeforeTitle {</font></div><div class=""><font face="Menlo" class=""> layoutHorizontally(leftRect: &imageRect, rightRect: &titleRect)</font></div><div class=""><font face="Menlo" class=""> } else {</font></div><div class=""><font face="Menlo" class=""> layoutHorizontally(leftRect: &titleRect, rightRect: &imageRect)</font></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""> func layoutHorizontally(leftRect: inout CGRect, rightRect: inout CGRect) {</font></div><div class=""><font face="Menlo" class=""> leftRect.origin.x = padding</font></div><div class=""><font face="Menlo" class=""> rightRect.origin.x = leftRect.maxX + spacing</font></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">While the layoutHorizontally method has two CGRect inout parameters, never in my code do I pass the same CGRect. Any ideas if this is a bug I should post on <a href="http://bugs.swift.org/" class="">bugs.swift.org</a> or if I’m missing something?</div><div class=""><br class=""></div><div class="">David.</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>