3333#include " swift/Option/Options.h"
3434#include " clang/CAS/CASOptions.h"
3535#include " clang/Frontend/CompileJobCacheResult.h"
36+ #include " clang/Frontend/FrontendOptions.h"
3637#include " llvm/ADT/ArrayRef.h"
3738#include " llvm/ADT/IntrusiveRefCntPtr.h"
3839#include " llvm/ADT/SmallVector.h"
@@ -933,6 +934,7 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
933934 Outputs.try_emplace (ID, File);
934935 });
935936 Outputs.try_emplace (file_types::TY_CachedDiagnostics, " <cached-diagnostics>" );
937+ Outputs.try_emplace (file_types::ID::TY_SymbolGraphFile, " <symbol-graph>" );
936938
937939 // Load all the output buffer.
938940 bool Remarks = Instance.Invocation .getCASOptions ().EnableCachingRemarks ;
@@ -944,6 +946,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
944946 SmallVector<OutputEntry> OutputProxies;
945947 std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
946948 bool UseCASBackend = Invocation.getIRGenOptions ().UseCASBackend ;
949+ const FrontendOptions &FrontendOpts =
950+ Inst.getInvocation ().getFrontendOptions ();
947951
948952 swift::cas::CachedResultLoader Loader (CAS, Comp.Output );
949953 if (auto Err = Loader.replay (
@@ -960,6 +964,32 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
960964 if (Kind == file_types::ID::TY_CachedDiagnostics) {
961965 assert (!DiagnosticsOutput && " more than 1 diagnostics found" );
962966 DiagnosticsOutput = std::move (*Proxy);
967+ } else if (Kind == file_types::ID::TY_SymbolGraphFile &&
968+ !FrontendOpts.SymbolGraphOutputDir .empty ()) {
969+ auto Err = Proxy->forEachReference ([&](llvm::cas::ObjectRef Ref)
970+ -> llvm::Error {
971+ auto Proxy = CAS.getProxy (Ref);
972+ if (!Proxy)
973+ return Proxy.takeError ();
974+ auto PathRef = Proxy->getReference (0 );
975+ auto ContentRef = Proxy->getReference (1 );
976+ auto Path = CAS.getProxy (PathRef);
977+ auto Content = CAS.getProxy (ContentRef);
978+ if (!Path)
979+ return Path.takeError ();
980+ if (!Content)
981+ return Content.takeError ();
982+
983+ SmallString<128 > OutputPath (FrontendOpts.SymbolGraphOutputDir );
984+ llvm::sys::path::append (OutputPath, Path->getData ());
985+
986+ OutputProxies.emplace_back (OutputEntry{
987+ std::string (OutputPath), std::move (*Content), Kind});
988+
989+ return Error::success ();
990+ });
991+ if (Err)
992+ return Err;
963993 } else
964994 OutputProxies.emplace_back (
965995 OutputEntry{OutputPath->second , std::move (*Proxy), Kind});
@@ -1010,10 +1040,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
10101040 Inst.getDiags ().diagnose (SourceLoc (), diag::error_mccas,
10111041 toString (std::move (E)));
10121042 } else if (Output.Kind == file_types::ID::TY_Dependencies) {
1013- if (emitMakeDependenciesFromSerializedBuffer (
1014- Output.Proxy .getData (), *File,
1015- Inst.getInvocation ().getFrontendOptions (), Input,
1016- Inst.getDiags ()))
1043+ if (emitMakeDependenciesFromSerializedBuffer (Output.Proxy .getData (),
1044+ *File, FrontendOpts, Input,
1045+ Inst.getDiags ()))
10171046 Inst.getDiags ().diagnose (SourceLoc (), diag::cache_replay_failed,
10181047 " failed to emit dependency file" );
10191048 } else
0 commit comments