[Pitch] SE-0377 Amendment: Making `borrowing` and `consuming` parameters require manual copying with a `copy` operator

Fascinating, my confusion is probably due to my experience with Rust, since rust will implicitly copy anything that is Copy when passed as an argument, and since Swift implicitly makes everything Copyable I had assumed it was always copying passed in values. It actually sounds like Swift is implicit copy and implicit borrow based on circumstance. Is this documented?

Knowing this I think the above makes enough sense. I think ownership documentation would be benefited by clear documentation on implicit copy and implicit borrow semantics as well then.

Just to throw this out there, what about a sigil such as implicit x (name pending) if an argument is being passed into a function that has implicit binding behavior? I'm not sure I'm sold on this myself, on the other hand there's still something that very much irks me about writing a function with explicit ownership semantics and then any called function may not entirely respect the intent. Something nice about Rust is one can usually tell just by the call-site what some of the performance implications of a function are based on the argument bindings (like if it's expecting a reference then it's probably not getting copied/cloned). I suppose one way to get around it is, if there is no explicit ownership binding for the argument of the function, just assume the value passed in gets copied internally and act accordingly (edit it or write a different function or github issue or just accept it, etc.).

I've written up a proposal for this change, and edited the top post to reference it:

3 Likes

After discussion with the Language Workgroup, they requested that I recast this as an amendment to SE-0377 rather than a whole new proposal. I've updated the linked PR to be an update to SE-0377.

3 Likes