-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clangd] [Modules] Use ASTReader directly in IsModuleFileUpToDate #113879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include "clang/Frontend/FrontendAction.h" | ||
#include "clang/Frontend/FrontendActions.h" | ||
#include "clang/Serialization/ASTReader.h" | ||
#include "clang/Serialization/InMemoryModuleCache.h" | ||
|
||
namespace clang { | ||
namespace clangd { | ||
|
@@ -127,50 +128,65 @@ struct ModuleFile { | |
std::string ModuleFilePath; | ||
}; | ||
|
||
bool IsModuleFileUpToDate( | ||
PathRef ModuleFilePath, | ||
const PrerequisiteModules &RequisiteModules) { | ||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags = | ||
CompilerInstance::createDiagnostics(new DiagnosticOptions()); | ||
|
||
bool IsModuleFileUpToDate(PathRef ModuleFilePath, | ||
const PrerequisiteModules &RequisiteModules, | ||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { | ||
auto HSOpts = std::make_shared<HeaderSearchOptions>(); | ||
RequisiteModules.adjustHeaderSearchOptions(*HSOpts); | ||
HSOpts->ForceCheckCXX20ModulesInputFiles = true; | ||
HSOpts->ValidateASTInputFilesContent = true; | ||
|
||
clang::clangd::IgnoreDiagnostics IgnoreDiags; | ||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags = | ||
CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, /*ShouldOwnClient=*/false); | ||
ChuanqiXu9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
LangOptions LangOpts; | ||
LangOpts.SkipODRCheckInGMF = true; | ||
|
||
FileManager FileMgr(FileSystemOptions(), VFS); | ||
|
||
SourceManager SourceMgr(*Diags, FileMgr); | ||
|
||
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts, | ||
/*Target=*/nullptr); | ||
|
||
TrivialModuleLoader ModuleLoader; | ||
Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts, | ||
SourceMgr, HeaderInfo, ModuleLoader); | ||
|
||
IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache = new InMemoryModuleCache; | ||
kadircet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PCHContainerOperations PCHOperations; | ||
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile( | ||
ModuleFilePath.str(), PCHOperations.getRawReader(), ASTUnit::LoadASTOnly, | ||
Diags, FileSystemOptions(), std::move(HSOpts)); | ||
ASTReader Reader(PP, *ModuleCache, /*ASTContext=*/nullptr, | ||
PCHOperations.getRawReader(), {}); | ||
|
||
if (!Unit) | ||
return false; | ||
Reader.setListener(std::make_unique<PPIntializer>(PP)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need a Listener? and where's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. It was not updated. I guess I had a typo when verify it by typing |
||
|
||
auto Reader = Unit->getASTReader(); | ||
if (!Reader) | ||
if (Reader.ReadAST(ModuleFilePath, serialization::MK_MainFile, | ||
SourceLocation(), | ||
ASTReader::ARR_None) != ASTReader::Success) | ||
return false; | ||
|
||
bool UpToDate = true; | ||
Reader->getModuleManager().visit([&](serialization::ModuleFile &MF) -> bool { | ||
Reader->visitInputFiles( | ||
Reader.getModuleManager().visit([&](serialization::ModuleFile &MF) -> bool { | ||
Reader.visitInputFiles( | ||
MF, /*IncludeSystem=*/false, /*Complain=*/false, | ||
[&](const serialization::InputFile &IF, bool isSystem) { | ||
if (!IF.getFile() || IF.isOutOfDate()) | ||
UpToDate = false; | ||
}); | ||
|
||
return !UpToDate; | ||
}); | ||
|
||
return UpToDate; | ||
} | ||
|
||
bool IsModuleFilesUpToDate( | ||
llvm::SmallVector<PathRef> ModuleFilePaths, | ||
const PrerequisiteModules &RequisiteModules) { | ||
return llvm::all_of(ModuleFilePaths, [&RequisiteModules](auto ModuleFilePath) { | ||
return IsModuleFileUpToDate(ModuleFilePath, RequisiteModules); | ||
}); | ||
const PrerequisiteModules &RequisiteModules, | ||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { | ||
return llvm::all_of( | ||
ModuleFilePaths, [&RequisiteModules, VFS](auto ModuleFilePath) { | ||
return IsModuleFileUpToDate(ModuleFilePath, RequisiteModules, VFS); | ||
}); | ||
} | ||
|
||
// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all | ||
|
@@ -347,7 +363,7 @@ bool StandalonePrerequisiteModules::canReuse( | |
SmallVector<StringRef> BMIPaths; | ||
for (auto &MF : RequiredModules) | ||
BMIPaths.push_back(MF.ModuleFilePath); | ||
return IsModuleFilesUpToDate(BMIPaths, *this); | ||
return IsModuleFilesUpToDate(BMIPaths, *this, VFS); | ||
} | ||
|
||
} // namespace clangd | ||
|
Uh oh!
There was an error while loading. Please reload this page.