-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isElementAllocated
/isValueAllocated
/isPayloadAllocated
functions to SeqAccess/MapAccess/VariantAccess interface
#127
Comments
Can you update the proposal so that it includes adding an Not to mention, the consistency would allow me to finally define (in a sane manner) Getty's allocation story during deserialization:
|
isElementAllocated
/isValueAllocated
functions to SeqAccess/MapAccess interfaceisElementAllocated
/isValueAllocated
/isPayloadAllocated
functions to SeqAccess/MapAccess/VariantAccess interface
Sorry for the late response, my availability have been sporadic for the last few days. I have updated the proposal to include |
No worries!
Yep. I had thought I added it to the doc comment for
Right. I think the visitors that Getty define handle incomplete values properly with custom logic. But custom visitors written by users should know that they should use custom logic as well in those cases, so a doc comment would be nice for them. |
I'll assign this to you for now since I think you had some work started already. Let me know if you can't or don't want to do it. I don't mind implementing it 👍 |
Yeah sure, I just need to patch up my changes a bit and add some documentation. |
Problem
There are cases where it is desirable to know whether the last element deserialized by
nextElementSeed
, the last value deserialized bynextValueSeed
or the last variant deserialized bypayloadSeed
is allocated on the heap. For instance, a data structure may apply some transformation to an element to be inserted such that the original value is unneeded, or a data structure may create defensive copies of inserted values making the original values unreachable.I observed this use case while working working on (de)serialization support for std.IndexedSet as part of #120 which translate values inserted into it to indices, making the values themselves ephemeral.
Proposal
Add the functions
isElementAllocated
,isValueAllocated
,isPayloadAllocated
functions to SeqAccess, MapAccess and VariantAccess interface respectively. This allows checking the storage location of a value deserialized from access methods (e.g.,nextKey
) and makes it possible to conditionally free the value only if it is allocated on the heap. Using these functions permit deserialization without an allocator when no allocation would be performed, following the principle of least privilege. For example,Alternatives
Leave the status quo as is, the described problem can be remedied by unconditionally freeing the last deserialized element/values. For example,
This works because types which are not allocated do not implement a free function however it has the consequence of always requiring an allocator for deserialization even if when no allocation would be performed
Additional Context
No response
The text was updated successfully, but these errors were encountered: