<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div><div><div>Most of the front-end language types hang out in cfe-dev, so you're more likely to get a response there. I've CCed that list, so no need to re-send.</div><div><br></div><div>-Jim</div><div><br></div><div>On Oct 2, 2012, at 8:35 AM, Iaroslav Pavlov <<a href="mailto:iaroslav.pavlov@gmail.com">iaroslav.pavlov@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi guys,<div><br></div><div><div>I've been using blocks for a while and found that current behavior is error prone. So I am going to propose to you the better one.</div><div><br></div><div><b>Motivation:</b></div><div><br></div><div>1) The __weak variables in blocks are very common pattern. So having any implicit default behavior makes thing worse.</div><div>2) Some stupid mistakes like: </div><div><br></div><div>__weak typeof (self) theSelf = self;</div><div><br></div><div>...^ {</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span>theSelf.blabla = ..</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span>....</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">  </span>[self blabla];  // ups, calling self directly is an error</div><div>        _ivar = … // or implicit call to self.</div><div>}</div><div><br></div><div>Retain cycles are very hard to find. I am not saying about trivial ones, that compiler can find, or the Leaks tool. Recently I have 3 retain cycles in my program, no one appeared in Leaks. So the main point is prevent such errors at first place, not to rely on that tool will find it. </div><div><br></div><div><b>Proposition: </b></div><div><br></div><div>Any variable captured in block must have explicit qualifier to specify memory capturing semantic: <b>__retain</b>, <b>__weak</b>, <b>__unsafe_unretained</b>. Qualifier is obligatory, no defaults allowed.</div><div><br></div><div>Code will look something like this:</div><div><br></div><div>1) </div><div>NSString* theLocalVariable = …</div><div><br></div><div>...^ {</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>...</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span><b>__weak</b> self;</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>self.blabla  =  ...</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>…</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>[self blabla:(__retain theLocalVariable)];</div><div>}</div><div><br></div><div>2)</div><div>{</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>self.blabla = … // <span style="color: rgb(233, 36, 2); ">compile error: missing memory capture semantic qualifier.</span></div><div><span class="Apple-tab-span" style="white-space: pre; ">     </span>....</div><div>}</div><div><br></div><div>For <b>__block</b> qualifier I propose to leave old behavior (leave the default <b>__retain</b> semantic), because retain cycles with write-to variables are uncommon.</div><div><br></div><div>Regards,</div><div>Yaroslav.</div></div></div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br></div></body></html>