-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] mark dict entry as destroyed in Dict.pop()
#2796
Conversation
ok, tests passed locally, but test_reversed is still failing, so this fix may not work |
stdlib/src/collections/dict.mojo
Outdated
return entry_value.value^ | ||
_ = entry_value.key^ | ||
var value = entry_value.value^ | ||
__mlir_op.`lit.ownership.mark_destroyed`( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i imagine it's not since the test_reversed still failed... maybe it's not related, but i was really hoping it was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it did fix a crash locally for me though. (the exmaple given in #2756)
@helehex I made a PR recently fixing the flakyness in |
@helehex, based on #2822 last comment, |
5f7e64b
to
e586986
Compare
Anyone know why this cant go through? last time I checked, |
Is there still an issue with pop on latest nightly? Originally, we were seeing failures around the time you opened this PR, but I thought I remember @gabrieldemarmiesse chasing down the root cause and fixing it. |
I just checked, and the test provided here still fails in the latest nightly. |
Sorry, after reading through this thread again, I realize I should've communicated better what was going on. |
Here's a few notes:
|
Yes, this PR would make it possible the move a value out of the dictionary. I think that what we return now is a weird copy that gets double freed. If we turn we'd have an overhead of So this PR move the value out by scavaging an
The problem that could be a bug (without PR)
Currently, we move the value out, and var entry_value = entry[].unsafe_take() #DictEntry
...
return entry_value.value^ So if the user received an instance of a type that has |
666e623
to
f25d09c
Compare
!sync |
@@ -216,6 +216,15 @@ struct DictEntry[K: KeyElement, V: CollectionElement]( | |||
self.key = other.key | |||
self.value = other.value | |||
|
|||
fn reap_value(owned self) -> V: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this private? I don't expect users to need to interact with this API directly, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I'm not sure actually.
def main():
print(str(take()))
def take() -> String:
var entry = DictEntry[String, String]("a", "b")
return entry.value^
Doing this still causes a segfault and the language server to crash.. do you know if this is a bug, or maybe it should give me an error in the editor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As things are right now, it seems useful to have the function available and documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding __mlir_op.`lit.ownership.mark_destroyed`(__get_mvalue_as_litref(entry))
after entry
is the solution to it, but that's definitely a private function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think this should be private right now.
…ruction of entry_value in `Dict.pop()` Signed-off-by: Max Brylski <[email protected]>
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
…897) [External] [stdlib] mark dict entry as destroyed in `Dict.pop()` Fixes #2756 Co-authored-by: Helehex <[email protected]> Closes #2796 MODULAR_ORIG_COMMIT_REV_ID: d9ee05077d11b2b4b54bdd48d1a67100ab624eee
Landed in 486ff59! Thank you for your contribution 🎉 |
…897) [External] [stdlib] mark dict entry as destroyed in `Dict.pop()` Fixes modularml#2756 Co-authored-by: Helehex <[email protected]> Closes modularml#2796 MODULAR_ORIG_COMMIT_REV_ID: d9ee05077d11b2b4b54bdd48d1a67100ab624eee Signed-off-by: Manuel Saelices <[email protected]>
…897) [External] [stdlib] mark dict entry as destroyed in `Dict.pop()` Fixes #2756 Co-authored-by: Helehex <[email protected]> Closes #2796 MODULAR_ORIG_COMMIT_REV_ID: d9ee05077d11b2b4b54bdd48d1a67100ab624eee
see #2756
this is an attempt to fix errors that sometimes arise when using the pop method. I'm not sure this is the best way, so feedback is much appreciated