@@ -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+
11551178void 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,
0 commit comments