[swift-dev] isUniquelyReferenced issues

Andrew Trick atrick at apple.com
Fri Apr 1 18:10:28 CDT 2016


> On Apr 1, 2016, at 8:43 AM, Joe Groff via swift-dev <swift-dev at swift.org> wrote:
> 
> 
>> On Mar 31, 2016, at 11:49 PM, Patrick Pijnappel <patrickpijnappel at gmail.com> wrote:
>> 
>> The modified version doesn't seem to change any of the results (on -O or -Onone). Note that the problem is that it's not uniquely referenced inside bar where it actually should be – that would mean that ownership is currently not directly transferred right?
> 
> You're right, I'm sorry, I misread your original comment. If the ARC optimizer didn't transfer ownership, then it is correct for `isUniquelyReferenced` to be false inside `bar`, since the `foo` inside of `test` and the `foo` parameter to `bar` are semantically independent values. If this weren't the case, then `bar` could modify a COW value type and have its changes be seen back in `test`'s copy.

In other words, to avoid a copy, the COW value must be passed ‘inout’. This is normally true anyway for functions that mutate the value.

It would be neat to have a ‘move’ operator that handed ownership of the COW value off to the callee. But the memory safety of that would be problematic in general.

-Andy


More information about the swift-dev mailing list