Skip to content

Commit 05e81fc

Browse files
committed
Rename and document factory function, expand ModuleCache documentation
1 parent 3ac8635 commit 05e81fc

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
206206
Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
207207
SourceMgr, HeaderInfo, ModuleLoader);
208208

209-
IntrusiveRefCntPtr<ModuleCache> ModCache = getCrossProcessModuleCache();
209+
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
210210
PCHContainerOperations PCHOperations;
211211
ASTReader Reader(PP, *ModCache, /*ASTContext=*/nullptr,
212212
PCHOperations.getRawReader(), {});

clang/include/clang/Serialization/ModuleCache.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class AdvisoryLock;
1919
namespace clang {
2020
class InMemoryModuleCache;
2121

22-
/// The module cache used by implicitly-built modules.
22+
/// The module cache used for compiling modules implicitly. This centralizes the
23+
/// operations the compiler might want to perform on the cache.
2324
class ModuleCache : public RefCountedBase<ModuleCache> {
2425
public:
2526
/// May perform any work that only needs to be performed once for multiple
@@ -34,12 +35,16 @@ class ModuleCache : public RefCountedBase<ModuleCache> {
3435
virtual InMemoryModuleCache &getInMemoryModuleCache() = 0;
3536
virtual const InMemoryModuleCache &getInMemoryModuleCache() const = 0;
3637

37-
// TODO: Virtualize writing/reading PCM files, timestamp files, etc.
38+
// TODO: Virtualize writing/reading PCM files, timestamping, pruning, etc.
3839

3940
virtual ~ModuleCache() = default;
4041
};
4142

42-
IntrusiveRefCntPtr<ModuleCache> getCrossProcessModuleCache();
43+
/// Creates new \c ModuleCache backed by a file system directory that may be
44+
/// operated on by multiple processes. This instance must be used across all
45+
/// \c CompilerInstance instances participating in building modules for single
46+
/// translation unit in order to share the same \c InMemoryModuleCache.
47+
IntrusiveRefCntPtr<ModuleCache> createCrossProcessModuleCache();
4348
} // namespace clang
4449

4550
#endif

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
829829
AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
830830
AST->getFileManager(),
831831
UserFilesAreVolatile);
832-
AST->ModCache = getCrossProcessModuleCache();
832+
AST->ModCache = createCrossProcessModuleCache();
833833
AST->HSOpts = HSOpts ? HSOpts : std::make_shared<HeaderSearchOptions>();
834834
AST->HSOpts->ModuleFormat = std::string(PCHContainerRdr.getFormats().front());
835835
AST->HeaderInfo.reset(new HeaderSearch(AST->HSOpts,
@@ -1545,7 +1545,7 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
15451545
AST->UserFilesAreVolatile = UserFilesAreVolatile;
15461546
AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
15471547
UserFilesAreVolatile);
1548-
AST->ModCache = getCrossProcessModuleCache();
1548+
AST->ModCache = createCrossProcessModuleCache();
15491549

15501550
return AST;
15511551
}
@@ -1832,7 +1832,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCommandLine(
18321832
AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
18331833
AST->StorePreamblesInMemory = StorePreamblesInMemory;
18341834
AST->PreambleStoragePath = PreambleStoragePath;
1835-
AST->ModCache = getCrossProcessModuleCache();
1835+
AST->ModCache = createCrossProcessModuleCache();
18361836
AST->OnlyLocalDecls = OnlyLocalDecls;
18371837
AST->CaptureDiagnostics = CaptureDiagnostics;
18381838
AST->TUKind = TUKind;
@@ -2378,7 +2378,7 @@ bool ASTUnit::serialize(raw_ostream &OS) {
23782378

23792379
SmallString<128> Buffer;
23802380
llvm::BitstreamWriter Stream(Buffer);
2381-
IntrusiveRefCntPtr<ModuleCache> ModCache = getCrossProcessModuleCache();
2381+
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
23822382
ASTWriter Writer(Stream, Buffer, *ModCache, {});
23832383
return serializeUnit(Writer, Buffer, getSema(), OS);
23842384
}

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CompilerInstance::CompilerInstance(
7070
ModuleCache *ModCache)
7171
: ModuleLoader(/*BuildingModule=*/ModCache),
7272
Invocation(new CompilerInvocation()),
73-
ModCache(ModCache ? ModCache : getCrossProcessModuleCache()),
73+
ModCache(ModCache ? ModCache : createCrossProcessModuleCache()),
7474
ThePCHContainerOperations(std::move(PCHContainerOps)) {}
7575

7676
CompilerInstance::~CompilerInstance() {

clang/lib/Serialization/ModuleCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ class CrossProcessModuleCache : public ModuleCache {
3939
};
4040
} // namespace
4141

42-
IntrusiveRefCntPtr<ModuleCache> clang::getCrossProcessModuleCache() {
42+
IntrusiveRefCntPtr<ModuleCache> clang::createCrossProcessModuleCache() {
4343
return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>();
4444
}

0 commit comments

Comments
 (0)