[swift-dev] isUniquelyReferenced issues

John McCall rjmccall at apple.com
Fri Apr 1 19:22:17 CDT 2016


> On Apr 1, 2016, at 4:10 PM, Andrew Trick via swift-dev <swift-dev at swift.org> wrote:
>> 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.

It could be supported on local variables, which would probably be good enough.  DI would just ensure that the value wasn't used after that point.  Similar DI work will be necessary in the long run anyway to implement unique-ownership types.

John.


More information about the swift-dev mailing list