mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ModuleInterface] Always use the real name for modules not imported directly
In AliasModuleNames, avoid wrongfully printing aliased names for modules that were not aliased. This can happen in the case of modules indirectly imported via a reexport. rdar://102262019
This commit is contained in:
@@ -49,7 +49,9 @@ version::Version swift::InterfaceFormatVersion({1, 0});
|
||||
/// construct \p M.
|
||||
static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
ModuleInterfaceOptions const &Opts,
|
||||
ModuleDecl *M) {
|
||||
ModuleDecl *M,
|
||||
llvm::SmallSet<StringRef, 4>
|
||||
&AliasModuleNamesTargets) {
|
||||
auto &Ctx = M->getASTContext();
|
||||
auto ToolsVersion =
|
||||
getSwiftInterfaceCompilerVersionForCurrentCompiler(Ctx);
|
||||
@@ -62,9 +64,8 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
|
||||
// Insert additional -module-alias flags
|
||||
if (Opts.AliasModuleNames) {
|
||||
llvm::SmallSet<StringRef, 2> aliasTargets;
|
||||
StringRef moduleName = M->getNameStr();
|
||||
aliasTargets.insert(M->getNameStr());
|
||||
AliasModuleNamesTargets.insert(M->getNameStr());
|
||||
out << " -module-alias " << MODULE_DISAMBIGUATING_PREFIX <<
|
||||
moduleName << "=" << moduleName;
|
||||
|
||||
@@ -77,7 +78,7 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
M->getMissingImportedModules(imports);
|
||||
for (ImportedModule import: imports) {
|
||||
StringRef importedName = import.importedModule->getNameStr();
|
||||
if (aliasTargets.insert(importedName).second) {
|
||||
if (AliasModuleNamesTargets.insert(importedName).second) {
|
||||
out << " -module-alias " << MODULE_DISAMBIGUATING_PREFIX <<
|
||||
importedName << "=" << importedName;
|
||||
}
|
||||
@@ -782,12 +783,14 @@ bool swift::emitSwiftInterface(raw_ostream &out,
|
||||
ModuleDecl *M) {
|
||||
assert(M);
|
||||
|
||||
printToolVersionAndFlagsComment(out, Opts, M);
|
||||
llvm::SmallSet<StringRef, 4> aliasModuleNamesTargets;
|
||||
printToolVersionAndFlagsComment(out, Opts, M, aliasModuleNamesTargets);
|
||||
|
||||
printImports(out, Opts, M);
|
||||
|
||||
const PrintOptions printOptions = PrintOptions::printSwiftInterfaceFile(
|
||||
M, Opts.PreserveTypesAsWritten, Opts.PrintFullConvention, Opts.PrintSPIs,
|
||||
Opts.AliasModuleNames);
|
||||
Opts.AliasModuleNames, &aliasModuleNamesTargets);
|
||||
InheritedProtocolCollector::PerTypeMap inheritedProtocolMap;
|
||||
|
||||
SmallVector<Decl *, 16> topLevelDecls;
|
||||
|
||||
Reference in New Issue
Block a user