On Aug 2, 2012, at 5:28 PM, John McCall <[email protected]> wrote:

> On Aug 2, 2012, at 2:38 PM, Jordan Rose wrote:
>> On Aug 2, 2012, at 14:37 , jahanian <[email protected]> wrote:
>>> On Aug 2, 2012, at 2:23 PM, Jordan Rose wrote:
>>> 
>>>> How about the other case? Can we avoid offering fixits for transferring 
>>>> globals in and out of ARC? I wouldn't stop a developer from writing it 
>>>> deliberately, but it seems very unlikely to be the correct solution in a 
>>>> case where they just forgot the cast.
>>> 
>>> Maybe I was not clear. I am using an existing API to decide when to provide 
>>> fixit and when not. According to ARCCastChecker which enforces the
>>> rules, we issue the fix-it warning unless global is in system header file. 
>>> Please talk to John if you feel this behavior should change.
>> 
>> Yes, I got that for why the type sucks; this time I was indeed suggesting a 
>> change to our heuristics about what's a good possible cast. John?
> 
> I'm not totally clear on what you're proposing.  Are you suggesting that we 
> should suggest a non-bridging cast when the source is a "global"?

We should suggest a non-transferring cast, i.e. __bridge is okay but 
CFBridgingRetain/Release are probably not. If I really try I can come up with 
scenarios where it'd be okay to bridge-transfer things out of globals (when 
you're changing the global but still need the old value around for a bit) but 
95% of the time we're probably talking about global constants like 
kCFBundleNameKey, for which the only  sensible thing to do is __bridge because 
you don't own them. You'd break the global if you did that.

I'm not saying we should stop accepting the code, just taking it out of the 
fixit. Think of it this way: how often do you CFRelease a global? It happens, 
but it's much more likely than not to break your code.

I know ARC's been out for quite a while now, but I think that people will see 
the two suggestions and have one of two reactions: (a) "bridge casts are hard! 
which one of these should I use?" (and hopefully not "I'll try the pretty 
function-like one first"), and (b) "why would you even suggest 
CFBridgingRetain/Release here?"

What do you think?
Jordan

P.S. This heuristic can probably also be applied to static locals. I wish it 
could be applied to parameters, but then we have to get a lot smarter about 
what parameters we own and what we don't. I'm not sure how NS_CONSUMED works 
under ARC.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to