Skip to content

Commit a380855

Browse files
authored
Merge pull request #7401 from swiftix/wip-generics-inlining-flag-4
Fix a linking issue introduced by recent SILModule changes.
2 parents 6633214 + e744739 commit a380855

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

lib/SIL/SILModule.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
499499
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
500500
}
501501

502+
bool SILModule::hasFunction(StringRef Name) {
503+
if (lookUpFunction(Name))
504+
return true;
505+
SILLinkerVisitor Visitor(*this, getSILLoader(),
506+
SILModule::LinkingMode::LinkNormal);
507+
return Visitor.hasFunction(Name);
508+
}
509+
502510
/// Check if a given SIL linkage matches the required linkage.
503511
/// If the required linkage is Private, then anything matches it.
504512
static bool isMatchingLinkage(SILLinkage ActualLinkage,
@@ -508,19 +516,15 @@ static bool isMatchingLinkage(SILLinkage ActualLinkage,
508516
return ActualLinkage == Linkage;
509517
}
510518

511-
bool SILModule::hasFunction(StringRef Name) {
512-
if (lookUpFunction(Name))
513-
return true;
514-
SILLinkerVisitor Visitor(*this, getSILLoader(),
515-
SILModule::LinkingMode::LinkNormal);
516-
return Visitor.hasFunction(Name);
517-
}
518-
519519
SILFunction *SILModule::findFunction(StringRef Name,
520520
Optional<SILLinkage> Linkage) {
521+
assert(Linkage);
522+
auto RequiredLinkage = *Linkage;
523+
assert((RequiredLinkage == SILLinkage::Public ||
524+
RequiredLinkage == SILLinkage::PublicExternal) &&
525+
"Only a lookup of public functions is supported currently");
521526

522527
SILFunction *F = nullptr;
523-
SILLinkage RequiredLinkage = Linkage ? *Linkage : SILLinkage::Private;
524528

525529
// First, check if there is a function with a required name in the
526530
// current module.
@@ -565,27 +569,20 @@ SILFunction *SILModule::findFunction(StringRef Name,
565569
}
566570
}
567571

568-
// If a function exists already and it is a non-optimizing
569-
// compilation, simply convert it into an external declaration,
572+
// If an external public function representing a pre-specialization
573+
// exists already and it is a non-optimizing compilation,
574+
// simply convert it into an external declaration,
570575
// so that a compiled version from the shared library is used.
576+
// It is important to remove its body here, because it may
577+
// contain references to non-public functions.
571578
if (F->isDefinition() &&
572579
F->getModule().getOptions().Optimization <
573580
SILOptions::SILOptMode::Optimize) {
574581
F->convertToDeclaration();
575582
}
576-
if (F->isExternalDeclaration()) {
583+
if (F->isExternalDeclaration())
577584
F->setFragile(IsFragile_t::IsNotFragile);
578-
if (isAvailableExternally(F->getLinkage()) &&
579-
!hasPublicVisibility(F->getLinkage()) && !Linkage) {
580-
// We were just asked if a given function exists anywhere.
581-
// It is not going to be used by the current module.
582-
// Since external non-public function declarations should not
583-
// exist, strip the "external" part from the linkage.
584-
F->setLinkage(stripExternalFromLinkage(F->getLinkage()));
585-
}
586-
}
587-
if (Linkage)
588-
F->setLinkage(RequiredLinkage);
585+
F->setLinkage(RequiredLinkage);
589586
return F;
590587
}
591588

0 commit comments

Comments
 (0)