Skip to content

Extend std C++ include header list (fix #692) #693

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

Closed
wants to merge 2 commits into from

Conversation

fedapo
Copy link
Contributor

@fedapo fedapo commented Sep 21, 2023

The new list is taken from the CPP2_USE_MODULES case and sorted alphabetically. This is a bit repetitive and could have been avoided, but I chose not to mess with the preprocessor if-else logic. I can change it, should several voices prefer that.

hsutter added a commit that referenced this pull request Sep 25, 2023
@hsutter
Copy link
Owner

hsutter commented Sep 25, 2023

Thanks! To make it easier for me to track what's being added, I went ahead and sorted the list myself (I think? it's been a long Sunday, please also fix any ordering oversights). So if you could please update the PR then I can see what headers are being added in the diff.

@fedapo fedapo force-pushed the add-missing-std-headers branch from f02aad5 to b9b5bf9 Compare September 25, 2023 06:34
@fedapo
Copy link
Contributor Author

fedapo commented Sep 25, 2023

@hsutter Sure. Done.

Comment on lines 197 to 198
// Otherwise, we're not in -pure-cpp2 and so just #include
// what we need in this header to make this self-contained
Copy link
Contributor

Choose a reason for hiding this comment

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

Now this comment isn't true anymore.

@hsutter
Copy link
Owner

hsutter commented Sep 28, 2023

Ah, now I see what you're doing... I think you're suggesting that even non-pure/modules mode should just include all standard headers always? I was slightly worried about possible compile time impact, but then I suppose we're already doing that in -pure mode (when modules aren't available, which is most of the time right now in practice).

@hsutter
Copy link
Owner

hsutter commented Oct 9, 2023

Thanks @fedapo !

The original reason to provide the entire standard library in -pure-cpp2 mode was that module is import is blazing fast -- it's faster to use C++23 import std; than to compile iostream Hello World. So it made sense to try the experiment of just making it the default.

The reason I provided a way to include all std headers was as a fallback path for compilers that didn't have real module import yet (most of them) or C++23 import std; (essentially all of them).

I've tried out the suggestion here, and I'm seeing that #include of the entire standard library makes compiling small files (including the regression tests) noticeably sluggish -- not a whole lot, but noticeable.

However, I see value in providing a way to include the entire standard library even in non-pure-cpp2 mode, so I'm going to try out providing it as command line options. The idea is to make it "zero-overhead," i.e., let users can pay for the additional compilation work only if they ask for it:

  -im[port-std]           import the entire C++ standard library via 'import std;'
  -in[clude-std]          #include the entire C++ standard library - ignored if -import-std is set
  -p[ure-cpp2]            Allow Cpp2 syntax only - also sets -import-std

So now a mixed-Cpp1-and-Cpp2 file can easily opt into the convenience of either importing (fast!) or including (wait a couple of extra seconds) the entire standard library. Note -pure-cpp2 retains its current behavior because it implies -import-std.

I'll push that commit instead of this PR, but it was directly inspired by this. Again, thanks @fedapo !

@fedapo
Copy link
Contributor Author

fedapo commented Oct 9, 2023

@hsutter Thanks for the notice.
Fine with me to get the full set of std includes through an ad hoc command-line switch.

@hsutter hsutter closed this in d484264 Oct 9, 2023
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants