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

Implement SSO for constexpr string #1735

Merged
merged 5 commits into from
Jun 19, 2022
Merged

Conversation

miscco
Copy link
Contributor

@miscco miscco commented Mar 13, 2021

In #1502 we found that it should be possible to enable SSO, but we wanted to get constexpr string in.

It turns out that we were not that far off. I verified that all test compile fine with clang-12. That said, it seems I uncovered 2 distinct MSVC bugs:

  1. The test for basic_string::operator-> is failing. MSVC complains about an uninitialized symbol. Clang is happy. I have no idea what is wrong there.
  2. Clang complained heavily about switching back to SSO form. It turns out that previously we were directly constructing the sentinel in the first slot of the SSO array. However, we never switched from the _Ptr to the _Buf member. So I believe clang is correct here and MSVC should recognize that _Bufs lifetime did not yet start

stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Mar 14, 2021
@miscco

This comment was marked as outdated.

@mnatsuhara

This comment was marked as outdated.

@miscco

This comment was marked as outdated.

Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

Thanks for going through and working on this! Sorry for the wait on a review here. Things look pretty good to me, just a few questions / nitpicks and request for more extensive test coverage :)

tests/std/tests/P0980R1_constexpr_strings/test.cpp Outdated Show resolved Hide resolved
stl/inc/xstring Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
@mnatsuhara

This comment was marked as resolved.

@miscco

This comment was marked as resolved.

@miscco

This comment was marked as resolved.

@miscco miscco force-pushed the SSO_string branch 2 times, most recently from c164242 to de327ee Compare August 27, 2021 09:54
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
@mnatsuhara

This comment was marked as resolved.

@miscco

This comment was marked as resolved.

Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

The only real "request changes" here is the missing _STD, otherwise looks great! Thanks for all of the bug fixes and extensive added test coverage 😻

stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Show resolved Hide resolved
tests/std/tests/P0980R1_constexpr_strings/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0980R1_constexpr_strings/test.cpp Outdated Show resolved Hide resolved
@miscco

This comment was marked as resolved.

stl/inc/xstring Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks, this is so much easier to understand now! 😻

I pushed changes to remove one more workaround (didn't affect correctness).

... and do so without ending the lifetime of the enclosing `basic_string` by reusing its storage.
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

I'm going to push a tiny change to address the pre-existing issue and approve.

stl/inc/xstring Outdated Show resolved Hide resolved
tests/std/tests/P0980R1_constexpr_strings/test.cpp Outdated Show resolved Hide resolved
stl/inc/xstring Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
tests/std/tests/P0980R1_constexpr_strings/test.cpp Outdated Show resolved Hide resolved
stl/inc/xstring Outdated Show resolved Hide resolved
Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
@StephanTLavavej StephanTLavavej self-assigned this Jun 19, 2022
@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 1ea95df into microsoft:main Jun 19, 2022
@StephanTLavavej
Copy link
Member

Thanks for simplifying these codepaths and making basic_string easier to maintain! 🎉 ✅ 😺

fsb4000 pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
Co-authored-by: Casey Carter <Casey@Carter.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants