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