@@ -67,10 +67,9 @@ TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
67
67
desc.getParentModule(), desc.getOptions(),
68
68
symbolCallback) {}
69
69
70
- void TBDGenVisitor::addSymbolInternal (StringRef name,
71
- llvm::MachO::SymbolKind kind,
72
- bool isLinkerDirective) {
73
- if (!isLinkerDirective && Opts.LinkerDirectivesOnly )
70
+ void TBDGenVisitor::addSymbolInternal (StringRef name, SymbolKind kind,
71
+ SymbolSource source) {
72
+ if (!source.isLinkerDirective () && Opts.LinkerDirectivesOnly )
74
73
return ;
75
74
76
75
#ifndef NDEBUG
@@ -81,7 +80,7 @@ void TBDGenVisitor::addSymbolInternal(StringRef name,
81
80
}
82
81
}
83
82
#endif
84
- SymbolCallback (name, kind);
83
+ SymbolCallback (name, kind, source );
85
84
}
86
85
87
86
static std::vector<OriginallyDefinedInAttr::ActiveVersion>
@@ -337,8 +336,8 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
337
336
OS << IntroVer->getMajor () << " ." << getMinor (IntroVer->getMinor ()) << " $" ;
338
337
OS << Ver.Version .getMajor () << " ." << getMinor (Ver.Version .getMinor ()) << " $" ;
339
338
OS << name << " $" ;
340
- addSymbolInternal (OS.str (), llvm::MachO:: SymbolKind::GlobalSymbol,
341
- /* LinkerDirective */ true );
339
+ addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
340
+ SymbolSource::forLinkerDirective () );
342
341
}
343
342
}
344
343
@@ -383,18 +382,19 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(StringRef name,
383
382
llvm::SmallString<64 > Buffer;
384
383
llvm::raw_svector_ostream OS (Buffer);
385
384
OS << " $ld$hide$os" << CurMaj << " ." << CurMin << " $" << name;
386
- addSymbolInternal (OS.str (), llvm::MachO:: SymbolKind::GlobalSymbol,
387
- /* LinkerDirective */ true );
385
+ addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
386
+ SymbolSource::forLinkerDirective () );
388
387
}
389
388
}
390
389
}
391
390
392
- void TBDGenVisitor::addSymbol (StringRef name, SymbolKind kind) {
391
+ void TBDGenVisitor::addSymbol (StringRef name, SymbolSource source,
392
+ SymbolKind kind) {
393
393
// The linker expects to see mangled symbol names in TBD files, so make sure
394
394
// to mangle before inserting the symbol.
395
395
SmallString<32 > mangled;
396
396
llvm::Mangler::getNameWithPrefix (mangled, name, DataLayout);
397
- addSymbolInternal (mangled, kind);
397
+ addSymbolInternal (mangled, kind, source );
398
398
if (previousInstallNameMap) {
399
399
addLinkerDirectiveSymbolsLdPrevious (mangled, kind);
400
400
} else {
@@ -407,7 +407,7 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef) {
407
407
declRef.getLinkage (ForDefinition),
408
408
declRef.getSubclassScope ());
409
409
if (linkage == SILLinkage::Public)
410
- addSymbol (declRef.mangle ());
410
+ addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef) );
411
411
}
412
412
413
413
void TBDGenVisitor::addSymbol (LinkEntity entity) {
@@ -419,7 +419,7 @@ void TBDGenVisitor::addSymbol(LinkEntity entity) {
419
419
linkage.getVisibility () != llvm::GlobalValue::HiddenVisibility;
420
420
421
421
if (externallyVisible)
422
- addSymbol (linkage.getName ());
422
+ addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity) );
423
423
}
424
424
425
425
void TBDGenVisitor::addDispatchThunk (SILDeclRef declRef) {
@@ -490,8 +490,10 @@ void TBDGenVisitor::addConformances(const IterableDeclContext *IDC) {
490
490
(isa<SelfProtocolConformance>(rootConformance) ||
491
491
fixmeWitnessHasLinkageThatNeedsToBePublic (witnessRef))) {
492
492
Mangle::ASTMangler Mangler;
493
- addSymbol (
494
- Mangler.mangleWitnessThunk (rootConformance, requirementDecl));
493
+
494
+ // FIXME: We should have a SILDeclRef SymbolSource for this.
495
+ addSymbol (Mangler.mangleWitnessThunk (rootConformance, requirementDecl),
496
+ SymbolSource::forUnknown ());
495
497
}
496
498
};
497
499
@@ -542,7 +544,7 @@ void TBDGenVisitor::addAutoDiffLinearMapFunction(AbstractFunctionDecl *original,
542
544
original->getGenericSignature (), config.derivativeGenericSignature )};
543
545
std::string linearMapName =
544
546
mangler.mangleAutoDiffLinearMapHelper (declRef.mangle (), kind, silConfig);
545
- addSymbol (linearMapName);
547
+ addSymbol (linearMapName, SymbolSource::forSILDeclRef (declRef) );
546
548
}
547
549
548
550
void TBDGenVisitor::addAutoDiffDerivativeFunction (
@@ -587,7 +589,7 @@ void TBDGenVisitor::addDifferentiabilityWitness(
587
589
588
590
Mangle::ASTMangler mangler;
589
591
auto mangledName = mangler.mangleSILDifferentiabilityWitnessKey (key);
590
- addSymbol (mangledName);
592
+ addSymbol (mangledName, SymbolSource::forSILDeclRef (declRef) );
591
593
}
592
594
593
595
void TBDGenVisitor::addDerivativeConfiguration (AbstractFunctionDecl *original,
@@ -771,8 +773,9 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
771
773
isGlobalOrStaticVar (VD)) {
772
774
if (getDeclLinkage (VD) == FormalLinkage::PublicUnique) {
773
775
// The actual variable has a symbol.
776
+ // FIXME: We ought to have a symbol source for this.
774
777
Mangle::ASTMangler mangler;
775
- addSymbol (mangler.mangleEntity (VD));
778
+ addSymbol (mangler.mangleEntity (VD), SymbolSource::forUnknown () );
776
779
}
777
780
778
781
if (VD->isLazilyInitializedGlobal ())
@@ -835,8 +838,10 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
835
838
addSymbol (LinkEntity::forSwiftMetaclassStub (CD));
836
839
837
840
if (addObjCClass) {
841
+ // FIXME: We ought to have a symbol source for this.
838
842
SmallString<128 > buffer;
839
- addSymbol (CD->getObjCRuntimeName (buffer), SymbolKind::ObjectiveCClass);
843
+ addSymbol (CD->getObjCRuntimeName (buffer), SymbolSource::forUnknown (),
844
+ SymbolKind::ObjectiveCClass);
840
845
}
841
846
}
842
847
@@ -1048,8 +1053,10 @@ void TBDGenVisitor::visitEnumElementDecl(EnumElementDecl *EED) {
1048
1053
1049
1054
void TBDGenVisitor::addFirstFileSymbols () {
1050
1055
if (!Opts.ModuleLinkName .empty ()) {
1056
+ // FIXME: We ought to have a symbol source for this.
1051
1057
SmallString<32 > buf;
1052
- addSymbol (irgen::encodeForceLoadSymbolName (buf, Opts.ModuleLinkName ));
1058
+ addSymbol (irgen::encodeForceLoadSymbolName (buf, Opts.ModuleLinkName ),
1059
+ SymbolSource::forUnknown ());
1053
1060
}
1054
1061
}
1055
1062
@@ -1196,7 +1203,7 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
1196
1203
}
1197
1204
1198
1205
llvm::MachO::TargetList targets{target};
1199
- auto addSymbol = [&](StringRef symbol, SymbolKind kind) {
1206
+ auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source ) {
1200
1207
file.addSymbol (kind, symbol, targets);
1201
1208
};
1202
1209
@@ -1209,7 +1216,7 @@ std::vector<std::string>
1209
1216
PublicSymbolsRequest::evaluate (Evaluator &evaluator,
1210
1217
TBDGenDescriptor desc) const {
1211
1218
std::vector<std::string> symbols;
1212
- auto addSymbol = [&](StringRef symbol, SymbolKind kind) {
1219
+ auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source ) {
1213
1220
if (kind == SymbolKind::GlobalSymbol)
1214
1221
symbols.push_back (symbol.str ());
1215
1222
};
@@ -1231,3 +1238,24 @@ void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
1231
1238
llvm::cantFail (llvm::MachO::TextAPIWriter::writeToStream (os, file),
1232
1239
" YAML writing should be error-free" );
1233
1240
}
1241
+
1242
+ SymbolSourceMap SymbolSourceMapRequest::evaluate (Evaluator &evaluator,
1243
+ TBDGenDescriptor desc) const {
1244
+ using Map = SymbolSourceMap::Storage;
1245
+ Map symbolSources;
1246
+
1247
+ auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source) {
1248
+ symbolSources.insert ({symbol, source});
1249
+ };
1250
+
1251
+ TBDGenVisitor visitor (desc, addSymbol);
1252
+ visitor.visit (desc);
1253
+
1254
+ // FIXME: Once the evaluator supports returning a reference to a cached value
1255
+ // in storage, this won't be necessary.
1256
+ auto &ctx = desc.getParentModule ()->getASTContext ();
1257
+ auto *memory = ctx.Allocate <Map>();
1258
+ *memory = std::move (symbolSources);
1259
+ ctx.addCleanup ([memory](){ memory->~Map (); });
1260
+ return SymbolSourceMap (memory);
1261
+ }
0 commit comments