Skip to content

Commit 9020c13

Browse files
committed
[TBDGen] Use proper symbol source for main
Now that SILDeclRef can represent the main function, tweak TBDGen to refer to it.
1 parent de7e5ef commit 9020c13

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,29 @@ void TBDGenVisitor::addFirstFileSymbols() {
11521152
}
11531153
}
11541154

1155+
void TBDGenVisitor::addMainIfNecessary(FileUnit *file) {
1156+
// HACK: 'main' is a special symbol that's always emitted in SILGen if
1157+
// the file has an entry point. Since it doesn't show up in the
1158+
// module until SILGen, we need to explicitly add it here.
1159+
//
1160+
// Make sure to only add the main symbol for the module that we're emitting
1161+
// TBD for, and not for any statically linked libraries.
1162+
if (!file->hasEntryPoint() || file->getParentModule() != SwiftModule)
1163+
return;
1164+
1165+
auto entryPointSymbol =
1166+
SwiftModule->getASTContext().getEntryPointFunctionName();
1167+
1168+
if (auto *decl = file->getMainDecl()) {
1169+
auto ref = SILDeclRef::getMainDeclEntryPoint(decl);
1170+
addSymbol(entryPointSymbol, SymbolSource::forSILDeclRef(ref));
1171+
return;
1172+
}
1173+
1174+
auto ref = SILDeclRef::getMainFileEntryPoint(file);
1175+
addSymbol(entryPointSymbol, SymbolSource::forSILDeclRef(ref));
1176+
}
1177+
11551178
void TBDGenVisitor::visit(Decl *D) {
11561179
DeclStack.push_back(D);
11571180
SWIFT_DEFER { DeclStack.pop_back(); };
@@ -1348,8 +1371,8 @@ class APIGenRecorder final : public APIRecorder {
13481371
apigen::APIAvailability availability;
13491372
if (source.kind == SymbolSource::Kind::SIL) {
13501373
auto ref = source.getSILDeclRef();
1351-
if (auto *decl = ref.getDecl())
1352-
availability = getAvailability(decl);
1374+
if (ref.hasDecl())
1375+
availability = getAvailability(ref.getDecl());
13531376
}
13541377

13551378
api.addSymbol(symbol, moduleLoc, apigen::APILinkage::Exported,

lib/TBDGen/TBDGenVisitor.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,9 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
181181
TBDGenVisitor(const TBDGenDescriptor &desc, APIRecorder &recorder);
182182

183183
~TBDGenVisitor() { assert(DeclStack.empty()); }
184-
void addMainIfNecessary(FileUnit *file) {
185-
// HACK: 'main' is a special symbol that's always emitted in SILGen if
186-
// the file has an entry point. Since it doesn't show up in the
187-
// module until SILGen, we need to explicitly add it here.
188-
//
189-
// Make sure to only add the main symbol for the module that we're emitting
190-
// TBD for, and not for any statically linked libraries.
191-
// FIXME: We should have a SymbolSource for main.
192-
if (file->hasEntryPoint() && file->getParentModule() == SwiftModule)
193-
addSymbol(SwiftModule->getASTContext().getEntryPointFunctionName(),
194-
SymbolSource::forUnknown());
195-
}
184+
185+
/// Add the main symbol.
186+
void addMainIfNecessary(FileUnit *file);
196187

197188
/// Adds the global symbols associated with the first file.
198189
void addFirstFileSymbols();

0 commit comments

Comments
 (0)