> On Apr 1, 2016, at 4:10 PM, Andrew Trick via swift-dev <swift-dev@swift.org> > wrote: >> On Apr 1, 2016, at 8:43 AM, Joe Groff via swift-dev <swift-dev@swift.org> >> wrote: >> >> >>> On Mar 31, 2016, at 11:49 PM, Patrick Pijnappel >>> <patrickpijnap...@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. _______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev