@@ -499,29 +499,9 @@ 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
- // / Check if a given SIL linkage matches the required linkage.
511
- // / If the required linkage is Private, then anything matches it.
512
- static bool isMatchingLinkage (SILLinkage ActualLinkage,
513
- Optional<SILLinkage> Linkage) {
514
- if (!Linkage)
515
- return true ;
516
- return ActualLinkage == Linkage;
517
- }
518
-
519
- SILFunction *SILModule::findFunction (StringRef Name,
520
- Optional<SILLinkage> Linkage) {
521
- assert (Linkage);
522
- auto RequiredLinkage = *Linkage;
523
- assert ((RequiredLinkage == SILLinkage::Public ||
524
- RequiredLinkage == SILLinkage::PublicExternal) &&
502
+ SILFunction *SILModule::hasFunction (StringRef Name, SILLinkage Linkage) {
503
+ assert ((Linkage == SILLinkage::Public ||
504
+ Linkage == SILLinkage::PublicExternal) &&
525
505
" Only a lookup of public functions is supported currently" );
526
506
527
507
SILFunction *F = nullptr ;
@@ -532,10 +512,10 @@ SILFunction *SILModule::findFunction(StringRef Name,
532
512
533
513
// Nothing to do if the current module has a required function
534
514
// with a proper linkage already.
535
- if (CurF && isMatchingLinkage ( CurF->getLinkage (), Linkage) ) {
515
+ if (CurF && CurF->getLinkage () == Linkage) {
536
516
F = CurF;
537
517
} else {
538
- assert ((!CurF || CurF->getLinkage () != RequiredLinkage ) &&
518
+ assert ((!CurF || CurF->getLinkage () != Linkage ) &&
539
519
" hasFunction should be only called for functions that are not "
540
520
" contained in the SILModule yet or do not have a required linkage" );
541
521
}
@@ -548,7 +528,7 @@ SILFunction *SILModule::findFunction(StringRef Name,
548
528
// name is present in the current module.
549
529
// This is done to reduce the amount of IO from the
550
530
// swift module file.
551
- if (!Visitor.hasFunction (Name, RequiredLinkage ))
531
+ if (!Visitor.hasFunction (Name, Linkage ))
552
532
return nullptr ;
553
533
// The function in the current module will be changed.
554
534
F = CurF;
@@ -558,31 +538,27 @@ SILFunction *SILModule::findFunction(StringRef Name,
558
538
// or if it is known to exist, perform a lookup.
559
539
if (!F) {
560
540
// Try to load the function from other modules.
561
- F = Visitor.lookupFunction (Name, RequiredLinkage );
541
+ F = Visitor.lookupFunction (Name, Linkage );
562
542
// Bail if nothing was found and we are not sure if
563
543
// this function exists elsewhere.
564
544
if (!F)
565
545
return nullptr ;
566
546
assert (F && " SILFunction should be present in one of the modules" );
567
- assert (isMatchingLinkage (F->getLinkage (), Linkage) &&
568
- " SILFunction has a wrong linkage" );
547
+ assert (F->getLinkage () == Linkage && " SILFunction has a wrong linkage" );
569
548
}
570
549
}
571
550
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,
551
+ // If a function exists already and it is a non-optimizing
552
+ // compilation, simply convert it into an external declaration,
575
553
// 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
554
if (F->isDefinition () &&
579
555
F->getModule ().getOptions ().Optimization <
580
556
SILOptions::SILOptMode::Optimize) {
581
557
F->convertToDeclaration ();
582
558
}
583
559
if (F->isExternalDeclaration ())
584
560
F->setFragile (IsFragile_t::IsNotFragile);
585
- F->setLinkage (RequiredLinkage );
561
+ F->setLinkage (Linkage );
586
562
return F;
587
563
}
588
564
0 commit comments