This is an archive of the discontinued LLVM Phabricator instance.

[driver] Prune module-map related flags, if they are not going to be needed
AbandonedPublic

Authored by akyrtzi on Sep 2 2022, 12:56 PM.

Details

Summary

This is follow-up from https://reviews.llvm.org/D132801, but taking into account the conditions
where the module-map flags are still used even when -fmodules is disabled.

This useful for removing unnecessary input dependencies from the cc1 invocation.

Diff Detail

Event Timeline

akyrtzi created this revision.Sep 2 2022, 12:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 12:56 PM
akyrtzi requested review of this revision.Sep 2 2022, 12:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 12:56 PM
rsmith added a comment.Sep 2 2022, 4:16 PM

I've landed some tests for the specific functionality that intends to use modules info under -fno-modules in b484256f59850e702df4d4532c5f31f478879bb9.

I think the approach you're taking here is probably doomed -- too many things in Clang depend on whether we've read module map files, and it seems unlikely to me that you'll be able to catch all of them from the driver. For example:

$ touch a.h
$ echo 'module a { private header "a.h" }' > module.modulemap
$ echo '#include "a.h"' > b.cc
$ clang -fmodule-map-file=module.modulemap b.cc
b.cc:1:10: error: use of private header from outside its module: 'a.h' [-Wprivate-header]
#include "a.h"
         ^
1 error generated.

(and that error can be controlled by a #pragma, so you can't even do this if the driver sees -Wno-private-header).

I wonder if we could mark a Module as "used" whenever we use information from it, and treat module map files as dependencies of the current compilation only if they're used?

I think the approach you're taking here is probably doomed -- too many things in Clang depend on whether we've read module map files, and it seems unlikely to me that you'll be able to catch all of them from the driver.

I see, the driver approach does seem like a non-starter, thank you for the feedback! This needs reevaluation.

akyrtzi abandoned this revision.Sep 2 2022, 5:27 PM