[cfe-dev] Module resolution during preprocessing

Boris Kolpackov via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 13 04:17:50 PDT 2017


Richard Smith <richard at metafoo.co.uk> writes:

> 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.

In this setup how do you see a build system discovering BMIs it needs
to build? To me it seems the only way is for some kind of a notification
or callback by the compiler back into the build system as it processes
each import. And all the BMIs will have to be built serially.

At the same time, if one wants to have a module that also exports
macros, they can provide a header that imports the module proper and
then defines the macros.


> Would you be interested in writing a patch for this?

I can give it a try. In light of the above it seems a more appropriate
approach would be to provide a switch that simply disables import
handling during preprocessing (in a sense similar to -frewrite-includes)
rather than some kind of "pure TS" mode. Maybe -fignore-imports or
-fmodules-ignore?

BTW, a couple of observations:

1. -E -frewrite-includes already appears to ignore imports which is not
   quite correct since a macro defined by a preceding import could be
   used to #ifdef-out an #include.

2. -E does not treat 'module M;' (in module interface unit) as an import.
   This will have to change if TS modules are extended to support macros.
   So in this sense -fmodules-ignore is better than -fignore-imports.

If this sounds like a reasonable approach, I can give it a go.

Thanks,
Boris



More information about the cfe-dev mailing list