ModuleInterface: refactor compiler instance configuration to a standalone delegate class. NFC

Module interface builder used to maintain a separate compiler instance for
building Swift modules. The configuration of this compiler instance is also
useful for dependencies scanner because it needs to emit front-end compiler invocation
for building Swift modules explicitly.

This patch refactor the configuration out to a delegate class, and the
delegate class is also used by the dependency scanner.
This commit is contained in:
Xi Ge
2020-05-11 14:33:15 -07:00
parent c5503cee21
commit 3952fd5bf7
15 changed files with 414 additions and 372 deletions

View File

@@ -108,6 +108,7 @@
#define SWIFT_FRONTEND_MODULEINTERFACELOADER_H
#include "swift/Basic/LLVM.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/ModuleInterfaceSupport.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "llvm/Support/StringSaver.h"
@@ -203,18 +204,65 @@ public:
std::string
getModuleCachePathFromClang(const clang::CompilerInstance &Instance);
bool extractSwiftInterfaceVersionAndArgs(SourceManager &SM,
DiagnosticEngine &Diags,
StringRef InterfacePath,
version::Version &Vers,
StringRef &CompilerVersion,
llvm::StringSaver &SubArgSaver,
SmallVectorImpl<const char *> &SubArgs,
SourceLoc diagnosticLoc = SourceLoc());
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
private:
SourceManager &SM;
DiagnosticEngine &Diags;
CompilerInvocation subInvocation;
void inheritOptionsForBuildingInterface(CompilerInvocation &Invok,
const SearchPathOptions &SearchPathOpts,
const LangOptions &LangOpts);
template<typename ...ArgTypes>
InFlightDiagnostic diagnose(StringRef interfacePath,
SourceLoc diagnosticLoc,
Diag<ArgTypes...> ID,
typename detail::PassArgument<ArgTypes>::type... Args) {
SourceLoc loc = diagnosticLoc;
if (diagnosticLoc.isInvalid()) {
// Diagnose this inside the interface file, if possible.
loc = SM.getLocFromExternalSource(interfacePath, 1, 1);
}
return Diags.diagnose(loc, ID, std::move(Args)...);
}
bool extractSwiftInterfaceVersionAndArgs(llvm::StringSaver &SubArgSaver,
SmallVectorImpl<const char *> &SubArgs,
std::string &CompilerVersion,
StringRef interfacePath,
SourceLoc diagnosticLoc);
SubCompilerInstanceInfo createInstance(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc);
public:
InterfaceSubContextDelegateImpl(SourceManager &SM,
DiagnosticEngine &Diags,
const SearchPathOptions &searchPathOpts,
const LangOptions &langOpts,
ClangModuleLoader *clangImporter = nullptr,
StringRef moduleCachePath = StringRef(),
StringRef prebuiltCachePath = StringRef(),
bool serializeDependencyHashes = false,
bool trackSystemDependencies = false,
bool remarkOnRebuildFromInterface = false,
bool disableInterfaceFileLock = false);
bool runInSubContext(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<bool(ASTContext&)> action) override;
bool runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
~InterfaceSubContextDelegateImpl() = default;
/// includes a hash of relevant key data.
void computeCachedOutputPath(StringRef moduleName,
StringRef UseInterfacePath,
llvm::SmallString<256> &OutPath);
std::string getCacheHash(StringRef useInterfacePath);
};
}
#endif