[ModuleInterface] Print @_spiOnly imports in the private swiftinterface

This commit is contained in:
Alexis Laferrière
2022-08-25 09:41:34 -07:00
parent a530e3841a
commit 67e35c3b3e
2 changed files with 121 additions and 2 deletions

View File

@@ -217,6 +217,26 @@ static void printImports(raw_ostream &out,
allImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
}
/// Collect @_spiOnly imports that are not imported elsewhere publicly.
llvm::SmallSet<ImportedModule, 4, ImportedModule::Order> spiOnlyImportSet;
if (Opts.PrintSPIs) {
SmallVector<ImportedModule, 4> spiOnlyImports, otherImports;
M->getImportedModules(spiOnlyImports,
ModuleDecl::ImportFilterKind::SPIOnly);
M->getImportedModules(otherImports,
allImportFilter);
llvm::SmallSet<ImportedModule, 8, ImportedModule::Order> otherImportsSet;
otherImportsSet.insert(otherImports.begin(), otherImports.end());
// Rule out inconsistent imports.
for (auto import: spiOnlyImports)
if (otherImportsSet.count(import) == 0)
spiOnlyImportSet.insert(import);
allImportFilter |= ModuleDecl::ImportFilterKind::SPIOnly;
}
SmallVector<ImportedModule, 8> allImports;
M->getImportedModules(allImports, allImportFilter);
@@ -231,7 +251,6 @@ static void printImports(raw_ostream &out,
SmallVector<ImportedModule, 8> publicImports;
M->getImportedModules(publicImports, ModuleDecl::ImportFilterKind::Exported);
llvm::SmallSet<ImportedModule, 8, ImportedModule::Order> publicImportSet;
publicImportSet.insert(publicImports.begin(), publicImports.end());
for (auto import : allImports) {
@@ -259,8 +278,18 @@ static void printImports(raw_ostream &out,
if (publicImportSet.count(import))
out << "@_exported ";
// SPI attribute on imports
if (Opts.PrintSPIs) {
// An import visible in the private swiftinterface only.
//
// In the long term, we want to print this attribute for consistency and
// to enforce exportability analysis of generated code.
// For now, not printing the attribute allows us to have backwards
// compatible swiftinterfaces and we can live without
// checking the generate code for a while.
if (spiOnlyImportSet.count(import))
out << "/*@_spiOnly*/ ";
// List of imported SPI groups for local use.
for (auto spiName : spis)
out << "@_spi(" << spiName << ") ";
}