This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules] Implement include translation.
AbandonedPublicDraft

Authored by iains on Jul 1 2022, 3:52 AM.

Details

Reviewers
None
Summary

This addresses [cpp.include]/7

(when encountering #include header-name)

If the header identified by the header-name denotes an importable header, it
is implementation-defined whether the #include preprocessing directive is
instead replaced by an import directive.

In this implementation, include translation is performed _only_ for headers
in the Global Module fragment, so:

module;
 #include "will-be-translated.h" // IFF the header unit is available.

export module M;
 #include "will-not-be-translated.h" // even if the header unit is available

The reasoning is that, in general, includes in the module purview would not
be validly translatable (they would have to immediately follow the module
decl and without any other intervening decls). Otherwise that would violate
the rules on contiguous import directives.

This would be quite complex to track in the preprocessor, and for relatively
little gain (the user can 'import "will-not-be-translated.h";' instead.)

TODO: This is one area where it becomes increasingly difficult to disambiguate
clang modules in C++ from C++ standard modules. That needs to be addressed in
both the driver and the FE.

Diff Detail

Event Timeline

iains created this revision.Jul 1 2022, 3:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2022, 3:53 AM
iains updated this revision to Diff 441657.Jul 1 2022, 3:54 AM

retry after a failed git commit.

iains abandoned this revision.Jul 8 2022, 1:04 AM

somehow a duplicate of the first patch version was submitted.

Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 1:05 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript