Proposal to change the default ownership for passing parameters

Hi Eric,

Sorry for the delay getting back to you. IMO your plan makes perfect sense, I'd love to see this, and I agree with your special case for setters. I expect it falls out of this change, but please make sure that varargs list arguments are also +0 values :-) Thanks!

-Chris

It would certainly be best if the array was passed +0, but the current code-generation pattern on varargs does require all the elements to be copied so that they can be stored into the array.

The expressions passed into the varargs list are only used by that varargs list, so they should be movable, no?

EDIT: Oh, right, that's only if the expression is produced as a +1 value itself. If it is a borrowed value, then this doesn't work. The right model is probably a borrowed array for varargs. How's ownership going? :-)

-Chris

Heh. To answer seriously: for move-only parameters, the tentative plan is that we'll require functions to be explicit about ownership, because it's very semantically important. (We can continue to default methods to borrowing, of course.) The ideal result for varargs would be to do the same thing: basically, either the entire varargs array is borrowed or owned. The biggest problem there is that I don't really know how to make an array of borrowed values! That's not something that our intentionally-simplified ownership system actually supports; we'd really need the varargs collection to be a more abstracted collection type than just Array, something where we can easily kick in arbitrary code to do a copy if the user requests one (which, given an array of actually move-only types, they can't, but presumably this also should work as an optimization for copyable types).

Ok, right. I agree that there isn't a simple way to avoid copying the elements in the general case. It seems reasonable to give up that hope, it will be no worse than our +1 arguments currently are at least.

Will arrays of move-only types work? Will we be able to pass move-only types through varargs?

Yeah. The array becomes move-only itself, of course.

We should still look into making it so that varargs don't pass an Array at the ABI boundary too.

1 Like

+1!!