[cfe-dev] Module resolution during preprocessing
Richard Smith via cfe-dev
cfe-dev at lists.llvm.org
Mon Jun 12 15:23:15 PDT 2017
On 10 June 2017 at 00:20, Boris Kolpackov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Richard Smith <richard at metafoo.co.uk> writes:
>
> > Clang supports mixing Modules TS modules with header modules. Header
> > modules support exporting macros. Therefore, because "import foo;" might
> > import a module that exports a macro, it must be available during
> > preprocessing.
>
> This causes a bit of a chicken and egg problem for us: we analyze the
> preprocessed output to discover which modules are required but need to
> know the required modules before preprocessing.
>
> I could remove the -fmodules-ts but that's not ideal since this option
> could conceivably alter predefined macros (like __cpp_modules).
>
> Is there a way to disable this "header modules" support and get a pure
> Modules TS semantics? If not, do you think such a mode could be added?
>
That wouldn't help if we want to give Modules TS modules the ability to
export macros as an extension (which it seems like we probably would want
to do). But... at that point, the problem is fundamental: an
earlier-imported module could export a macro that is expanded later and
generates a module import. Given that your analysis strategy is
incompatible with such an extension anyway, I think your request for a mode
that sets up the modules-specific build configuration but doesn't handle
'import' in the preprocessor is reasonable.
Would you be interested in writing a patch for this?
> We could have only enabled "header modules" if both -fmodules-ts and
> -fmodules are specified, but that ship might have already sailed.
It wouldn't be too late for that. The command-line interface for header
modules has been around for a long while, have been used in numerous build
systems, and would be painful to change at this point, but the same is not
true for the modules TS command-line interface. But we would still have the
issue that we explicitly permit a Modules TS import to import a (header)
module that exports macros, so I don't think this solves your problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170612/1026d1fd/attachment.html>
More information about the cfe-dev
mailing list