Make dropping an empty BTreeMap free - #161791
Open
jakedrew wants to merge 2 commits into
Open
Conversation
Collaborator
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
Nice, but that requires libs review. r? rust-lang/libs |
|
Hmm, maybe not https://godbolt.org/z/Wzhqh9jre. |
clarfonthey
reviewed
Aug 27, 2026
| use std::collections::BTreeMap; | ||
|
|
||
| // CHECK-LABEL: @drop_btree | ||
| // CHECK-NOT: dying_next |
Contributor
There was a problem hiding this comment.
I personally would rather this check for calls to dealloc rather than dying_next, since I this test could easily become worthless if this method is renamed.
Contributor
|
@rustbot author |
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#161375 (code example) shows that drop of an empty BTree map walks the dying_next path and so is not free. I tracked this down to 7b28036 in 1.56.0 using godbolt’s version comparison.
When the Btree map has no root we use the ManuallyDrop to safely drop the allocator early resulting in a free drop and a
retinstead of thedying_nextpath.Includes codegen test which correctly catches the prior dying_next case, which I based on
uninit-aggregate-field.rs.Fixes #161375