Mirror outputs into CAS using CASOutputBackend

When `-enable-cas` option is used, mirror the output into CAS so it can
be fetched from CAS with the cache key in the future.
This commit is contained in:
Steven Wu
2023-04-18 13:37:39 -07:00
parent c153210505
commit 8cbf83f903
13 changed files with 448 additions and 14 deletions

View File

@@ -26,6 +26,7 @@
#include "swift/Basic/FileTypes.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/Statistic.h"
#include "swift/Frontend/CachingUtils.h"
#include "swift/Frontend/CompileJobCacheKey.h"
#include "swift/Frontend/ModuleInterfaceLoader.h"
#include "swift/Parse/Lexer.h"
@@ -448,6 +449,15 @@ void CompilerInstance::setupOutputBackend() {
OutputBackend =
llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
// Mirror the output into CAS.
if (supportCaching()) {
auto CASOutputBackend = createSwiftCachingOutputBackend(
*CAS, *ResultCache, *CompileJobBaseKey,
Invocation.getFrontendOptions().InputsAndOutputs);
OutputBackend =
llvm::vfs::makeMirroringOutputBackend(OutputBackend, CASOutputBackend);
}
// Setup verification backend.
// Create a mirroring outputbackend to produce hash for output files.
// We cannot skip disk here since swift compiler is expecting to read back
@@ -1043,6 +1053,14 @@ bool CompilerInstance::canImportCxxShim() const {
!Invocation.getFrontendOptions().InputsAndOutputs.hasModuleInterfaceOutputPath();
}
bool CompilerInstance::supportCaching() const {
if (!Invocation.getFrontendOptions().EnableCAS)
return false;
return FrontendOptions::supportCompilationCaching(
Invocation.getFrontendOptions().RequestedAction);
}
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
auto &frontendOpts = Invocation.getFrontendOptions();