20648, "mppf", "what should we do with owned.create and shared.create?", "2022-09-07T14:14:48Z"
Today we have these functions:
proc type owned.create(in take: owned) // Case 1
proc type owned.create(p : unmanaged) // Case 2
proc type shared.create(in src: shared) // Case 1
proc type shared.create(p : unmanaged) // Case 2
proc type shared.create(in take: owned) // Case 3
These were added in PR #15119 to replace even stranger syntax.
They fall into 3 cases:
Using create to make a copy of an owned/shared value. This is the same as copy initializing e.g. with var x = myOwned. This form is arguably redundant and confusing.
Using create to make an owned/shared that manages an unmanaged pointer. As far as I know, there is no other way of writing this today.
Using create to create a shared from an owned that takes the responsibility for managing that memory. This can be done with a cast today (with some limitations -- see #20647). Previously, it could also be done in initialization or assignment (e.g. var x: shared MyClass = myOwned). However, that was removed in PR #20492 since it was deemed to be too subtle.
In some previous discussion about this, it was argued that we should remove create. One reason for doing so is to enable authors of classes to make their own type method called create and then call it on owned/shared types (e.g. (owned MyClass).create()). See also issue #20336. However, I have not yet seen discussion about how to handle case (2) above if owned.create(myUnmanagedPtr) / shared.create(myUnmanagedPtr) are not the way.