mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ModuleInterface] Print @_spiOnly imports in the private swiftinterface
This commit is contained in:
@@ -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 << ") ";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user