aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-05-14 14:31:23 -0700
committerGitHub <noreply@github.com>2025-05-14 14:31:23 -0700
commit960afcc90e8fb75b725ed331f4bc60eb2398d6e5 (patch)
tree9415bb216da3f252bc15f7c43218b695f0238f04 /clang/lib/Serialization
parenta608b4914209f4238fe83a6b5fa8fd7219f11115 (diff)
downloadllvm-960afcc90e8fb75b725ed331f4bc60eb2398d6e5.zip
llvm-960afcc90e8fb75b725ed331f4bc60eb2398d6e5.tar.gz
llvm-960afcc90e8fb75b725ed331f4bc60eb2398d6e5.tar.bz2
[clang][modules] Timestamp-less validation API (#138983)
Timestamps are an implementation detail of the cross-process module cache implementation. This PR hides it from the `ModuleCache` API, which simplifies the in-process implementation.
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp9
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp2
-rw-r--r--clang/lib/Serialization/ModuleCache.cpp20
-rw-r--r--clang/lib/Serialization/ModuleManager.cpp6
4 files changed, 21 insertions, 16 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index d068f5e1..2462b5c 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3103,8 +3103,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
unsigned N = ValidateSystemInputs ? NumInputs : NumUserInputs;
if (HSOpts.ModulesValidateOncePerBuildSession &&
- F.InputFilesValidationTimestamp > HSOpts.BuildSessionTimestamp &&
- F.Kind == MK_ImplicitModule)
+ F.InputFilesValidated && F.Kind == MK_ImplicitModule)
N = ForceValidateUserInputs ? NumUserInputs : 0;
for (unsigned I = 0; I < N; ++I) {
@@ -4950,10 +4949,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, ModuleKind Type,
// timestamp files are up-to-date in this build session.
for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
ImportedModule &M = Loaded[I];
- if (M.Mod->Kind == MK_ImplicitModule &&
- M.Mod->InputFilesValidationTimestamp < HSOpts.BuildSessionTimestamp)
- getModuleManager().getModuleCache().updateModuleTimestamp(
- M.Mod->FileName);
+ if (M.Mod->Kind == MK_ImplicitModule && !M.Mod->InputFilesValidated)
+ getModuleManager().getModuleCache().markUpToDate(M.Mod->FileName);
}
}
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 1b3d3c2..491149b 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5391,7 +5391,7 @@ ASTWriter::WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
if (WritingModule && PPRef.getHeaderSearchInfo()
.getHeaderSearchOpts()
.ModulesValidateOncePerBuildSession)
- ModCache.updateModuleTimestamp(OutputFile);
+ ModCache.markUpToDate(OutputFile);
if (ShouldCacheASTInMemory) {
// Construct MemoryBuffer and update buffer manager.
diff --git a/clang/lib/Serialization/ModuleCache.cpp b/clang/lib/Serialization/ModuleCache.cpp
index 4ae49c4..43f8ff8 100644
--- a/clang/lib/Serialization/ModuleCache.cpp
+++ b/clang/lib/Serialization/ModuleCache.cpp
@@ -20,7 +20,12 @@ namespace {
class CrossProcessModuleCache : public ModuleCache {
InMemoryModuleCache InMemory;
+ std::time_t BuildSessionTimestamp;
+
public:
+ explicit CrossProcessModuleCache(std::time_t BuildSessionTimestamp)
+ : BuildSessionTimestamp(BuildSessionTimestamp) {}
+
void prepareForGetLock(StringRef ModuleFilename) override {
// FIXME: Do this in LockFileManager and only if the directory doesn't
// exist.
@@ -33,16 +38,17 @@ public:
return std::make_unique<llvm::LockFileManager>(ModuleFilename);
}
- std::time_t getModuleTimestamp(StringRef ModuleFilename) override {
+ bool isMarkedUpToDate(StringRef ModuleFilename) override {
std::string TimestampFilename =
serialization::ModuleFile::getTimestampFilename(ModuleFilename);
llvm::sys::fs::file_status Status;
if (llvm::sys::fs::status(ModuleFilename, Status) != std::error_code{})
- return 0;
- return llvm::sys::toTimeT(Status.getLastModificationTime());
+ return false;
+ return llvm::sys::toTimeT(Status.getLastModificationTime()) >
+ BuildSessionTimestamp;
}
- void updateModuleTimestamp(StringRef ModuleFilename) override {
+ void markUpToDate(StringRef ModuleFilename) override {
// Overwrite the timestamp file contents so that file's mtime changes.
std::error_code EC;
llvm::raw_fd_ostream OS(
@@ -62,6 +68,8 @@ public:
};
} // namespace
-IntrusiveRefCntPtr<ModuleCache> clang::createCrossProcessModuleCache() {
- return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>();
+IntrusiveRefCntPtr<ModuleCache>
+clang::createCrossProcessModuleCache(std::time_t BuildSessionTimestamp) {
+ return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>(
+ BuildSessionTimestamp);
}
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index fa9533b..9fd7505 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -174,11 +174,11 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
NewModule->Index = Chain.size();
NewModule->FileName = FileName.str();
NewModule->ImportLoc = ImportLoc;
- NewModule->InputFilesValidationTimestamp = 0;
+ NewModule->InputFilesValidated = false;
if (NewModule->Kind == MK_ImplicitModule)
- NewModule->InputFilesValidationTimestamp =
- ModCache->getModuleTimestamp(NewModule->FileName);
+ NewModule->InputFilesValidated =
+ ModCache->isMarkedUpToDate(NewModule->FileName);
// Load the contents of the module
if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) {