@@ -44,7 +44,7 @@ class Deserializer {
44
44
45
45
public:
46
46
Deserializer (llvm::MemoryBufferRef Data) : Cursor(Data) {}
47
- bool readFineGrainedDependencyGraph (SourceFileDepGraph &g);
47
+ bool readFineGrainedDependencyGraph (SourceFileDepGraph &g, bool standalone );
48
48
bool readFineGrainedDependencyGraphFromSwiftModule (SourceFileDepGraph &g);
49
49
};
50
50
@@ -151,13 +151,14 @@ static llvm::Optional<DeclAspect> getDeclAspect(unsigned declAspect) {
151
151
return None;
152
152
}
153
153
154
- bool Deserializer::readFineGrainedDependencyGraph (SourceFileDepGraph &g) {
154
+ bool Deserializer::readFineGrainedDependencyGraph (SourceFileDepGraph &g,
155
+ bool standalone) {
155
156
using namespace record_block ;
156
157
157
- if (readSignature ())
158
+ if (standalone && readSignature ())
158
159
return true ;
159
160
160
- if (enterTopLevelBlock ())
161
+ if (standalone && enterTopLevelBlock ())
161
162
return true ;
162
163
163
164
if (readMetadata ())
@@ -260,7 +261,7 @@ bool Deserializer::readFineGrainedDependencyGraph(SourceFileDepGraph &g) {
260
261
bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph (
261
262
llvm::MemoryBuffer &buffer, SourceFileDepGraph &g) {
262
263
Deserializer deserializer (buffer.getMemBufferRef ());
263
- return deserializer.readFineGrainedDependencyGraph (g);
264
+ return deserializer.readFineGrainedDependencyGraph (g, /* standalone */ true );
264
265
}
265
266
266
267
bool swift::fine_grained_dependencies::readFineGrainedDependencyGraph (
@@ -322,7 +323,8 @@ class Serializer {
322
323
Serializer (llvm::BitstreamWriter &ExistingOut) : Out(ExistingOut) {}
323
324
324
325
public:
325
- void writeFineGrainedDependencyGraph (const SourceFileDepGraph &g);
326
+ void writeFineGrainedDependencyGraph (const SourceFileDepGraph &g,
327
+ bool standalone);
326
328
};
327
329
328
330
} // end namespace
@@ -382,11 +384,15 @@ void Serializer::writeMetadata() {
382
384
}
383
385
384
386
void
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 );
390
396
391
397
using namespace record_block ;
392
398
@@ -468,9 +474,9 @@ unsigned Serializer::getIdentifier(StringRef str) {
468
474
}
469
475
470
476
void swift::fine_grained_dependencies::writeFineGrainedDependencyGraph (
471
- llvm::BitstreamWriter &Out, const SourceFileDepGraph &g) {
477
+ llvm::BitstreamWriter &Out, const SourceFileDepGraph &g, bool standalone ) {
472
478
Serializer serializer{Out};
473
- serializer.writeFineGrainedDependencyGraph (g);
479
+ serializer.writeFineGrainedDependencyGraph (g, standalone );
474
480
}
475
481
476
482
bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath (
@@ -480,7 +486,7 @@ bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath(
480
486
return withOutputFile (diags, path, [&](llvm::raw_ostream &out) {
481
487
SmallVector<char , 0 > Buffer;
482
488
llvm::BitstreamWriter Writer{Buffer};
483
- writeFineGrainedDependencyGraph (Writer, g);
489
+ writeFineGrainedDependencyGraph (Writer, g, /* standalone */ true );
484
490
out.write (Buffer.data (), Buffer.size ());
485
491
out.flush ();
486
492
return false ;
@@ -516,7 +522,7 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, unsigned ID,
516
522
if (next.Kind != llvm::BitstreamEntry::SubBlock)
517
523
return false ;
518
524
519
- if (next.ID == RECORD_BLOCK_ID ) {
525
+ if (next.ID == llvm::bitc::BLOCKINFO_BLOCK_ID ) {
520
526
if (shouldReadBlockInfo) {
521
527
if (!cursor.ReadBlockInfoBlock ())
522
528
return false ;
@@ -531,7 +537,6 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor, unsigned ID,
531
537
return false ;
532
538
533
539
if (llvm::Error Err = cursor.EnterSubBlock (ID)) {
534
- // FIXME this drops the error on the floor.
535
540
consumeError (std::move (Err));
536
541
return false ;
537
542
}
@@ -549,12 +554,12 @@ bool swift::fine_grained_dependencies::
549
554
bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule (
550
555
SourceFileDepGraph &g) {
551
556
if (!checkModuleSignature (Cursor, {0xE2 , 0x9C , 0xA8 , 0x0E }) ||
552
- !enterTopLevelModuleBlock (Cursor, RECORD_BLOCK_ID , false )) {
557
+ !enterTopLevelModuleBlock (Cursor, llvm::bitc::FIRST_APPLICATION_BLOCKID , false )) {
553
558
return false ;
554
559
}
555
560
556
561
llvm::BitstreamEntry topLevelEntry;
557
-
562
+ bool ReadFineGrainedDependencies = false ;
558
563
while (!Cursor.AtEndOfStream ()) {
559
564
llvm::Expected<llvm::BitstreamEntry> maybeEntry =
560
565
Cursor.advance (llvm::BitstreamCursor::AF_DontPopBlockAtEnd);
@@ -573,7 +578,11 @@ bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule(
573
578
consumeError (std::move (Err));
574
579
return false ;
575
580
}
576
- readFineGrainedDependencyGraph (g);
581
+ if (readFineGrainedDependencyGraph (g, /* standalone*/ false )) {
582
+ break ;
583
+ }
584
+
585
+ ReadFineGrainedDependencies = true ;
577
586
break ;
578
587
}
579
588
@@ -587,5 +596,5 @@ bool Deserializer::readFineGrainedDependencyGraphFromSwiftModule(
587
596
}
588
597
}
589
598
590
- return false ;
599
+ return ReadFineGrainedDependencies ;
591
600
}
0 commit comments