@@ -499,14 +499,6 @@ bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
499
499
return SILLinkerVisitor (*this , getSILLoader (), Mode).processFunction (Name);
500
500
}
501
501
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
-
510
502
// / Check if a given SIL linkage matches the required linkage.
511
503
// / If the required linkage is Private, then anything matches it.
512
504
static bool isMatchingLinkage (SILLinkage ActualLinkage,
@@ -516,15 +508,19 @@ static bool isMatchingLinkage(SILLinkage ActualLinkage,
516
508
return ActualLinkage == Linkage;
517
509
}
518
510
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
+
519
519
SILFunction *SILModule::findFunction (StringRef Name,
520
520
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" );
526
521
527
522
SILFunction *F = nullptr ;
523
+ SILLinkage RequiredLinkage = Linkage ? *Linkage : SILLinkage::Private;
528
524
529
525
// First, check if there is a function with a required name in the
530
526
// current module.
@@ -569,20 +565,27 @@ SILFunction *SILModule::findFunction(StringRef Name,
569
565
}
570
566
}
571
567
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,
568
+ // If a function exists already and it is a non-optimizing
569
+ // compilation, simply convert it into an external declaration,
575
570
// 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.
578
571
if (F->isDefinition () &&
579
572
F->getModule ().getOptions ().Optimization <
580
573
SILOptions::SILOptMode::Optimize) {
581
574
F->convertToDeclaration ();
582
575
}
583
- if (F->isExternalDeclaration ())
576
+ if (F->isExternalDeclaration ()) {
584
577
F->setFragile (IsFragile_t::IsNotFragile);
585
- F->setLinkage (RequiredLinkage);
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);
586
589
return F;
587
590
}
588
591
0 commit comments