Chaining clang::Modules


I know I am walking on fragile grounds. But they are just too
interesting, so let me ask nonetheless :slight_smile:

I have a module core.pcm that contains Core.h. When generating big.pcm
(which contains Big.h which in turn #include-s Core.h) I want the
Preprocessor and the ASTWriter to make use of core.pcm - for instance to
not have to merge the modules when loading.

What's the best approach here? I don't manage to convince the ASTWriter
to use the chaining mechanism (in analogy to the chaining of PCHs); the
amount of registered "sub-"modules (core and big = 2) does not
correspond to the amount of modules written - which is only big.pcm
which does not have submodules and thus 1, as defined by ASTWriter's

It seems the ASTWriter expects me to create big.pcm as a super-module
with core.pcm as its submodule. The problem is that I will also generate
bigger.pcm and huge.pcm that would all like to reuse core.pcm, meaning
core.pcm is the submodule of many.

So is the submodule layout really appropriate here?

Cheers, Axel.

I think you’ve got “submodules” mixed up with “dependencies”. Submodules are modules stored within the same .pcm file and accessed as TopLevelModule.Submodule. Dependencies, on the other hand, are just other modules that the current module refers to and/or re-exports. So in your case, it sounds like “Big” is its own module with “Core” as a dependency.

The trick is that a pcm file can only be used if there is a module map that refers to the header file. So, for example, you could drop this file in next to Core.h:

module Core {
header “Core.h”
export *

And then anything that does “#include <Core.h>” should pick up the module map…as long as you are compiling with -fmodules, of course. (I can’t remember if ‘#include “Core.h”’ will do it, nor ‘#include “path/to/Core.h”’, but I would expect yes.)

Was that the missing piece?