Skip to content

Commit c8f8afd

Browse files
author
Harlan
authored
Merge pull request #18736 from harlanhaskins/magic-eraser
[TBDGen] Remove TBD options from FrontendOptions
2 parents 3403bb6 + 75e2195 commit c8f8afd

18 files changed

+132
-76
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "swift/Sema/SourceLoader.h"
3939
#include "swift/Serialization/Validation.h"
4040
#include "swift/Subsystems.h"
41+
#include "swift/TBDGen/TBDGen.h"
4142
#include "llvm/ADT/IntrusiveRefCntPtr.h"
4243
#include "llvm/ADT/SetVector.h"
4344
#include "llvm/Option/ArgList.h"
@@ -70,6 +71,7 @@ class CompilerInvocation {
7071
MigratorOptions MigratorOpts;
7172
SILOptions SILOpts;
7273
IRGenOptions IRGenOpts;
74+
TBDGenOptions TBDGenOpts;
7375
/// The \c SyntaxParsingCache to use when parsing the main file of this
7476
/// invocation
7577
SyntaxParsingCache *MainFileSyntaxParsingCache = nullptr;
@@ -197,6 +199,9 @@ class CompilerInvocation {
197199
FrontendOptions &getFrontendOptions() { return FrontendOpts; }
198200
const FrontendOptions &getFrontendOptions() const { return FrontendOpts; }
199201

202+
TBDGenOptions &getTBDGenOptions() { return TBDGenOpts; }
203+
const TBDGenOptions &getTBDGenOptions() const { return TBDGenOpts; }
204+
200205
ClangImporterOptions &getClangImporterOptions() { return ClangImporterOpts; }
201206
const ClangImporterOptions &getClangImporterOptions() const {
202207
return ClangImporterOpts;

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,6 @@ class FrontendOptions {
260260
/// Compare the symbols in the IR against the TBD file we would generate.
261261
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::Default;
262262

263-
/// The install_name to use in the TBD file.
264-
std::string TBDInstallName;
265-
266-
// The current project version to use in the generated TBD file. Defaults
267-
// to 1, which matches the default if the DYLIB_CURRENT_VERSION build setting
268-
// is not set.
269-
version::Version TBDCurrentVersion = {1, 0, 0};
270-
271-
// The dylib compatibility-version to use in the generated TBD file. Defaults
272-
// to 1, which matches the default if the DYLIB_COMPATIBILITY_VERSION build
273-
// setting is not set.
274-
version::Version TBDCompatibilityVersion = {1, 0, 0};
275-
276263
/// An enum with different modes for automatically crashing at defined times.
277264
enum class DebugCrashMode {
278265
None, ///< Don't automatically crash.

include/swift/TBDGen/TBDGen.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,39 @@ namespace swift {
2424
class FileUnit;
2525
class ModuleDecl;
2626

27-
/// \brief The current ABI version of Swift, as tapi labels it.
27+
/// The current ABI version of Swift, as tapi labels it.
2828
const uint8_t TAPI_SWIFT_ABI_VERSION = 5;
2929

30-
/// \brief Options for controlling the exact set of symbols included in the TBD
30+
/// Options for controlling the exact set of symbols included in the TBD
3131
/// output.
3232
struct TBDGenOptions {
33-
/// \brief Whether this compilation has multiple IRGen instances.
33+
/// Whether this compilation has multiple IRGen instances.
3434
bool HasMultipleIGMs;
35-
/// \brief The install-name used for the compilation.
36-
llvm::StringRef InstallName;
37-
/// \brief The module link name (for force loading).
38-
llvm::StringRef ModuleLinkName;
39-
/// \brief The current project version.
40-
version::Version CurrentVersion;
41-
/// \brief The dylib compatibility version.
42-
version::Version CompatibilityVersion;
35+
36+
/// The install_name to use in the TBD file.
37+
std::string InstallName;
38+
39+
/// The module link name (for force loading).
40+
std::string ModuleLinkName;
41+
42+
/// The current project version to use in the generated TBD file. Defaults
43+
/// to 1, which matches the default if the DYLIB_CURRENT_VERSION build setting
44+
/// is not set.
45+
version::Version CurrentVersion = {1, 0, 0};
46+
47+
/// The dylib compatibility-version to use in the generated TBD file. Defaults
48+
/// to 1, which matches the default if the DYLIB_COMPATIBILITY_VERSION build
49+
/// setting is not set.
50+
version::Version CompatibilityVersion = {1, 0, 0};
4351
};
4452

4553
void enumeratePublicSymbols(FileUnit *module, llvm::StringSet<> &symbols,
46-
TBDGenOptions &opts);
54+
const TBDGenOptions &opts);
4755
void enumeratePublicSymbols(ModuleDecl *module, llvm::StringSet<> &symbols,
48-
TBDGenOptions &opts);
56+
const TBDGenOptions &opts);
4957

50-
void writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os, TBDGenOptions &opts);
58+
void writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
59+
const TBDGenOptions &opts);
5160

5261
} // end namespace swift
5362

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,6 @@ void ArgsToFrontendOptionsConverter::computeTBDOptions() {
214214
A->getOption().getPrefixedName(), value);
215215
}
216216
}
217-
if (const Arg *A = Args.getLastArg(OPT_tbd_install_name)) {
218-
Opts.TBDInstallName = A->getValue();
219-
}
220-
if (const Arg *A = Args.getLastArg(OPT_tbd_compatibility_version)) {
221-
if (auto vers = version::Version::parseVersionString(
222-
A->getValue(), SourceLoc(), &Diags)) {
223-
Opts.TBDCompatibilityVersion = *vers;
224-
}
225-
}
226-
if (const Arg *A = Args.getLastArg(OPT_tbd_current_version)) {
227-
if (auto vers = version::Version::parseVersionString(
228-
A->getValue(), SourceLoc(), &Diags)) {
229-
Opts.TBDCurrentVersion = *vers;
230-
}
231-
}
232217
}
233218

234219
void ArgsToFrontendOptionsConverter::setUnsignedIntegerArgument(

lib/Frontend/CompilerInvocation.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,36 @@ void CompilerInvocation::buildDebugFlags(std::string &Output,
769769
}
770770
}
771771

772+
static bool ParseTBDGenArgs(TBDGenOptions &Opts, ArgList &Args,
773+
DiagnosticEngine &Diags,
774+
CompilerInvocation &Invocation) {
775+
using namespace options;
776+
777+
Opts.HasMultipleIGMs = Invocation.getSILOptions().hasMultipleIGMs();
778+
779+
if (const Arg *A = Args.getLastArg(OPT_module_link_name)) {
780+
Opts.ModuleLinkName = A->getValue();
781+
}
782+
783+
if (const Arg *A = Args.getLastArg(OPT_tbd_install_name)) {
784+
Opts.InstallName = A->getValue();
785+
}
786+
787+
if (const Arg *A = Args.getLastArg(OPT_tbd_compatibility_version)) {
788+
if (auto vers = version::Version::parseVersionString(
789+
A->getValue(), SourceLoc(), &Diags)) {
790+
Opts.CompatibilityVersion = *vers;
791+
}
792+
}
793+
if (const Arg *A = Args.getLastArg(OPT_tbd_current_version)) {
794+
if (auto vers = version::Version::parseVersionString(
795+
A->getValue(), SourceLoc(), &Diags)) {
796+
Opts.CurrentVersion = *vers;
797+
}
798+
}
799+
return false;
800+
}
801+
772802
static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
773803
DiagnosticEngine &Diags,
774804
const FrontendOptions &FrontendOpts,
@@ -1146,6 +1176,10 @@ bool CompilerInvocation::parseArgs(
11461176
return true;
11471177
}
11481178

1179+
if (ParseTBDGenArgs(TBDGenOpts, ParsedArgs, Diags, *this)) {
1180+
return true;
1181+
}
1182+
11491183
if (ParseDiagnosticArgs(DiagnosticOpts, ParsedArgs, Diags)) {
11501184
return true;
11511185
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
782782
static bool writeTBDIfNeeded(CompilerInvocation &Invocation,
783783
CompilerInstance &Instance) {
784784
const auto &frontendOpts = Invocation.getFrontendOptions();
785+
const auto &tbdOpts = Invocation.getTBDGenOptions();
785786
if (!frontendOpts.InputsAndOutputs.hasTBDPath())
786787
return false;
787788

@@ -793,18 +794,7 @@ static bool writeTBDIfNeeded(CompilerInvocation &Invocation,
793794

794795
const std::string &TBDPath = Invocation.getTBDPathForWholeModule();
795796

796-
auto installName = frontendOpts.TBDInstallName.empty()
797-
? "lib" + Invocation.getModuleName().str() + ".dylib"
798-
: frontendOpts.TBDInstallName;
799-
800-
TBDGenOptions opts;
801-
opts.InstallName = installName;
802-
opts.HasMultipleIGMs = Invocation.getSILOptions().hasMultipleIGMs();
803-
opts.ModuleLinkName = frontendOpts.ModuleLinkName;
804-
opts.CurrentVersion = frontendOpts.TBDCurrentVersion;
805-
opts.CompatibilityVersion = frontendOpts.TBDCompatibilityVersion;
806-
807-
return writeTBD(Instance.getMainModule(), TBDPath, opts);
797+
return writeTBD(Instance.getMainModule(), TBDPath, tbdOpts);
808798
}
809799

810800
static std::deque<PostSILGenInputs>
@@ -989,6 +979,9 @@ static bool performCompile(CompilerInstance &Instance,
989979
return true;
990980
}
991981

982+
if (writeTBDIfNeeded(Invocation, Instance))
983+
return true;
984+
992985
// FIXME: This is still a lousy approximation of whether the module file will
993986
// be externally consumed.
994987
bool moduleIsPublic =
@@ -1011,9 +1004,6 @@ static bool performCompile(CompilerInstance &Instance,
10111004
return hadPrintAsObjCError || hadEmitIndexDataError || Context.hadError();
10121005
}
10131006

1014-
if (writeTBDIfNeeded(Invocation, Instance))
1015-
return true;
1016-
10171007
assert(FrontendOptions::doesActionGenerateSIL(Action) &&
10181008
"All actions not requiring SILGen must have been handled!");
10191009

@@ -1213,14 +1203,13 @@ static bool validateTBDIfNeeded(CompilerInvocation &Invocation,
12131203
case FrontendOptions::TBDValidationMode::MissingFromTBD:
12141204
break;
12151205
}
1216-
TBDGenOptions opts;
1217-
opts.HasMultipleIGMs = Invocation.getSILOptions().hasMultipleIGMs();
1218-
opts.ModuleLinkName = frontendOpts.ModuleLinkName;
12191206

12201207
const bool allSymbols = mode == FrontendOptions::TBDValidationMode::All;
12211208
return MSF.is<SourceFile *>()
1222-
? validateTBD(MSF.get<SourceFile *>(), IRModule, opts, allSymbols)
1223-
: validateTBD(MSF.get<ModuleDecl *>(), IRModule, opts, allSymbols);
1209+
? validateTBD(MSF.get<SourceFile *>(), IRModule,
1210+
Invocation.getTBDGenOptions(), allSymbols)
1211+
: validateTBD(MSF.get<ModuleDecl *>(), IRModule,
1212+
Invocation.getTBDGenOptions(), allSymbols);
12241213
}
12251214

12261215
static bool generateCode(CompilerInvocation &Invocation,

lib/FrontendTool/TBD.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static std::vector<StringRef> sortSymbols(llvm::StringSet<> &symbols) {
3939
}
4040

4141
bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
42-
TBDGenOptions &Opts) {
42+
const TBDGenOptions &Opts) {
4343
std::error_code EC;
4444
llvm::raw_fd_ostream OS(OutputFilename, EC, llvm::sys::fs::F_None);
4545
if (EC) {
@@ -124,7 +124,8 @@ static bool validateSymbolSet(DiagnosticEngine &diags,
124124
}
125125

126126
bool swift::validateTBD(ModuleDecl *M, llvm::Module &IRModule,
127-
TBDGenOptions &opts, bool diagnoseExtraSymbolsInTBD) {
127+
const TBDGenOptions &opts,
128+
bool diagnoseExtraSymbolsInTBD) {
128129
llvm::StringSet<> symbols;
129130
enumeratePublicSymbols(M, symbols, opts);
130131

@@ -133,10 +134,12 @@ bool swift::validateTBD(ModuleDecl *M, llvm::Module &IRModule,
133134
}
134135

135136
bool swift::validateTBD(FileUnit *file, llvm::Module &IRModule,
136-
TBDGenOptions &opts, bool diagnoseExtraSymbolsInTBD) {
137+
const TBDGenOptions &opts,
138+
bool diagnoseExtraSymbolsInTBD) {
137139
llvm::StringSet<> symbols;
138140
enumeratePublicSymbols(file, symbols, opts);
139141

140142
return validateSymbolSet(file->getParentModule()->getASTContext().Diags,
141-
symbols, IRModule, diagnoseExtraSymbolsInTBD);
143+
symbols, IRModule,
144+
diagnoseExtraSymbolsInTBD);
142145
}

lib/FrontendTool/TBD.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ class FileUnit;
2525
class FrontendOptions;
2626
struct TBDGenOptions;
2727

28-
bool writeTBD(ModuleDecl *M, StringRef OutputFilename, TBDGenOptions &Opts);
28+
bool writeTBD(ModuleDecl *M, StringRef OutputFilename,
29+
const TBDGenOptions &Opts);
2930
bool inputFileKindCanHaveTBDValidated(InputFileKind kind);
30-
bool validateTBD(ModuleDecl *M, llvm::Module &IRModule, TBDGenOptions &opts,
31+
bool validateTBD(ModuleDecl *M, llvm::Module &IRModule,
32+
const TBDGenOptions &opts,
3133
bool diagnoseExtraSymbolsInTBD);
32-
bool validateTBD(FileUnit *M, llvm::Module &IRModule, TBDGenOptions &opts,
34+
bool validateTBD(FileUnit *M, llvm::Module &IRModule,
35+
const TBDGenOptions &opts,
3336
bool diagnoseExtraSymbolsInTBD);
3437
}
3538

lib/TBDGen/TBDGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void TBDGenVisitor::addFirstFileSymbols() {
414414
/// Converts a version tuple into a packed version, ignoring components beyond
415415
/// major, minor, and subminor.
416416
static tapi::internal::PackedVersion
417-
convertToPacked(version::Version &version) {
417+
convertToPacked(const version::Version &version) {
418418
// FIXME: Warn if version is greater than 3 components?
419419
unsigned major = 0, minor = 0, subminor = 0;
420420
if (version.size() > 0) major = version[0];
@@ -426,7 +426,7 @@ convertToPacked(version::Version &version) {
426426
static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
427427
StringSet *symbols,
428428
llvm::raw_ostream *os,
429-
TBDGenOptions &opts) {
429+
const TBDGenOptions &opts) {
430430
auto isWholeModule = singleFile == nullptr;
431431
const auto &target = M->getASTContext().LangOpts.Target;
432432
UniversalLinkageInfo linkInfo(target, opts.HasMultipleIGMs, isWholeModule);
@@ -481,15 +481,15 @@ static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
481481
}
482482

483483
void swift::enumeratePublicSymbols(FileUnit *file, StringSet &symbols,
484-
TBDGenOptions &opts) {
484+
const TBDGenOptions &opts) {
485485
enumeratePublicSymbolsAndWrite(file->getParentModule(), file, &symbols,
486486
nullptr, opts);
487487
}
488488
void swift::enumeratePublicSymbols(ModuleDecl *M, StringSet &symbols,
489-
TBDGenOptions &opts) {
489+
const TBDGenOptions &opts) {
490490
enumeratePublicSymbolsAndWrite(M, nullptr, &symbols, nullptr, opts);
491491
}
492492
void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
493-
TBDGenOptions &opts) {
493+
const TBDGenOptions &opts) {
494494
enumeratePublicSymbolsAndWrite(M, nullptr, nullptr, &os, opts);
495495
}

lib/TBDGen/TBDGenVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
4848

4949
const UniversalLinkageInfo &UniversalLinkInfo;
5050
ModuleDecl *SwiftModule;
51-
TBDGenOptions &Opts;
51+
const TBDGenOptions &Opts;
5252

5353
private:
5454
bool FileHasEntryPoint = false;
@@ -68,7 +68,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
6868
TBDGenVisitor(tapi::internal::InterfaceFile &symbols,
6969
tapi::internal::ArchitectureSet archs, StringSet *stringSymbols,
7070
const UniversalLinkageInfo &universalLinkInfo,
71-
ModuleDecl *swiftModule, TBDGenOptions &opts)
71+
ModuleDecl *swiftModule, const TBDGenOptions &opts)
7272
: Symbols(symbols), Archs(archs), StringSymbols(stringSymbols),
7373
UniversalLinkInfo(universalLinkInfo), SwiftModule(swiftModule),
7474
Opts(opts) {}

test/TBD/class.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing -O
99
// RUN: %target-swift-frontend -enable-resilience -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -enable-testing -O
1010

11+
// RUN: %empty-directory(%t)
12+
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
13+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/emit-ir.tbd
14+
// RUN: diff -u %t/typecheck.tbd %t/emit-ir.tbd
15+
1116
open class OpenNothing {}
1217

1318
open class OpenInit {

test/TBD/enum.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing -O
2222
// RUN: %target-swift-frontend -enable-resilience -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=missing %s -swift-version 4 -enable-testing -O
2323

24+
// RUN: %empty-directory(%t)
25+
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
26+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/emit-ir.tbd
27+
// RUN: diff -u %t/typecheck.tbd %t/emit-ir.tbd
28+
29+
2430
public protocol P {}
2531

2632
public class C {

test/TBD/function.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -O
44
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -swift-version 4 %s -enable-testing -O
55

6+
// RUN: %empty-directory(%t)
7+
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
8+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/emit-ir.tbd
9+
// RUN: diff -u %t/typecheck.tbd %t/emit-ir.tbd
10+
611
public func publicNoArgs() {}
712
public func publicSomeArgs(_: Int, x: Int) {}
813
public func publicWithDefault(_: Int = 0) {}

test/TBD/global.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing -O
88
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all -enable-resilience -enable-testing %s -O
99

10+
// RUN: %empty-directory(%t)
11+
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
12+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/emit-ir.tbd
13+
// RUN: diff -u %t/typecheck.tbd %t/emit-ir.tbd
14+
1015
public let publicLet: Int = 0
1116
internal let internalLet: Int = 0
1217
private let privateLet: Int = 0

0 commit comments

Comments
 (0)