<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/80663>80663</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [C++23] [Modules] [std module] Skip including standard headers if the std module is imported
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++,
            clang:modules
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ChuanqiXu9
      </td>
    </tr>
</table>

<pre>
    While there is an annoying issue called "include after import": https://clang.llvm.org/docs/StandardCPlusPlusModules.html#including-headers-after-import-is-problematic, it should still be problematic to increase the compilation time (or the size of BMIs, if it exists). And this is fundamental to clang and it looks hard to fix it completely and perfectly in the side side.

And I feel this is straightforward for people to understand:

```
module;
import std;
#include <vector>
#include <string>
export module M;
...
```

may have larger BMI and compile slower than:

```
module;
import std;
export module M;
...
```

While the example looks silly, it is actually pretty common since the standard library can be used in other headers.

In a private meeting with MSVC developer, he mentioned MSVC have extensions (or plan to?) to skip the standard headers if the std module is imported.

I feel this sounds good and can be pretty helpful to end users.

For the implementation, I don't have a complete design now. In my mind, the immediate idea may be:
- Implement this in the library side completely.
- Implement this in the compiler side completely.
- Implement this within the compiler and the library.

The idea to implement this in the library may require the library to provide an additional header to include all the controlling macros. So that the user (manually) can import std in a way like:

```
import std;
#include <controlling_macros_for_std_headers>

#include "..."
```

The idea in the compiler side may need to hardcode all the filenames for the standard headers and skip entering such headers.

The idea to implement this in the compiler side and the library side is the library provides such header and the compiler can insert it automatically.

The idea to implement this is still in the early phase. Any comments are welcomed.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVs1u6zYTfRp6M7AgU7ETL7xInM9AFgE-IEXbXTAWRxZ7KVKXpOK4T18MxSh2GuTetoDjWKQ4P-fMGQ6GoA-WaCOWd2J5P8Mhts5vtu2A9rv-fVjP9k6dNr-12hDEljyBDoAW0Fp30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