[Frontend] Output the private module interface with the SPI info

This commit is contained in:
Alexis Laferrière
2020-02-06 12:28:26 -08:00
parent 2e73cb44fd
commit 901392896d
19 changed files with 139 additions and 24 deletions

View File

@@ -83,12 +83,15 @@ llvm::Regex swift::getSwiftInterfaceModuleFlagsRegex() {
/// Prints the imported modules in \p M to \p out in the form of \c import
/// source declarations.
static void printImports(raw_ostream &out, ModuleDecl *M) {
static void printImports(raw_ostream &out,
ModuleInterfaceOptions const &Opts,
ModuleDecl *M) {
// FIXME: This is very similar to what's in Serializer::writeInputBlock, but
// it's not obvious what higher-level optimization would be factored out here.
ModuleDecl::ImportFilter allImportFilter;
allImportFilter |= ModuleDecl::ImportFilterKind::Public;
allImportFilter |= ModuleDecl::ImportFilterKind::Private;
allImportFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
SmallVector<ModuleDecl::ImportedModule, 8> allImports;
M->getImportedModules(allImports, allImportFilter);
@@ -104,15 +107,25 @@ static void printImports(raw_ostream &out, ModuleDecl *M) {
publicImportSet.insert(publicImports.begin(), publicImports.end());
for (auto import : allImports) {
if (import.second->isOnoneSupportModule() ||
import.second->isBuiltinModule()) {
auto importedModule = import.second;
if (importedModule->isOnoneSupportModule() ||
importedModule->isBuiltinModule()) {
continue;
}
if (publicImportSet.count(import))
out << "@_exported ";
// SPI attribute on imports
if (Opts.PrintSPIs) {
SmallVector<Identifier, 4> spis;
M->lookupImportedSPIs(importedModule, spis);
for (auto spiName : spis)
out << "@_spi(" << spiName << ") ";
}
out << "import ";
import.second->getReverseFullModuleName().printForward(out);
importedModule->getReverseFullModuleName().printForward(out);
// Write the access path we should be honoring but aren't.
// (See diagnoseScopedImports above.)
@@ -437,10 +450,10 @@ bool swift::emitSwiftInterface(raw_ostream &out,
assert(M);
printToolVersionAndFlagsComment(out, Opts, M);
printImports(out, M);
printImports(out, Opts, M);
const PrintOptions printOptions = PrintOptions::printSwiftInterfaceFile(
Opts.PreserveTypesAsWritten, Opts.PrintFullConvention);
Opts.PreserveTypesAsWritten, Opts.PrintFullConvention, Opts.PrintSPIs);
InheritedProtocolCollector::PerTypeMap inheritedProtocolMap;
SmallVector<Decl *, 16> topLevelDecls;