20
20
#include " swift/Frontend/CompileJobCacheKey.h"
21
21
#include " swift/Frontend/CompileJobCacheResult.h"
22
22
#include " swift/Frontend/FrontendOptions.h"
23
+ #include " swift/Frontend/MakeStyleDependencies.h"
23
24
#include " swift/Option/Options.h"
24
25
#include " clang/CAS/CASOptions.h"
25
26
#include " clang/CAS/IncludeTree.h"
@@ -135,19 +136,21 @@ lookupCacheKey(ObjectStore &CAS, ActionCache &Cache, ObjectRef CacheKey) {
135
136
136
137
bool replayCachedCompilerOutputs (
137
138
ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
138
- DiagnosticEngine &Diag, const FrontendInputsAndOutputs &InputsAndOutputs ,
139
+ DiagnosticEngine &Diag, const FrontendOptions &Opts ,
139
140
CachingDiagnosticsProcessor &CDP, bool CacheRemarks, bool UseCASBackend) {
140
141
bool CanReplayAllOutput = true ;
141
142
struct OutputEntry {
142
143
std::string Path;
143
144
CASID Key;
145
+ file_types::ID Kind;
146
+ const InputFile &Input;
144
147
ObjectProxy Proxy;
145
148
};
146
149
SmallVector<OutputEntry> OutputProxies;
147
150
std::optional<OutputEntry> DiagnosticsOutput;
148
- std::string ObjFile;
149
151
150
- auto replayOutputsForInputFile = [&](const std::string &InputPath,
152
+ auto replayOutputsForInputFile = [&](const InputFile &Input,
153
+ const std::string &InputPath,
151
154
unsigned InputIndex,
152
155
const DenseMap<file_types::ID,
153
156
std::string> &Outputs) {
@@ -190,15 +193,13 @@ bool replayCachedCompilerOutputs(
190
193
if (!Proxy)
191
194
return Proxy.takeError ();
192
195
193
- if (Kind == file_types::ID::TY_Object && UseCASBackend)
194
- ObjFile = OutputPath->second ;
195
-
196
196
if (Kind == file_types::ID::TY_CachedDiagnostics) {
197
197
assert (!DiagnosticsOutput && " more than 1 diagnotics found" );
198
- DiagnosticsOutput = OutputEntry{OutputPath->second , OutID, *Proxy};
198
+ DiagnosticsOutput.emplace (
199
+ OutputEntry{OutputPath->second , OutID, Kind, Input, *Proxy});
199
200
} else
200
201
OutputProxies.emplace_back (
201
- OutputEntry{OutputPath->second , OutID, *Proxy});
202
+ OutputEntry{OutputPath->second , OutID, Kind, Input, *Proxy});
202
203
return Error::success ();
203
204
})) {
204
205
Diag.diagnose (SourceLoc (), diag::error_cas, toString (std::move (Err)));
@@ -211,7 +212,7 @@ bool replayCachedCompilerOutputs(
211
212
auto InputPath = Input.getFileName ();
212
213
DenseMap<file_types::ID, std::string> Outputs;
213
214
if (!Input.outputFilename ().empty ())
214
- Outputs.try_emplace (InputsAndOutputs.getPrincipalOutputType (),
215
+ Outputs.try_emplace (Opts. InputsAndOutputs .getPrincipalOutputType (),
215
216
Input.outputFilename ());
216
217
217
218
Input.getPrimarySpecificPaths ()
@@ -233,15 +234,15 @@ bool replayCachedCompilerOutputs(
233
234
Outputs.try_emplace (file_types::ID::TY_CachedDiagnostics,
234
235
" <cached-diagnostics>" );
235
236
236
- return replayOutputsForInputFile (InputPath, InputIndex, Outputs);
237
+ return replayOutputsForInputFile (Input, InputPath, InputIndex, Outputs);
237
238
};
238
239
239
- auto AllInputs = InputsAndOutputs.getAllInputs ();
240
+ auto AllInputs = Opts. InputsAndOutputs .getAllInputs ();
240
241
// If there are primary inputs, look up only the primary input files.
241
242
// Otherwise, prepare to do cache lookup for all inputs.
242
243
for (unsigned Index = 0 ; Index < AllInputs.size (); ++Index) {
243
244
const auto &Input = AllInputs[Index];
244
- if (InputsAndOutputs.hasPrimaryInputs () && !Input.isPrimary ())
245
+ if (Opts. InputsAndOutputs .hasPrimaryInputs () && !Input.isPrimary ())
245
246
continue ;
246
247
247
248
replayOutputFromInput (Input, Index);
@@ -255,8 +256,9 @@ bool replayCachedCompilerOutputs(
255
256
// diagnostics from first file.
256
257
if (!DiagnosticsOutput)
257
258
replayOutputsForInputFile (
259
+ Opts.InputsAndOutputs .getFirstOutputProducingInput (),
258
260
" <cached-diagnostics>" ,
259
- InputsAndOutputs.getIndexOfFirstOutputProducingInput (),
261
+ Opts. InputsAndOutputs .getIndexOfFirstOutputProducingInput (),
260
262
{{file_types::ID::TY_CachedDiagnostics, " <cached-diagnostics>" }});
261
263
262
264
// Check again to make sure diagnostics is fetched successfully.
@@ -287,10 +289,16 @@ bool replayCachedCompilerOutputs(
287
289
continue ;
288
290
}
289
291
290
- if (UseCASBackend && Output.Path == ObjFile ) {
292
+ if (UseCASBackend && Output.Kind == file_types::ID::TY_Object ) {
291
293
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
292
- if (auto E = Schema->serializeObjectFile (Output.Proxy , *File))
294
+ if (auto E = Schema->serializeObjectFile (Output.Proxy , *File)) {
293
295
Diag.diagnose (SourceLoc (), diag::error_mccas, toString (std::move (E)));
296
+ return false ;
297
+ }
298
+ } else if (Output.Kind == file_types::ID::TY_Dependencies) {
299
+ if (emitMakeDependenciesFromSerializedBuffer (
300
+ Output.Proxy .getData (), *File, Opts, Output.Input , Diag))
301
+ return false ;
294
302
} else
295
303
*File << Output.Proxy .getData ();
296
304
0 commit comments