Skip to content

Commit d695acf

Browse files
committed
Document 'standalone' Parameters
1 parent a77f059 commit d695acf

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed

include/swift/AST/FineGrainedDependencyFormat.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,32 @@ bool writeFineGrainedDependencyGraphToPath(DiagnosticEngine &diags,
135135
llvm::StringRef path,
136136
const SourceFileDepGraph &g);
137137

138+
/// Enumerates the supported set of purposes for writing out or reading in
139+
/// swift dependency information into a file. These can be used to influence
140+
/// the structure of the resulting data that is produced by the serialization
141+
/// machinery defined here.
142+
enum class Purpose : bool {
143+
/// Write out fine grained dependency metadata suitable for embedding in
144+
/// \c .swiftmodule file.
145+
///
146+
/// The resulting metadata does not contain the usual block descriptor header
147+
/// nor does it contain a leading magic signature, which would otherwise
148+
/// disrupt clients and tools that do not expect them to be present such as
149+
/// llvm-bcanalyzer.
150+
ForSwiftModule = false,
151+
/// Write out fine grained dependency metadata suitable for a standalone
152+
/// \c .swiftdeps file.
153+
///
154+
/// The resulting metadata will contain a leading magic signature and block
155+
/// descriptor header.
156+
ForSwiftDeps = true,
157+
};
158+
159+
/// Tries to write out the given dependency graph with the given
160+
/// bitstream writer.
138161
void writeFineGrainedDependencyGraph(llvm::BitstreamWriter &Out,
139162
const SourceFileDepGraph &g,
140-
bool standalone);
163+
Purpose purpose);
141164

142165
} // namespace fine_grained_dependencies
143166
} // namespace swift

lib/AST/FineGrainedDependencyFormat.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Deserializer {
4444

4545
public:
4646
Deserializer(llvm::MemoryBufferRef Data) : Cursor(Data) {}
47-
bool readFineGrainedDependencyGraph(SourceFileDepGraph &g, bool standalone);
47+
bool readFineGrainedDependencyGraph(SourceFileDepGraph &g, Purpose purpose);
4848
bool readFineGrainedDependencyGraphFromSwiftModule(SourceFileDepGraph &g);
4949
};
5050

@@ -152,14 +152,23 @@ static llvm::Optional<DeclAspect> getDeclAspect(unsigned declAspect) {
152152
}
153153

154154
bool Deserializer::readFineGrainedDependencyGraph(SourceFileDepGraph &g,
155-
bool standalone) {
155+
Purpose purpose) {
156156
using namespace record_block;
157157

158-
if (standalone && readSignature())
159-
return true;
158+
switch (purpose) {
159+
case Purpose::ForSwiftDeps:
160+
if (readSignature())
161+
return true;
160162

161-
if (standalone && enterTopLevelBlock())
162-
return true;
163+
if (enterTopLevelBlock())
164+
return true;
165+
LLVM_FALLTHROUGH;
166+
case Purpose::ForSwiftModule:
167+
// N.B. Incremental metadata embedded in swiftmodule files does not have
168+
// a leading signature, and its top-level block has already been
169+
// consumed by the time we get here.
170+
break;
171+
}
163172

164173
if (readMetadata())
165174
return true;
@@ -261,7 +270,7 @@ bool Deserializer::readFineGrainedDependencyGraph(SourceFileDepGraph &g,
261270
bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph(
262271
llvm::MemoryBuffer &buffer, SourceFileDepGraph &g) {
263272
Deserializer deserializer(buffer.getMemBufferRef());
264-
return deserializer.readFineGrainedDependencyGraph(g, /*standalone*/true);
273+
return deserializer.readFineGrainedDependencyGraph(g, Purpose::ForSwiftDeps);
265274
}
266275

267276
bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph(
@@ -324,7 +333,7 @@ class Serializer {
324333

325334
public:
326335
void writeFineGrainedDependencyGraph(const SourceFileDepGraph &g,
327-
bool standalone);
336+
Purpose purpose);
328337
};
329338

330339
} // end namespace
@@ -385,13 +394,19 @@ void Serializer::writeMetadata() {
385394

386395
void
387396
Serializer::writeFineGrainedDependencyGraph(const SourceFileDepGraph &g,
388-
bool standalone) {
389-
auto blockID = INCREMENTAL_INFORMATION_BLOCK_ID;
390-
if (standalone) {
397+
Purpose purpose) {
398+
unsigned blockID = 0;
399+
switch (purpose) {
400+
case Purpose::ForSwiftDeps:
391401
writeSignature();
392402
writeBlockInfoBlock();
393403
blockID = RECORD_BLOCK_ID;
404+
break;
405+
case Purpose::ForSwiftModule:
406+
blockID = INCREMENTAL_INFORMATION_BLOCK_ID;
407+
break;
394408
}
409+
395410
llvm::BCBlockRAII restoreBlock(Out, blockID, 8);
396411

397412
using namespace record_block;
@@ -474,9 +489,10 @@ unsigned Serializer::getIdentifier(StringRef str) {
474489
}
475490

476491
void swift::fine_grained_dependencies::writeFineGrainedDependencyGraph(
477-
llvm::BitstreamWriter &Out, const SourceFileDepGraph &g, bool standalone) {
492+
llvm::BitstreamWriter &Out, const SourceFileDepGraph &g,
493+
Purpose purpose) {
478494
Serializer serializer{Out};
479-
serializer.writeFineGrainedDependencyGraph(g, standalone);
495+
serializer.writeFineGrainedDependencyGraph(g, purpose);
480496
}
481497

482498
bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath(
@@ -486,7 +502,7 @@ bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath(
486502
return withOutputFile(diags, path, [&](llvm::raw_ostream &out) {
487503
SmallVector<char, 0> Buffer;
488504
llvm::BitstreamWriter Writer{Buffer};
489-
writeFineGrainedDependencyGraph(Writer, g, /*standalone*/ true);
505+
writeFineGrainedDependencyGraph(Writer, g, Purpose::ForSwiftDeps);
490506
out.write(Buffer.data(), Buffer.size());
491507
out.flush();
492508
return false;
@@ -578,7 +594,7 @@ bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule(
578594
consumeError(std::move(Err));
579595
return false;
580596
}
581-
if (readFineGrainedDependencyGraph(g, /*standalone*/ false)) {
597+
if (readFineGrainedDependencyGraph(g, Purpose::ForSwiftModule)) {
582598
break;
583599
}
584600

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ ModuleDepGraph::Changes ModuleDepGraph::loadFromSwiftModuleBuffer(
120120
SourceFileDepGraph::loadFromSwiftModuleBuffer(buffer);
121121
if (!sourceFileDepGraph)
122122
return None;
123-
jobsBySwiftDeps.insert(std::make_pair(buffer.getBufferIdentifier(), Cmd));
123+
jobsBySwiftDeps[buffer.getBufferIdentifier().str()] = Cmd;
124124
auto changes = integrate(*sourceFileDepGraph, buffer.getBufferIdentifier());
125125
if (verifyFineGrainedDependencyGraphAfterEveryImport)
126126
verify();

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5240,7 +5240,7 @@ void Serializer::writeToStream(
52405240
S.writeAST(DC);
52415241
if (options.ExperimentalCrossModuleIncrementalInfo && DepGraph) {
52425242
fine_grained_dependencies::writeFineGrainedDependencyGraph(
5243-
S.Out, *DepGraph, /*standalone*/ false);
5243+
S.Out, *DepGraph, fine_grained_dependencies::Purpose::ForSwiftModule);
52445244
}
52455245
}
52465246

0 commit comments

Comments
 (0)