This is an archive of the discontinued LLVM Phabricator instance.

[Modules] Fix rebuilding an updated module for each of its consumers.
ClosedPublic

Authored by vsapsai on Aug 28 2019, 3:05 PM.

Details

Summary

Marking a module for a rebuild when its signature differs from the
expected one causes redundant module rebuilds for incremental builds.
When a module is updated, its signature changes. But its consumers still
have the old signature and loading them will result in signature
mismatches. It will correctly cause the rebuilds for the consumers but
we don't need to rebuild the common module for each of them as it is
already up to date.

In practice this bug causes longer build times. We are doing more work
than required and only a single process can build a module, so parallel
builds degrade to a single-process mode where extra processes are just
waiting on a file lock.

Fix by not marking a module dependency for a rebuild on signature
mismatch. We'll check if it is up to date when we load it.

rdar://problem/50212358

Diff Detail

Repository
rL LLVM

Event Timeline

vsapsai created this revision.Aug 28 2019, 3:05 PM

Earlier tryToDropPCM was called tryToRemoveBuffer and it was added in r298278. According to my investigation and understanding it was used to remove tentatively loaded dependencies. Otherwise we would finalize them before validating if they are up to date. But now we are tracking a state of each module (Unknown, Tentative, ToBuild, Final) individually and don't need tryToDropPCM.

dexonsmith accepted this revision.Aug 28 2019, 3:54 PM

This LGTM.

The key insight you're making is that when you're importing B into A and B's signature doesn't match what A expects, that does not mean that B is out-of-date. B may have just been built and be totally correct. It only means that A is out-of-date. I had considered removing this call, but was confused about exactly what this would mean.

clang/lib/Serialization/ModuleManager.cpp
211 ↗(On Diff #217729)

This is the only caller of FileManager::invalidateCache. I suggest deleting it in a follow-up, in order to reduce complexity in the FileManager.

This revision is now accepted and ready to land.Aug 28 2019, 3:54 PM
bruno accepted this revision.Aug 28 2019, 4:03 PM

Thanks for fixing this, LGTM!

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2019, 4:32 PM
vsapsai marked an inline comment as done.Aug 28 2019, 4:47 PM
vsapsai added inline comments.
clang/lib/Serialization/ModuleManager.cpp
211 ↗(On Diff #217729)

Good suggestion. Agree it will be better to keep the FileManager simpler.