@@ -406,8 +406,10 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef) {
406
406
auto linkage = effectiveLinkageForClassMember (
407
407
declRef.getLinkage (ForDefinition),
408
408
declRef.getSubclassScope ());
409
- if (linkage == SILLinkage::Public)
410
- addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef));
409
+ if (Opts.PublicSymbolsOnly && linkage != SILLinkage::Public)
410
+ return ;
411
+
412
+ addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef));
411
413
}
412
414
413
415
void TBDGenVisitor::addSymbol (LinkEntity entity) {
@@ -418,8 +420,10 @@ void TBDGenVisitor::addSymbol(LinkEntity entity) {
418
420
llvm::GlobalValue::isExternalLinkage (linkage.getLinkage ()) &&
419
421
linkage.getVisibility () != llvm::GlobalValue::HiddenVisibility;
420
422
421
- if (externallyVisible)
422
- addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity));
423
+ if (Opts.PublicSymbolsOnly && !externallyVisible)
424
+ return ;
425
+
426
+ addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity));
423
427
}
424
428
425
429
void TBDGenVisitor::addDispatchThunk (SILDeclRef declRef) {
@@ -486,15 +490,21 @@ void TBDGenVisitor::addConformances(const IterableDeclContext *IDC) {
486
490
auto addSymbolIfNecessary = [&](ValueDecl *requirementDecl,
487
491
ValueDecl *witnessDecl) {
488
492
auto witnessRef = SILDeclRef (witnessDecl);
489
- if (conformanceIsFixed &&
490
- (isa<SelfProtocolConformance>(rootConformance) ||
491
- fixmeWitnessHasLinkageThatNeedsToBePublic (witnessRef))) {
492
- Mangle::ASTMangler Mangler;
493
-
494
- // FIXME: We should have a SILDeclRef SymbolSource for this.
495
- addSymbol (Mangler. mangleWitnessThunk (rootConformance, requirementDecl),
496
- SymbolSource::forUnknown ());
493
+ if (Opts. PublicSymbolsOnly ) {
494
+ if (!conformanceIsFixed)
495
+ return ;
496
+
497
+ if (!isa<SelfProtocolConformance>(rootConformance) &&
498
+ ! fixmeWitnessHasLinkageThatNeedsToBePublic (witnessRef)) {
499
+ return ;
500
+ }
497
501
}
502
+
503
+ Mangle::ASTMangler Mangler;
504
+
505
+ // FIXME: We should have a SILDeclRef SymbolSource for this.
506
+ addSymbol (Mangler.mangleWitnessThunk (rootConformance, requirementDecl),
507
+ SymbolSource::forUnknown ());
498
508
};
499
509
500
510
rootConformance->forEachValueWitness ([&](ValueDecl *valueReq,
@@ -525,11 +535,11 @@ void TBDGenVisitor::addAutoDiffLinearMapFunction(AbstractFunctionDecl *original,
525
535
auto declRef =
526
536
SILDeclRef (original).asForeign (requiresForeignEntryPoint (original));
527
537
528
- if (!declRef.isSerialized ())
529
- return ;
530
- // Linear maps are public only when the original function is serialized.
531
- if (!declRef.isSerialized ())
538
+ // Linear maps are public only when the original function is serialized. So
539
+ // if we're only including public symbols and it's not serialized, bail.
540
+ if (Opts.PublicSymbolsOnly && !declRef.isSerialized ())
532
541
return ;
542
+
533
543
// Differential functions are emitted only when forward-mode is enabled.
534
544
if (kind == AutoDiffLinearMapKind::Differential &&
535
545
!ctx.LangOpts .EnableExperimentalForwardModeDifferentiation )
@@ -573,7 +583,7 @@ void TBDGenVisitor::addDifferentiabilityWitness(
573
583
auto originalLinkage = declRef.getLinkage (ForDefinition);
574
584
if (foreign)
575
585
originalLinkage = stripExternalFromLinkage (originalLinkage);
576
- if (originalLinkage != SILLinkage::Public)
586
+ if (Opts. PublicSymbolsOnly && originalLinkage != SILLinkage::Public)
577
587
return ;
578
588
579
589
auto *silParamIndices = autodiff::getLoweredParameterIndices (
@@ -631,7 +641,7 @@ static bool shouldUseAllocatorMangling(const AbstractFunctionDecl *afd) {
631
641
void TBDGenVisitor::visitDefaultArguments (ValueDecl *VD, ParameterList *PL) {
632
642
auto publicDefaultArgGenerators = SwiftModule->isTestingEnabled () ||
633
643
SwiftModule->arePrivateImportsEnabled ();
634
- if (!publicDefaultArgGenerators)
644
+ if (Opts. PublicSymbolsOnly && !publicDefaultArgGenerators)
635
645
return ;
636
646
637
647
// In Swift 3 (or under -enable-testing), default arguments (of public
@@ -771,7 +781,8 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
771
781
// statically/globally stored variables have some special handling.
772
782
if (VD->hasStorage () &&
773
783
isGlobalOrStaticVar (VD)) {
774
- if (getDeclLinkage (VD) == FormalLinkage::PublicUnique) {
784
+ if (!Opts.PublicSymbolsOnly ||
785
+ getDeclLinkage (VD) == FormalLinkage::PublicUnique) {
775
786
// The actual variable has a symbol.
776
787
// FIXME: We ought to have a symbol source for this.
777
788
Mangle::ASTMangler mangler;
@@ -814,7 +825,8 @@ void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) {
814
825
}
815
826
816
827
void TBDGenVisitor::visitClassDecl (ClassDecl *CD) {
817
- if (getDeclLinkage (CD) != FormalLinkage::PublicUnique)
828
+ if (Opts.PublicSymbolsOnly &&
829
+ getDeclLinkage (CD) != FormalLinkage::PublicUnique)
818
830
return ;
819
831
820
832
auto &ctxt = CD->getASTContext ();
0 commit comments