Virtualize swift compiler outputs (#63206)

Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
This commit is contained in:
Steven Wu
2023-04-05 23:34:37 +08:00
committed by GitHub
parent 829491b230
commit 09b8af86fb
52 changed files with 690 additions and 327 deletions

View File

@@ -36,6 +36,9 @@
#include "swift/IDE/APIDigesterData.h"
#include "swift/Option/Options.h"
#include "swift/Parse/ParseVersion.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/VirtualOutputBackends.h"
#include "llvm/Support/raw_ostream.h"
#include <functional>
using namespace swift;
@@ -2536,13 +2539,18 @@ public:
switch (Action) {
case ActionType::DumpSDK: {
llvm::StringSet<> Modules;
return (prepareForDump(InitInvoke, Modules))
? 1
: dumpSDKContent(InitInvoke, Modules,
getJsonOutputFilePath(
InitInvoke.getLangOptions().Target,
CheckerOpts.ABI, OutputFile, OutputDir),
CheckerOpts);
if (prepareForDump(InitInvoke, Modules))
return 1;
auto JsonOut =
getJsonOutputFilePath(InitInvoke.getLangOptions().Target,
CheckerOpts.ABI, OutputFile, OutputDir);
std::error_code EC;
llvm::raw_fd_ostream fs(JsonOut, EC);
if (EC) {
llvm::errs() << "Cannot open JSON output file: " << JsonOut << "\n";
return 1;
}
return dumpSDKContent(InitInvoke, Modules, fs, CheckerOpts);
}
case ActionType::MigratorGen:
case ActionType::DiagnoseSDKs: {
@@ -2606,7 +2614,13 @@ public:
}
case ActionType::GenerateEmptyBaseline: {
SDKContext Ctx(CheckerOpts);
dumpSDKRoot(getEmptySDKNodeRoot(Ctx), OutputFile);
std::error_code EC;
llvm::raw_fd_ostream fs(OutputFile, EC);
if (EC) {
llvm::errs() << "Cannot open output file: " << OutputFile << "\n";
return 1;
}
dumpSDKRoot(getEmptySDKNodeRoot(Ctx), fs);
return 0;
}
case ActionType::FindUsr: {