mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -2470,11 +2470,10 @@ void SwiftDeclCollector::deSerialize(StringRef Filename) {
|
||||
}
|
||||
|
||||
// Serialize the content of all roots to a given file using JSON format.
|
||||
void SwiftDeclCollector::serialize(StringRef Filename, SDKNode *Root,
|
||||
void SwiftDeclCollector::serialize(llvm::raw_ostream &os, SDKNode *Root,
|
||||
PayLoad OtherInfo) {
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream fs(Filename, EC, llvm::sys::fs::OF_None);
|
||||
json::Output yout(fs);
|
||||
json::Output yout(os);
|
||||
assert(Root->getKind() == SDKNodeKind::Root);
|
||||
SDKNodeRoot &root = *static_cast<SDKNodeRoot*>(Root);
|
||||
yout.beginObject();
|
||||
@@ -2486,8 +2485,8 @@ void SwiftDeclCollector::serialize(StringRef Filename, SDKNode *Root,
|
||||
}
|
||||
|
||||
// Serialize the content of all roots to a given file using JSON format.
|
||||
void SwiftDeclCollector::serialize(StringRef Filename) {
|
||||
SwiftDeclCollector::serialize(Filename, RootNode, PayLoad());
|
||||
void SwiftDeclCollector::serialize(llvm::raw_ostream &os) {
|
||||
SwiftDeclCollector::serialize(os, RootNode, PayLoad());
|
||||
}
|
||||
|
||||
SDKNodeRoot *
|
||||
@@ -2550,28 +2549,26 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
|
||||
}
|
||||
|
||||
void swift::ide::api::dumpSDKRoot(SDKNodeRoot *Root, PayLoad load,
|
||||
StringRef OutputFile) {
|
||||
llvm::raw_ostream &os) {
|
||||
assert(Root);
|
||||
auto Opts = Root->getSDKContext().getOpts();
|
||||
if (Opts.Verbose)
|
||||
llvm::errs() << "Dumping SDK...\n";
|
||||
SwiftDeclCollector::serialize(OutputFile, Root, load);
|
||||
if (Opts.Verbose)
|
||||
llvm::errs() << "Dumped to "<< OutputFile << "\n";
|
||||
SwiftDeclCollector::serialize(os, Root, load);
|
||||
}
|
||||
|
||||
void swift::ide::api::dumpSDKRoot(SDKNodeRoot *Root, StringRef OutputFile) {
|
||||
dumpSDKRoot(Root, PayLoad(), OutputFile);
|
||||
void swift::ide::api::dumpSDKRoot(SDKNodeRoot *Root, llvm::raw_ostream &os) {
|
||||
dumpSDKRoot(Root, PayLoad(), os);
|
||||
}
|
||||
|
||||
int swift::ide::api::dumpSDKContent(const CompilerInvocation &InitInvoke,
|
||||
const llvm::StringSet<> &ModuleNames,
|
||||
StringRef OutputFile, CheckerOptions Opts) {
|
||||
llvm::raw_ostream &os, CheckerOptions Opts) {
|
||||
SDKContext SDKCtx(Opts);
|
||||
SDKNodeRoot *Root = getSDKNodeRoot(SDKCtx, InitInvoke, ModuleNames);
|
||||
if (!Root)
|
||||
return 1;
|
||||
dumpSDKRoot(Root, OutputFile);
|
||||
dumpSDKRoot(Root, os);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2589,11 +2586,11 @@ int swift::ide::api::deserializeSDKDump(StringRef dumpPath, StringRef OutputPath
|
||||
|
||||
SwiftDeclCollector Collector(Ctx);
|
||||
Collector.deSerialize(dumpPath);
|
||||
Collector.serialize(OutputPath);
|
||||
Collector.serialize(FS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void swift::ide::api::dumpModuleContent(ModuleDecl *MD, StringRef OutputFile,
|
||||
void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
|
||||
bool ABI, bool Empty) {
|
||||
CheckerOptions opts;
|
||||
opts.ABI = ABI;
|
||||
@@ -2610,7 +2607,7 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, StringRef OutputFile,
|
||||
PayLoad payload;
|
||||
SWIFT_DEFER {
|
||||
payload.allContsValues = &extractor.getAllConstValues();
|
||||
dumpSDKRoot(collector.getSDKRoot(), payload, OutputFile);
|
||||
dumpSDKRoot(collector.getSDKRoot(), payload, os);
|
||||
};
|
||||
if (Empty) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user