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

Supporting import std; in C++20 #3945

Closed
StephanTLavavej opened this issue Aug 10, 2023 · 7 comments · Fixed by #3977
Closed

Supporting import std; in C++20 #3945

StephanTLavavej opened this issue Aug 10, 2023 · 7 comments · Fixed by #3977
Labels
fixed Something works now, yay! modules C++23 modules, C++20 header units

Comments

@StephanTLavavej
Copy link
Member

Currently, we block the C++23 Standard Library Modules from being used in C++20 mode. There's no technical reason for this, it's purely a policy choice. Supporting import std; in C++20 mode would be easy (remove the block, add test coverage, it'll take me just a few minutes - at least in the toolset, then we'll need to talk to the build systems), because we don't need anything from the C++23 Core Language here. However, after granting this ability to users, we can never take it back.

Therefore, we're looking for cross-vendor agreement. Next Wednesday (2023-08-16), the MSVC STL maintainers will talk about this at our weekly scheduled meeting and I expect we'll agree that this is a reasonable thing to do. If the libc++ and libstdc++ maintainer teams could discuss this in their own channels and then add comments here saying "The lib<meow>c++ maintainers want to support import std; in C++20 mode", then we can move forward together.

(This equally applies to import std.compat;, of course. It does not apply to any future modules that might be added to C++26 and beyond. Please note that we're not running a user survey here.)

@StephanTLavavej StephanTLavavej added decision needed We need to choose something before working on this modules C++23 modules, C++20 header units labels Aug 10, 2023
@jwakely
Copy link

jwakely commented Aug 10, 2023

The libstdc++ maintainers want to support import std; in C++20 mode.

I've noted this at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106852 too.

@ldionne
Copy link

ldionne commented Aug 11, 2023

There doesn't seem to be any technical concerns so libc++ will follow as well. We'll document it as an extension on our side around https://libcxx.llvm.org/UsingLibcxx.html#libc-extensions.

@grafikrobot
Copy link

Some basic questions:

  1. Does this also mean that when C++26, etc, comes along they will also be usable in the C++20 mode?
  2. Will all of the std be available, or just the C++20 parts?
  3. Will the feature macros indicate C++23 or C++20 for the respective parts when compiling in C++20 mode when importing the C++23 std?

@StephanTLavavej
Copy link
Member Author

  1. Does this also mean that when C++26, etc, comes along they will also be usable in the C++20 mode?

No. If C++26 adds std.meow modules, we implementers will need to separately decide whether to support those modules "downlevel" in C++23 and C++20 modes. (This may be technically difficult, if the C++26 Core Language adds module features that the Standard Library begins depending on, for example.)

  1. Will all of the std be available, or just the C++20 parts?

Just the C++20 parts (with any LWG issue resolutions and C++23-and-later features that implementers have chosen to backport).

This simply means that in -std=c++20 / /std:c++20 mode, import std; and #include <all_standard_library_headers> provide the same functionality, modulo macros.

  1. Will the feature macros indicate C++23 or C++20 for the respective parts when compiling in C++20 mode when importing the C++23 std?

Mu. import std; doesn't provide any macros, including the feature-test macros.

If you're in C++20 mode and import std; followed by (or preceded by) #include <version>, you get C++20 level feature-test macros, which correspond to the machinery you've imported.

Hopefully this all makes sense - the whole reason that the implementers view this as very easy to support is because the Standard mode is mostly orthogonal to the module mechanism (we have all made our codebases conditional on Standard mode, so selectively lighting up just the C++20 parts is trivial regardless of whether it's being done via classic headers or named modules).

@mordante
Copy link
Contributor

What @stl said matches what I intend to do for libc++.

@jwakely
Copy link

jwakely commented Aug 14, 2023

Does this also mean that when C++26, etc, comes along they will also be usable in the C++20 mode?

Nobody is suggesting that C++23 (e.g. std::expected and std::mdspan) will be usable in C++20 mode. So C++26 (e.g. std::submdspan) won't be usable in C++20 mode either.

@StephanTLavavej StephanTLavavej removed the decision needed We need to choose something before working on this label Aug 16, 2023
@StephanTLavavej
Copy link
Member Author

The MSVC STL maintainers are (unsurprisingly) in favor of this too; I'll work on a PR for our repo. Thanks everyone!

@CaseyCarter CaseyCarter added the fixed Something works now, yay! label Aug 31, 2023
mordante added a commit to llvm/llvm-project that referenced this issue Sep 5, 2023
The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] microsoft/STL#3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358
avillega pushed a commit to avillega/llvm-project that referenced this issue Sep 11, 2023
The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] microsoft/STL#3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358
blueboxd pushed a commit to blueboxd/libcxx that referenced this issue Sep 29, 2023
The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] microsoft/STL#3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358

NOKEYCHECK=True
GitOrigin-RevId: b9f24033f7f2d3485fbabbc56e3b31b5bc90e874
qihangkong pushed a commit to rvgpu/llvm that referenced this issue Apr 18, 2024
The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] microsoft/STL#3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Something works now, yay! modules C++23 modules, C++20 header units
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants