You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
Thought about the Dict for a while,
it would be nice to be able to move a value out of __del__() (because it is a place where struct can be not whole).
Maybe a new taking del could help with return DictEntry.value^ ?
You cannot make this specifically a 'del' but you can already make consuming methods, and they can return values. You have to explicitly disable the destructor of 'self' or else it will be called, which is the trick. This is equivalent to Rust's "mem::forget". We don't have syntax for this, but you can write it out manually with mlir magic:
fn take_value(owned self) -> V:
# don't run the destructor on 'self'
__mlir_op.`lit.ownership.mark_destroyed`(__get_mvalue_as_litref(self))
# Can now pillage the pieces of 'self' that I want. Any unused subfields
# will be individual destroyed.
return self.some_part^
Review Mojo's priorities
What is your request?
Thought about the
Dict
for a while,it would be nice to be able to move a value out of
__del__()
(because it is a place where struct can be not whole).Maybe a new taking del could help with return DictEntry.value^ ?
An example of what could be accomplished:
(Not sure about the decorator)
What is your motivation for this change?
Having
DictEntry.value
as anOptional
could be the thing,but since performance is a priority, maybe it would become slower ? (no benchmarks done)
The challenge is to be able to take the value field of a
DictEntry
as an owned value,that way, users would not get a copy when doing
Dict.pop("")
and it could fix #2756 .It is possible that it returns the value as a copy, because
return entry_value.value^
is different thanreturn entry_value^.value^
.Reference to #2756
Please have a look at the
Dict.pop
, it is weird that we are doingreturn entry_value.value^
,how can the value entry_value be destroyed if it is not whole ? (Documentation: field lifetimes)
This might be the source of the double free ?
Any other details?
No response
The text was updated successfully, but these errors were encountered: