Skip to content

Commit b5f9e05

Browse files
committed
[TBDGen] Make enumeratePublicSymbols more functional
Instead of taking an out parameter, have it return the set directly. Also coalesce the two overloads into a single overload that takes a `TBDGenDescriptor`.
1 parent 89f0f5d commit b5f9e05

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

include/swift/TBDGen/TBDGen.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/ADT/Hashing.h"
1616
#include "llvm/ADT/StringSet.h"
17+
#include "swift/AST/TBDGenRequests.h"
1718
#include "swift/Basic/Version.h"
1819
#include <vector>
1920

@@ -88,10 +89,7 @@ struct TBDGenOptions {
8889
}
8990
};
9091

91-
void enumeratePublicSymbols(FileUnit *module, llvm::StringSet<> &symbols,
92-
const TBDGenOptions &opts);
93-
void enumeratePublicSymbols(ModuleDecl *module, llvm::StringSet<> &symbols,
94-
const TBDGenOptions &opts);
92+
llvm::StringSet<> getPublicSymbols(TBDGenDescriptor desc);
9593

9694
void writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
9795
const TBDGenOptions &opts);

lib/FrontendTool/FrontendTool.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,9 @@ static bool writeLdAddCFileIfNeeded(CompilerInstance &Instance) {
10541054
}
10551055
auto tbdOpts = Invocation.getTBDGenOptions();
10561056
tbdOpts.LinkerDirectivesOnly = true;
1057-
llvm::StringSet<> ldSymbols;
10581057
auto *module = Instance.getMainModule();
1059-
enumeratePublicSymbols(module, ldSymbols, tbdOpts);
1058+
auto ldSymbols =
1059+
getPublicSymbols(TBDGenDescriptor::forModule(module, tbdOpts));
10601060
std::error_code EC;
10611061
llvm::raw_fd_ostream OS(Path, EC, llvm::sys::fs::F_None);
10621062
if (EC) {
@@ -1663,15 +1663,17 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
16631663
OutputFilename, Instance.getStatsReporter());
16641664
}
16651665

1666-
static void collectLinkerDirectives(const CompilerInvocation &Invocation,
1667-
ModuleOrSourceFile MSF,
1668-
llvm::StringSet<> &Symbols) {
1666+
static llvm::StringSet<>
1667+
collectLinkerDirectives(const CompilerInvocation &Invocation,
1668+
ModuleOrSourceFile MSF) {
16691669
auto tbdOpts = Invocation.getTBDGenOptions();
16701670
tbdOpts.LinkerDirectivesOnly = true;
1671-
if (MSF.is<SourceFile*>())
1672-
enumeratePublicSymbols(MSF.get<SourceFile*>(), Symbols, tbdOpts);
1673-
else
1674-
enumeratePublicSymbols(MSF.get<ModuleDecl*>(), Symbols, tbdOpts);
1671+
if (auto *SF = MSF.dyn_cast<SourceFile *>()) {
1672+
return getPublicSymbols(TBDGenDescriptor::forFile(SF, tbdOpts));
1673+
} else {
1674+
return getPublicSymbols(
1675+
TBDGenDescriptor::forModule(MSF.get<ModuleDecl *>(), tbdOpts));
1676+
}
16751677
}
16761678

16771679
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,

lib/FrontendTool/TBD.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ bool swift::validateTBD(ModuleDecl *M,
139139
const llvm::Module &IRModule,
140140
const TBDGenOptions &opts,
141141
bool diagnoseExtraSymbolsInTBD) {
142-
llvm::StringSet<> symbols;
143-
enumeratePublicSymbols(M, symbols, opts);
144-
142+
auto symbols = getPublicSymbols(TBDGenDescriptor::forModule(M, opts));
145143
return validateSymbolSet(M->getASTContext().Diags, symbols, IRModule,
146144
diagnoseExtraSymbolsInTBD);
147145
}
@@ -150,9 +148,7 @@ bool swift::validateTBD(FileUnit *file,
150148
const llvm::Module &IRModule,
151149
const TBDGenOptions &opts,
152150
bool diagnoseExtraSymbolsInTBD) {
153-
llvm::StringSet<> symbols;
154-
enumeratePublicSymbols(file, symbols, opts);
155-
151+
auto symbols = getPublicSymbols(TBDGenDescriptor::forFile(file, opts));
156152
return validateSymbolSet(file->getParentModule()->getASTContext().Diags,
157153
symbols, IRModule,
158154
diagnoseExtraSymbolsInTBD);

lib/TBDGen/TBDGen.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,19 +1190,9 @@ GenerateTBDRequest::evaluate(Evaluator &evaluator,
11901190
return std::make_pair(std::move(file), std::move(symbols));
11911191
}
11921192

1193-
void swift::enumeratePublicSymbols(FileUnit *file, StringSet &symbols,
1194-
const TBDGenOptions &opts) {
1195-
assert(symbols.empty() && "Additive symbol enumeration not supported");
1196-
auto &evaluator = file->getASTContext().evaluator;
1197-
auto desc = TBDGenDescriptor::forFile(file, opts);
1198-
symbols = llvm::cantFail(evaluator(GenerateTBDRequest{desc})).second;
1199-
}
1200-
void swift::enumeratePublicSymbols(ModuleDecl *M, StringSet &symbols,
1201-
const TBDGenOptions &opts) {
1202-
assert(symbols.empty() && "Additive symbol enumeration not supported");
1203-
auto &evaluator = M->getASTContext().evaluator;
1204-
auto desc = TBDGenDescriptor::forModule(M, opts);
1205-
symbols = llvm::cantFail(evaluator(GenerateTBDRequest{desc})).second;
1193+
StringSet swift::getPublicSymbols(TBDGenDescriptor desc) {
1194+
auto &evaluator = desc.getParentModule()->getASTContext().evaluator;
1195+
return llvm::cantFail(evaluator(GenerateTBDRequest{desc})).second;
12061196
}
12071197
void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
12081198
const TBDGenOptions &opts) {

0 commit comments

Comments
 (0)