@@ -609,6 +609,8 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
609
609
// We can't deserialize function bodies after IRGen lowering passes have
610
610
// happened since other definitions in the module will no longer be in
611
611
// canonical SIL form.
612
+ assert (!forDebugScope || declarationOnly); // debug scopes must always be read
613
+ // declaration only
612
614
switch (SILMod.getStage ()) {
613
615
case SILStage::Raw:
614
616
case SILStage::Canonical:
@@ -628,12 +630,29 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
628
630
auto &cacheEntry = Funcs[FID - 1 ];
629
631
630
632
if (cacheEntry.isFullyDeserialized () ||
631
- (cacheEntry.isDeserialized () && ( declarationOnly || forDebugScope) )) {
633
+ (cacheEntry.isDeserialized () && declarationOnly)) {
632
634
auto fn = cacheEntry.get ();
633
635
634
- if (fn->isZombie () && !forDebugScope)
635
- return nullptr ;
636
- return fn;
636
+ // Functions onlyReferencedByDebugInfo (A) are a subset of functions
637
+ // referred to by debug scopes forDebugScope=true (B)
638
+
639
+ // I) Functions in A U B only ever get deserialized as zombies
640
+
641
+ // II) For rest of functions (B - A), there are two orders of
642
+ // deserialization:
643
+ // i) Deserialized for debugging -> deserialized by linker/optimizer:
644
+ // a) Deserialize as zombie. When referenced by linker/optimizer,
645
+ // createDeclaration would resurrect function as normal
646
+ // ii) Deserialized by linker/optimizer -> deserialized for debugging ->
647
+ // no zombie created
648
+
649
+ if (fn->isZombie () && !forDebugScope) {
650
+ if (cacheEntry.isFullyDeserialized ())
651
+ return nullptr ;
652
+ // else function resurrected below by createDeclaration
653
+ } else {
654
+ return fn;
655
+ }
637
656
}
638
657
639
658
BCOffsetRAII restoreOffset (SILCursor);
@@ -836,7 +855,7 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
836
855
837
856
// TODO: for functions deserialized for debug scopes, set linkage to private
838
857
// as public symbols make into the final binary even when zombies?
839
- fn->setLinkage (onlyReferencedByDebugInfo ? SILLinkage::Private : linkage);
858
+ fn->setLinkage (forDebugScope ? SILLinkage::Private : linkage);
840
859
fn->setTransparent (IsTransparent_t (isTransparent == 1 ));
841
860
fn->setSerializedKind (SerializedKind_t (serializedKind));
842
861
fn->setThunk (IsThunk_t (isThunk));
@@ -873,10 +892,9 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
873
892
for (auto ID : SemanticsIDs) {
874
893
fn->addSemanticsAttr (MF->getIdentifierText (ID));
875
894
}
876
- if (onlyReferencedByDebugInfo) {
895
+ if (forDebugScope)
877
896
SILMod.eraseFunction (fn);
878
- }
879
- if (Callback && !onlyReferencedByDebugInfo)
897
+ if (Callback && !forDebugScope)
880
898
Callback->didDeserialize (MF->getAssociatedModule (), fn);
881
899
}
882
900
@@ -1013,7 +1031,7 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
1013
1031
// Remember this in our cache in case it's a recursive function.
1014
1032
// Increase the reference count to keep it alive.
1015
1033
bool isFullyDeserialized =
1016
- (isEmptyFunction || !declarationOnly) && ! onlyReferencedByDebugInfo;
1034
+ (isEmptyFunction || !declarationOnly || onlyReferencedByDebugInfo) ;
1017
1035
if (cacheEntry.isDeserialized ()) {
1018
1036
assert (fn == cacheEntry.get () && " changing SIL function during deserialization!" );
1019
1037
} else {
0 commit comments