@@ -1152,6 +1152,29 @@ void TBDGenVisitor::addFirstFileSymbols() {
1152
1152
}
1153
1153
}
1154
1154
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
+
1155
1178
void TBDGenVisitor::visit (Decl *D) {
1156
1179
DeclStack.push_back (D);
1157
1180
SWIFT_DEFER { DeclStack.pop_back (); };
@@ -1348,8 +1371,8 @@ class APIGenRecorder final : public APIRecorder {
1348
1371
apigen::APIAvailability availability;
1349
1372
if (source.kind == SymbolSource::Kind::SIL) {
1350
1373
auto ref = source.getSILDeclRef ();
1351
- if (auto *decl = ref.getDecl ())
1352
- availability = getAvailability (decl );
1374
+ if (ref.hasDecl ())
1375
+ availability = getAvailability (ref. getDecl () );
1353
1376
}
1354
1377
1355
1378
api.addSymbol (symbol, moduleLoc, apigen::APILinkage::Exported,
0 commit comments