@@ -203,7 +203,8 @@ namespace {
203203 int32_t getNameDataForBase (const NominalTypeDecl *nominal,
204204 StringRef *dataToWrite = nullptr ) {
205205 if (nominal->getDeclContext ()->isModuleScopeContext ())
206- return -Serializer.addContainingModuleRef (nominal->getDeclContext ());
206+ return -Serializer.addContainingModuleRef (nominal->getDeclContext (),
207+ /* ignoreExport=*/ false );
207208
208209 auto &mangledName = MangledNameCache[nominal];
209210 if (mangledName.empty ())
@@ -727,7 +728,8 @@ IdentifierID Serializer::addFilename(StringRef filename) {
727728 return addUniquedString (filename).second ;
728729}
729730
730- IdentifierID Serializer::addContainingModuleRef (const DeclContext *DC) {
731+ IdentifierID Serializer::addContainingModuleRef (const DeclContext *DC,
732+ bool ignoreExport) {
731733 assert (!isa<ModuleDecl>(DC) &&
732734 " References should be to things within modules" );
733735 const FileUnit *file = cast<FileUnit>(DC->getModuleScopeContext ());
@@ -746,8 +748,19 @@ IdentifierID Serializer::addContainingModuleRef(const DeclContext *DC) {
746748
747749 auto exportedModuleName = file->getExportedModuleName ();
748750 assert (!exportedModuleName.empty ());
749- auto exportedModuleID = M->getASTContext ().getIdentifier (exportedModuleName);
750- return addDeclBaseNameRef (exportedModuleID);
751+ auto moduleID = M->getASTContext ().getIdentifier (exportedModuleName);
752+ if (ignoreExport) {
753+ auto realModuleName = M->getRealName ().str ();
754+ assert (!realModuleName.empty ());
755+ if (realModuleName != exportedModuleName) {
756+ // Still register the exported name as it can be referenced
757+ // from the lookup tables.
758+ addDeclBaseNameRef (moduleID);
759+
760+ moduleID = M->getASTContext ().getIdentifier (realModuleName);
761+ }
762+ }
763+ return addDeclBaseNameRef (moduleID);
751764}
752765
753766IdentifierID Serializer::addModuleRef (const ModuleDecl *module ) {
@@ -1632,7 +1645,8 @@ Serializer::writeASTBlockEntity(ProtocolConformance *conformance) {
16321645 abbrCode,
16331646 addDeclRef (normal->getProtocol ()),
16341647 addDeclRef (normal->getType ()->getAnyNominal ()),
1635- addContainingModuleRef (normal->getDeclContext ()));
1648+ addContainingModuleRef (normal->getDeclContext (),
1649+ /* ignoreExport=*/ true ));
16361650 }
16371651 break ;
16381652 }
@@ -1831,7 +1845,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
18311845 case DeclContextKind::FileUnit:
18321846 abbrCode = DeclTypeAbbrCodes[XRefLayout::Code];
18331847 XRefLayout::emitRecord (Out, ScratchRecord, abbrCode,
1834- addContainingModuleRef (DC), pathLen);
1848+ addContainingModuleRef (DC, /* ignoreExport=*/ true ),
1849+ pathLen);
18351850 break ;
18361851
18371852 case DeclContextKind::GenericTypeDecl: {
@@ -1883,7 +1898,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
18831898 genericSig = ext->getGenericSignature ().getCanonicalSignature ();
18841899 }
18851900 XRefExtensionPathPieceLayout::emitRecord (
1886- Out, ScratchRecord, abbrCode, addContainingModuleRef (DC),
1901+ Out, ScratchRecord, abbrCode,
1902+ addContainingModuleRef (DC, /* ignoreExport=*/ true ),
18871903 addGenericSignatureRef (genericSig));
18881904 break ;
18891905 }
0 commit comments