[interop] clear importer decl when emitting symbolic interface

This ensures that our interface do not reference already instantiated and imported specializations.
This commit is contained in:
Alex Lorenz
2023-01-31 12:54:13 -08:00
parent 0e60775e9a
commit a44a98bf64
5 changed files with 62 additions and 24 deletions

View File

@@ -544,18 +544,6 @@ void swift::ide::printModuleInterface(
auto &SwiftContext = TopLevelMod->getASTContext();
auto &Importer =
static_cast<ClangImporter &>(*SwiftContext.getClangModuleLoader());
if (Options.PrintSymbolicCXXDecls)
Importer.enableSymbolicImportFeature(true);
struct SymbolicImportRAII {
bool PrintSymbolicCXXDecls;
ClangImporter &Importer;
SymbolicImportRAII(bool PrintSymbolicCXXDecls, ClangImporter &Importer)
: PrintSymbolicCXXDecls(PrintSymbolicCXXDecls), Importer(Importer) {}
~SymbolicImportRAII() {
if (PrintSymbolicCXXDecls)
Importer.enableSymbolicImportFeature(false);
}
} deferDisableSymbolicImport(Options.PrintSymbolicCXXDecls, Importer);
auto AdjustedOptions = Options;
adjustPrintOptions(AdjustedOptions);
@@ -1159,9 +1147,14 @@ void swift::ide::printSymbolicSwiftClangModuleInterface(
opts |= ModuleTraversal::VisitSubmodules;
auto popts =
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
popts.PrintSymbolicCXXDecls = true;
popts.PrintDocumentationComments = false;
popts.PrintRegularClangComments = false;
printModuleInterface(M, {}, opts, Printer, popts,
/*SynthesizeExtensions=*/false);
auto &SwiftContext = M->getTopLevelModule()->getASTContext();
auto &Importer =
static_cast<ClangImporter &>(*SwiftContext.getClangModuleLoader());
Importer.withSymbolicFeatureEnabled([&]() {
printModuleInterface(M, {}, opts, Printer, popts,
/*SynthesizeExtensions=*/false);
});
}