Skip to content
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

<deque>: Make deque::shrink_to_fit never relocate elements #4091

Merged
merged 24 commits into from
Jan 30, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

Fixes #4072 by providing stronger guarantee.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner October 15, 2023 06:51
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
Properly handle the internal circular buffer!
@achabense

This comment was marked as resolved.

stl/inc/deque Outdated Show resolved Hide resolved
@achabense

This comment was marked as outdated.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Oct 15, 2023
stl/inc/deque Show resolved Hide resolved
{
deque<ThrowingMovable> deq(128);
deq.pop_back();
deq.emplace_front(0);
Copy link
Contributor

@achabense achabense Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having an assumption that the deque will be in all-full state. However, after debugging I realize that the _Mapsize() is already 64 (which means the capacity is already (roughly) 256 instead of 128), and _First_block_idx==63 and _Last_block_idx==32, which are not closely related as I originally supposed.

No changes requested, as what's going on here is enough to catch out the bug, and I have no idea how to improve the test here (mainly, how to control the relative position of _First_block_idx and _Last_block_idx in an obvious way?). I just want to point out that 128, together with pop-then-push, wrongly gives an impression that deq is in full state and thus it's testing a corner-case - no, this is not a corner case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, deque is really weird. I agree that this coverage is reasonable and I agree that it's not worth the extra effort to try to write a really comprehensive test.

stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej self-assigned this Oct 18, 2023
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
stl/inc/deque Outdated Show resolved Hide resolved
{
deque<ThrowingMovable> deq(128);
deq.pop_back();
deq.emplace_front(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, deque is really weird. I agree that this coverage is reasonable and I agree that it's not worth the extra effort to try to write a really comprehensive test.

@StephanTLavavej StephanTLavavej removed their assignment Jan 26, 2024
@StephanTLavavej
Copy link
Member

StephanTLavavej commented Jan 26, 2024

Thank you! 😻 After getting up to speed with your excellent overhaul here, I pushed a bunch of changes to make the logic clearer for my cat-sized brain. Please double-check that I didn't mess anything up.

This is vastly better than our original implementation of shrink_to_fit(), and now that I can see what the fix is doing, I'm not too worried about it subtly breaking deque invariants. However, this is definitely complex enough to need 3 maintainer eyes, so I'll ask for a final review before moving this to ready to merge.

@StephanTLavavej StephanTLavavej self-assigned this Jan 30, 2024
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 46402aa into microsoft:main Jan 30, 2024
35 checks passed
@StephanTLavavej
Copy link
Member

Thanks for fixing everyone's favorite STL container! 🛠️ 😹 🎉

@frederick-vs-ja frederick-vs-ja deleted the deque-shrink_to_fit branch January 30, 2024 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

<deque>: shrink_to_fit() should follow the Standard
5 participants