@@ -180,7 +180,7 @@ namespace {
180
180
int32_t getNameDataForBase (const NominalTypeDecl *nominal,
181
181
StringRef *dataToWrite = nullptr ) {
182
182
if (nominal->getDeclContext ()->isModuleScopeContext ())
183
- return -Serializer.addModuleRef (nominal->getParentModule ());
183
+ return -Serializer.addContainingModuleRef (nominal->getDeclContext ());
184
184
185
185
auto &mangledName = MangledNameCache[nominal];
186
186
if (mangledName.empty ())
@@ -731,7 +731,12 @@ IdentifierID Serializer::addFilename(StringRef filename) {
731
731
return addUniquedString (filename).second ;
732
732
}
733
733
734
- IdentifierID Serializer::addModuleRef (const ModuleDecl *M) {
734
+ IdentifierID Serializer::addContainingModuleRef (const DeclContext *DC) {
735
+ assert (!isa<ModuleDecl>(DC) &&
736
+ " References should be to things within modules" );
737
+ const FileUnit *file = cast<FileUnit>(DC->getModuleScopeContext ());
738
+ const ModuleDecl *M = file->getParentModule ();
739
+
735
740
if (M == this ->M )
736
741
return CURRENT_MODULE_ID;
737
742
if (M == this ->M ->getASTContext ().TheBuiltinModule )
@@ -743,18 +748,10 @@ IdentifierID Serializer::addModuleRef(const ModuleDecl *M) {
743
748
if (M == clangImporter->getImportedHeaderModule ())
744
749
return OBJC_HEADER_MODULE_ID;
745
750
746
- // If we're referring to a member of a private module that will be
747
- // re-exported via a public module, record the public module's name.
748
- if (auto clangModuleUnit =
749
- dyn_cast<ClangModuleUnit>(M->getFiles ().front ())) {
750
- auto exportedModuleName =
751
- M->getASTContext ().getIdentifier (
752
- clangModuleUnit->getExportedModuleName ());
753
- return addDeclBaseNameRef (exportedModuleName);
754
- }
755
-
756
- assert (!M->getName ().empty ());
757
- return addDeclBaseNameRef (M->getName ());
751
+ auto exportedModuleName = file->getExportedModuleName ();
752
+ assert (!exportedModuleName.empty ());
753
+ auto exportedModuleID = M->getASTContext ().getIdentifier (exportedModuleName);
754
+ return addDeclBaseNameRef (exportedModuleID);
758
755
}
759
756
760
757
SILLayoutID Serializer::addSILLayoutRef (SILLayout *layout) {
@@ -1650,7 +1647,7 @@ Serializer::writeConformance(ProtocolConformanceRef conformanceRef,
1650
1647
abbrCode,
1651
1648
addDeclRef (normal->getProtocol ()),
1652
1649
addDeclRef (normal->getType ()->getAnyNominal ()),
1653
- addModuleRef (normal->getDeclContext ()-> getParentModule ()));
1650
+ addContainingModuleRef (normal->getDeclContext ()));
1654
1651
}
1655
1652
break ;
1656
1653
}
@@ -1885,14 +1882,13 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
1885
1882
case DeclContextKind::EnumElementDecl:
1886
1883
llvm_unreachable (" cannot cross-reference this context" );
1887
1884
1888
- case DeclContextKind::FileUnit:
1889
- DC = cast<FileUnit>(DC)->getParentModule ();
1890
- LLVM_FALLTHROUGH;
1891
-
1892
1885
case DeclContextKind::Module:
1886
+ llvm_unreachable (" should only cross-reference something within a file" );
1887
+
1888
+ case DeclContextKind::FileUnit:
1893
1889
abbrCode = DeclTypeAbbrCodes[XRefLayout::Code];
1894
1890
XRefLayout::emitRecord (Out, ScratchRecord, abbrCode,
1895
- addModuleRef (cast<ModuleDecl>(DC) ), pathLen);
1891
+ addContainingModuleRef (DC ), pathLen);
1896
1892
break ;
1897
1893
1898
1894
case DeclContextKind::GenericTypeDecl: {
@@ -1929,7 +1925,7 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
1929
1925
genericSig = ext->getGenericSignature ()->getCanonicalSignature ();
1930
1926
}
1931
1927
XRefExtensionPathPieceLayout::emitRecord (
1932
- Out, ScratchRecord, abbrCode, addModuleRef (DC-> getParentModule () ),
1928
+ Out, ScratchRecord, abbrCode, addContainingModuleRef (DC),
1933
1929
addGenericSignatureRef (genericSig));
1934
1930
break ;
1935
1931
}
@@ -2022,7 +2018,7 @@ void Serializer::writeCrossReference(const Decl *D) {
2022
2018
unsigned abbrCode;
2023
2019
2024
2020
if (auto op = dyn_cast<OperatorDecl>(D)) {
2025
- writeCrossReference (op->getModuleContext (), 1 );
2021
+ writeCrossReference (op->getDeclContext (), 1 );
2026
2022
2027
2023
abbrCode = DeclTypeAbbrCodes[XRefOperatorOrAccessorPathPieceLayout::Code];
2028
2024
auto nameID = addDeclBaseNameRef (op->getName ());
@@ -2034,7 +2030,7 @@ void Serializer::writeCrossReference(const Decl *D) {
2034
2030
}
2035
2031
2036
2032
if (auto prec = dyn_cast<PrecedenceGroupDecl>(D)) {
2037
- writeCrossReference (prec->getModuleContext (), 1 );
2033
+ writeCrossReference (prec->getDeclContext (), 1 );
2038
2034
2039
2035
abbrCode = DeclTypeAbbrCodes[XRefOperatorOrAccessorPathPieceLayout::Code];
2040
2036
auto nameID = addDeclBaseNameRef (prec->getName ());
0 commit comments