This is an archive of the discontinued LLVM Phabricator instance.

[Modules] Don't parse/load explicit module maps if modules are disabled
AbandonedPublic

Authored by andrewjcg on Aug 28 2020, 12:13 PM.

Details

Reviewers
bruno
rsmith
Summary

In some build environments/systems, flags for explicit module map files
may be propagated up to dependents which may not choose to enable use of
modules (e.g. if a particular compilation doesn't currently work in
modular builds).

In this case, the explicit module files are still passed, even though
they're not used (and can trigger additional I/O at header search path,
like realpath'ing include roots if an explicit module map contains a
umbrella dir).

This diff avoids parsing/loading these module map files if modules
haven't been enabled.

Diff Detail

Event Timeline

andrewjcg created this revision.Aug 28 2020, 12:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2020, 12:13 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
andrewjcg requested review of this revision.Aug 28 2020, 12:13 PM

Hi Andrew, thanks for improving this. I think this makes sense: dependents can choose to not use modules without having to trigger the build system to rebuild all dependencies. Can you add a simple testcase to prove the point of the change?

clang/lib/Frontend/FrontendAction.cpp
814

Is this clang-formatted?

Can you add a simple testcase to prove the point of the change?

Yup, will do!

clang/lib/Frontend/FrontendAction.cpp
814

Ahh, yeah. Should I avoid this sort of thing (and e.g. instead do this in explicit codemod/refactoring diffs)?

How about a malformed module map is not loaded and gives no errors?

How about a malformed module map is not loaded and gives no errors?

Heh yeah, was thinking the same :)

bruno added inline comments.Aug 28 2020, 12:58 PM
clang/lib/Frontend/FrontendAction.cpp
814

It's fine in this case cause it's relevant as part of your changes (indentation for the block will change anyways), just double checking on the final formatting.

bruno added inline comments.Sep 1 2020, 10:51 AM
clang/test/Modules/explicit-module-maps.cpp
5

Minor suggestion here given the content of the file is pretty simple, how about something along these lines:

// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: echo 'DOES NOT PARSE!' > %t/invalid.modulemap
// RUN: %clang_cc1 -fmodule-map-file=%t/invalid.modulemap -verify %s
andrewjcg updated this revision to Diff 289236.Sep 1 2020, 11:38 AM

simplify test

andrewjcg marked an inline comment as done.Sep 1 2020, 12:09 PM
rsmith requested changes to this revision.Sep 1 2020, 1:01 PM
rsmith added a subscriber: rsmith.

Sorry for not noticing this review earlier.

We can't make this change. Module map files are still useful and still used even when modules are disabled -- they power the undeclared inclusion and private header diagnostics, and with -fmodules-local-submodule-visibility you still get modular semantics for modular headers even when -fmodules is disabled.

This revision now requires changes to proceed.Sep 1 2020, 1:01 PM
andrewjcg abandoned this revision.Sep 1 2020, 1:16 PM

Ahh, I see, make sense.

The motivating issue was due to an apparent bug where realpaths in umbrella dir support for module map files get leaked into dep files for includes starting with .. (e.g. #include "../foo.h") in non-modular builds.

I'll try get a repo together for a bug report for that issue instead.