[PATCH] Add stopgap option -fmodule-implementation-of
Ben Langmuir
blangmuir at apple.com
Tue May 27 20:15:53 PDT 2014
Hi Richard,
Thanks for the review! As I said, this didn’t feel like a great fix to me either.
> On May 27, 2014, at 3:00 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>
> On Tue, May 27, 2014 at 8:31 AM, Ben Langmuir <blangmuir at apple.com> wrote:
> CC’ing djasper, since you made -fmodule-name a driver option, so you may be familiar with this code.
>
> I’m not super happy with this patch, but we really need some way to not use modular imports while compiling the implementation (e.g. .c/.cpp/.m files) files that correspond to module headers. Both because we are not yet isolating submodules from each other enough to do incremental rebuilding
>
> Can you explain what you mean by this? In particular, I'm very unclear on how it the translation unit being compiled has any relation to this issue. (I've not seen any problems that match this description so far.)
My understanding is that when we build a module with submodules, the submodules can access the declarations/definitions in previously built submodules. Until that is fixed, it seems that to be safe we should rebuild everything that depends on a module whenever any of its headers change. That ruins incremental rebuilding for the author of the module whenever they change their headers since all of their implementation files likely would depend on the module.
>
> and because with the VFS added to the mix we may get a mix of textual and modular imports of the same headers when doing “quote”-style includes, which doesn’t yet work properly (multiple definitions, hidden definitions, fun stuff).
>
> I assume you intend for this bug to be fixed eventually. Once that's done, is there still value in this flag?
Right, ideally we should still find the module with the VFS, and even if we don’t it shouldn’t matter. Once that (and the above) is fixed, the flag has no use that I can think of.
>
> Add stopgap option -fmodule-implementation-of <name>
>
> Please do not add a stopgap workaround to our stable and backwards-compatible driver interface; just add it to -cc1 instead.
>
> This flag specifies that we are building an implementation file of the
> module <name>, preventing importing <name> as a module. This does not
> consider this to be the 'current module' for the purposes of doing
> modular checks like decluse or non-modular-include warnings, unlike
> -fmodule-name.
>
> I don't see any relation between the flag's name and its functionality; there seems to be no reason for this to be linked to the translation unit being the implementation of any particular module (and if there were, that's what -fmodule-name is for). Instead, I think what you're trying to specify is that a particular module is included textually for this compilation. Please pick a name that suggests that functionality instead.
The name is related to the use-case, not the mechanism. I originally thought about something like “-no-module=<name>", but I didn’t want to use a generic diagnostic e.g. “error: @import of module specified with -no-module=”). With the more specific flag I have a more specific diagnostic that says not to @import the module you’re implementing and use #import instead.
The reason -fmodule-name didn’t seem right here is that it treats the current TU as being part of a module build (i.e. we are inside compileModule and/or have set -emit-module). We look at CurrentModule (which is what -fmodule-name sets) in a number of places and can get odd behaviour if you aren’t actually compiling a module. For example, when we call loadModule, we skip loading the named module and making it visible, but we still add it to the list of imports. That causes trouble with PCH, which then think that this module was actually loaded already. I also don’t want to unconditionally do decluse checking or give non-modular include warnings, etc when building an implementation file.
Maybe when we really are inside a module build, a better way to spell -fmodule-name=Blah -emit-module would be -emit-module=Blah? But we already have -fmodule-name as a driver option so I don’t know if we would really want to change this.
>
> I'm also not sure how this is supposed to work in general: suppose the implementation of module A imports module B, and module B includes a header from module A. Do we get another variant of module B, or do we textually include A into B (generating probably-broken submodule visibility), or is that now an error, or something else?
Module B is unaffected by this option, since it gets reset in LangOptions::resetNonModularOptions(), which admittedly would end up going back to mixing modular and non-modular includes so maybe an error is more appropriate. I’m curious: what would the use case for this pattern be? I can see why you would want a submodule of A (e.g. A.Internal) to do this, but why some other top-level module B?
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140527/06d6969f/attachment.html>
More information about the cfe-commits
mailing list