Allow Refs
as members in user defined types
#1022
Labels
memory
Borrow checker and lifetimes
nice-to-have
under discussion
Things we've not come to a conclusion about.
In some cases, our lack of support for
Refs
as members of user defined types can result in ownership problems. In particular, when mapping anonymous functions over the inhabitants of some typet
these functions may need to take ownership when doing so is either not necessary or can lead to memory errors such as double frees. In particular, this can happen when currying lambdas, causing more than one lambda to capture the same value.#997 (comment) has a concrete illustration of this issue.
Should we permit
Refs
in user defined types? In theory there should be no issue doing so for sumtypes. For product types, thegetters
become a bit hairy. The current signature of getters is as follows:When
t
is a reference, the signature concretizes to:So, if we do want to support this, we'd have to determine precisely what a
Ref
to aRef
means, what copying it looks like, how (if at all) that affects ownership, etc.Note: There is already a workaround to this behavior using
Ptr
types.Ptrs
behave similarly toRef
s but are unmanaged, ensuring that problems arising from the anonymous function ownership described above can be circumvented--the user just needs to free these pointers manually in the capturing functions.The text was updated successfully, but these errors were encountered: