[C++20] [Modules] Deprecate to load C++20 Modules eagerly
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 24 Feb 2023 08:41:52 +0000 (16:41 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 3 Mar 2023 06:25:33 +0000 (14:25 +0800)
commit57833636816a13ccda53714413c532dc81e3b5ff
tree4b66de65267ad029ccb73c00d2804c9ed3f70d13
parentfe758254181a824d73ad960b651b42f671f8936b
[C++20] [Modules] Deprecate to load C++20 Modules eagerly

Close https://github.com/llvm/llvm-project/issues/60824

The form -fmodule-file=<path-to-BMI> will load modules eagerly and the
form -fmodule-file=<module-name>=<path-to-BMI> will load modules lazily.
The inconsistency adds many additional burdens to the implementations.
And the inconsistency looks not helpful and necessary neither. So I want
to deprecate the form -fmodule-file=<path-to-BMI> for named modules.
This is pretty helpful for us (the developers).

Does this change make any regression from the perspective of the users?

To be honest, yes. But I think such regression is acceptable. Here is
the example:

```
// M.cppm
export module M;
export int m = 5;

// N.cpp
// import M; // woops, we forgot to import M.
int n = m;
```

In the original version, the compiler can diagnose the users to import
`M` since the compiler have already imported M. But in the later style,
the compiler can only say "unknown identifier `m`".

But I think such regression doesn't make a deal since it only works if
the user put `-fmodule-file=M.pcm` in the command line. But how can the
user put `-fmodule-file=M.pcm` in the command line without `import M;`?
Especially currently such options are generated by build systems. And
the build systems will only generate the command line from the source
file.

So I think this change is pretty pretty helpful for developers and
almost innocent for users and we should accept this one.

I'll add the release notes and edit the document after we land this.

Differential Revision: https://reviews.llvm.org/D144707
31 files changed:
clang/include/clang/Basic/DiagnosticSerializationKinds.td
clang/lib/Serialization/ASTReader.cpp
clang/test/CXX/basic/basic.link/p10-ex2.cpp
clang/test/CXX/basic/basic.link/p2.cpp
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp
clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
clang/test/CXX/module/basic/basic.def.odr/p6.cppm
clang/test/CXX/module/basic/basic.link/module-declaration.cpp
clang/test/CXX/module/basic/basic.link/p2.cppm
clang/test/CXX/module/basic/basic.search/module-import.cppm
clang/test/CXX/module/dcl.dcl/dcl.module/dcl.module.import/p1.cppm
clang/test/CXX/module/dcl.dcl/dcl.module/dcl.module.interface/p1.cppm
clang/test/CXX/module/dcl.dcl/dcl.module/p1.cpp
clang/test/CXX/module/dcl.dcl/dcl.module/p5.cpp
clang/test/CXX/module/module.context/p7.cpp
clang/test/CXX/module/module.interface/p1.cpp
clang/test/CXX/module/module.interface/p2.cpp
clang/test/CXX/module/module.unit/p8.cpp
clang/test/Modules/cxx20-10-1-ex2.cpp
clang/test/Modules/cxx20-10-2-ex2.cpp
clang/test/Modules/cxx20-10-2-ex5.cpp
clang/test/Modules/cxx20-10-3-ex1.cpp
clang/test/Modules/cxx20-10-3-ex2.cpp
clang/test/Modules/cxx20-10-5-ex1.cpp
clang/test/Modules/cxx20-import-diagnostics-a.cpp
clang/test/Modules/cxx20-import-diagnostics-b.cpp
clang/test/Modules/eagerly-load-cxx-named-modules.cppm [new file with mode: 0644]
clang/test/Modules/named-modules-adl-2.cppm
clang/test/Modules/named-modules-adl.cppm
clang/test/Modules/pr60036.cppm
clang/test/SemaCXX/modules.cppm