@@ -44,7 +44,7 @@ class Deserializer {
4444
4545public:
4646 Deserializer (llvm::MemoryBufferRef Data) : Cursor(Data) {}
47- bool readFineGrainedDependencyGraph (SourceFileDepGraph &g);
47+ bool readFineGrainedDependencyGraph (SourceFileDepGraph &g, bool standalone );
4848 bool readFineGrainedDependencyGraphFromSwiftModule (SourceFileDepGraph &g);
4949};
5050
@@ -151,13 +151,14 @@ static llvm::Optional<DeclAspect> getDeclAspect(unsigned declAspect) {
151151 return None;
152152}
153153
154- bool Deserializer::readFineGrainedDependencyGraph (SourceFileDepGraph &g) {
154+ bool Deserializer::readFineGrainedDependencyGraph (SourceFileDepGraph &g,
155+ bool standalone) {
155156 using namespace record_block ;
156157
157- if (readSignature ())
158+ if (standalone && readSignature ())
158159 return true ;
159160
160- if (enterTopLevelBlock ())
161+ if (standalone && enterTopLevelBlock ())
161162 return true ;
162163
163164 if (readMetadata ())
@@ -260,7 +261,7 @@ bool Deserializer::readFineGrainedDependencyGraph(SourceFileDepGraph &g) {
260261bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph (
261262 llvm::MemoryBuffer &buffer, SourceFileDepGraph &g) {
262263 Deserializer deserializer (buffer.getMemBufferRef ());
263- return deserializer.readFineGrainedDependencyGraph (g);
264+ return deserializer.readFineGrainedDependencyGraph (g, /* standalone */ true );
264265}
265266
266267bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph (
@@ -322,7 +323,8 @@ class Serializer {
322323 Serializer (llvm::BitstreamWriter &ExistingOut) : Out(ExistingOut) {}
323324
324325public:
325- void writeFineGrainedDependencyGraph (const SourceFileDepGraph &g);
326+ void writeFineGrainedDependencyGraph (const SourceFileDepGraph &g,
327+ bool standalone);
326328};
327329
328330} // end namespace
@@ -382,11 +384,15 @@ void Serializer::writeMetadata() {
382384}
383385
384386void
385- Serializer::writeFineGrainedDependencyGraph (const SourceFileDepGraph &g) {
386- writeSignature ();
387- writeBlockInfoBlock ();
388-
389- llvm::BCBlockRAII restoreBlock (Out, RECORD_BLOCK_ID, 8 );
387+ Serializer::writeFineGrainedDependencyGraph (const SourceFileDepGraph &g,
388+ bool standalone) {
389+ auto blockID = INCREMENTAL_INFORMATION_BLOCK_ID;
390+ if (standalone) {
391+ writeSignature ();
392+ writeBlockInfoBlock ();
393+ blockID = RECORD_BLOCK_ID;
394+ }
395+ llvm::BCBlockRAII restoreBlock (Out, blockID, 8 );
390396
391397 using namespace record_block ;
392398
@@ -468,9 +474,9 @@ unsigned Serializer::getIdentifier(StringRef str) {
468474}
469475
470476void swift::fine_grained_dependencies::writeFineGrainedDependencyGraph (
471- llvm::BitstreamWriter &Out, const SourceFileDepGraph &g) {
477+ llvm::BitstreamWriter &Out, const SourceFileDepGraph &g, bool standalone ) {
472478 Serializer serializer{Out};
473- serializer.writeFineGrainedDependencyGraph (g);
479+ serializer.writeFineGrainedDependencyGraph (g, standalone );
474480}
475481
476482bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath (
@@ -480,7 +486,7 @@ bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath(
480486 return withOutputFile (diags, path, [&](llvm::raw_ostream &out) {
481487 SmallVector<char , 0 > Buffer;
482488 llvm::BitstreamWriter Writer{Buffer};
483- writeFineGrainedDependencyGraph (Writer, g);
489+ writeFineGrainedDependencyGraph (Writer, g, /* standalone */ true );
484490 out.write (Buffer.data (), Buffer.size ());
485491 out.flush ();
486492 return false ;
@@ -516,7 +522,7 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, unsigned ID,
516522 if (next.Kind != llvm::BitstreamEntry::SubBlock)
517523 return false ;
518524
519- if (next.ID == RECORD_BLOCK_ID ) {
525+ if (next.ID == llvm::bitc::BLOCKINFO_BLOCK_ID ) {
520526 if (shouldReadBlockInfo) {
521527 if (!cursor.ReadBlockInfoBlock ())
522528 return false ;
@@ -531,7 +537,6 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, unsigned ID,
531537 return false ;
532538
533539 if (llvm::Error Err = cursor.EnterSubBlock (ID)) {
534- // FIXME this drops the error on the floor.
535540 consumeError (std::move (Err));
536541 return false ;
537542 }
@@ -549,12 +554,12 @@ bool swift::fine_grained_dependencies::
549554bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule (
550555 SourceFileDepGraph &g) {
551556 if (!checkModuleSignature (Cursor, {0xE2 , 0x9C , 0xA8 , 0x0E }) ||
552- !enterTopLevelModuleBlock (Cursor, RECORD_BLOCK_ID , false )) {
557+ !enterTopLevelModuleBlock (Cursor, llvm::bitc::FIRST_APPLICATION_BLOCKID , false )) {
553558 return false ;
554559 }
555560
556561 llvm::BitstreamEntry topLevelEntry;
557-
562+ bool ReadFineGrainedDependencies = false ;
558563 while (!Cursor.AtEndOfStream ()) {
559564 llvm::Expected<llvm::BitstreamEntry> maybeEntry =
560565 Cursor.advance (llvm::BitstreamCursor::AF_DontPopBlockAtEnd);
@@ -573,7 +578,11 @@ bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule(
573578 consumeError (std::move (Err));
574579 return false ;
575580 }
576- readFineGrainedDependencyGraph (g);
581+ if (readFineGrainedDependencyGraph (g, /* standalone*/ false )) {
582+ break ;
583+ }
584+
585+ ReadFineGrainedDependencies = true ;
577586 break ;
578587 }
579588
@@ -587,5 +596,5 @@ bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule(
587596 }
588597 }
589598
590- return false ;
599+ return ReadFineGrainedDependencies ;
591600}
0 commit comments