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

Make <string_view> slimmer by default #4633

Merged

Conversation

frederick-vs-ja
Copy link
Contributor

The new header <__msvc_string_view.hpp> provides char_traits and basic_string_view and related utilities. <string_view> shouldn't provide other utilities in <xstring>. Fixes #4625.

<ranges> seemingly still need to include <xmemory> in C++23 due to elements_of whose default template argument depends on allocator (see #4620).

Escape hatch _LEGACY_CODE_ASSUMES_STRING_VIEW_INCLUDES_XSTRING is provided to restore legacy inclusion.

MSVC-internal changes are needed due to the new internal header.

The new header `<__msvc_string_view.hpp>` provides `char_traits` and
`basic_string_view` and related utilities. `<string_view>` shouldn't
provide other utilities in `<xstring>`.

`<ranges>` seemingly still need to include `<xmemory>` in C++23
due to `elements_of` whose default template argument depends on
`allocator`.

Escape hatch `_LEGACY_CODE_ASSUMES_STRING_VIEW_INCLUDES_XSTRING` is
added to restore legacy inclusion.

MSVC-internal changes are needed due to the new internal header.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner April 27, 2024 11:14
@StephanTLavavej StephanTLavavej added the throughput Must compile faster label Apr 27, 2024
@StephanTLavavej StephanTLavavej self-assigned this Apr 27, 2024
@StephanTLavavej
Copy link
Member

Thanks - I pushed a conflict-free merge with main.

@StephanTLavavej StephanTLavavej removed their assignment May 29, 2024
@StephanTLavavej StephanTLavavej self-assigned this May 29, 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 cce32f4 into microsoft:main May 30, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

Thanks for this significant throughput improvement for people who are carefully including only <string_view>! 😻 🎉 🚀

@frederick-vs-ja frederick-vs-ja deleted the split-string_view-header branch May 30, 2024 17:37
kou pushed a commit to apache/arrow that referenced this pull request Jun 7, 2024
### Rationale for this change

I work on MSVC's STL, and we regularly build popular open-source projects, including yours, with development builds of the MSVC toolset. This allows us to find and fix toolset regressions before they affect users, and also allows us to provide advance notice of breaking changes, which is the case here.

We recently merged microsoft/STL#4633 which will ship in VS 2022 17.11 Preview 3. This improved build throughput by refactoring `<string_view>` so that it no longer drags in `std::string`. It's also a source-breaking change for code that wasn't properly including `<string>`. Your `cpp/src/arrow/json/object_writer.h` declares `std::string Serialize();` without including `<string>`. When built with our updated STL, this will emit a compiler error:

```
C:\gitP\apache\arrow\cpp\src\arrow/json/object_writer.h(39): error C2039: 'string': is not a member of 'std'
```

### What changes are included in this PR?

The fix is simple and portable: include the necessary header.

### Are these changes tested?

Nope, I'm totally YOLOing it. If it builds, it's good.

(This will be tested in MSVC's internal "Real World Code" test infrastructure. Also, after VS 2022 17.11 ships, your existing build/test coverage will ensure that this keeps compiling.)

### Are there any user-facing changes?

No.

Authored-by: Stephan T. Lavavej <stl@microsoft.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
throughput Must compile faster
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Is it by design that <string_view> provides most contents of <string>?
2 participants