[Lldb-commits] [lldb] 731db2a - Revert "[C++20] [Modules] Support module level lookup (#122887)"

Chuanqi Xu via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 15 18:23:31 PST 2025


Author: Chuanqi Xu
Date: 2025-01-16T10:23:11+08:00
New Revision: 731db2a03e096fe42196f0ae6531179b998b0bf8

URL: https://github.com/llvm/llvm-project/commit/731db2a03e096fe42196f0ae6531179b998b0bf8
DIFF: https://github.com/llvm/llvm-project/commit/731db2a03e096fe42196f0ae6531179b998b0bf8.diff

LOG: Revert "[C++20] [Modules] Support module level lookup (#122887)"

This reverts commit 7201cae106260aeb3e9bbbb7d5291ff30f05076a.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/AST/DeclBase.h
    clang/include/clang/AST/ExternalASTMerger.h
    clang/include/clang/AST/ExternalASTSource.h
    clang/include/clang/Sema/MultiplexExternalSemaSource.h
    clang/include/clang/Serialization/ASTBitCodes.h
    clang/include/clang/Serialization/ASTReader.h
    clang/include/clang/Serialization/ASTWriter.h
    clang/lib/AST/DeclBase.cpp
    clang/lib/AST/ExternalASTMerger.cpp
    clang/lib/AST/ExternalASTSource.cpp
    clang/lib/Interpreter/CodeCompletion.cpp
    clang/lib/Sema/MultiplexExternalSemaSource.cpp
    clang/lib/Serialization/ASTReader.cpp
    clang/lib/Serialization/ASTReaderDecl.cpp
    clang/lib/Serialization/ASTReaderInternals.h
    clang/lib/Serialization/ASTWriter.cpp
    clang/lib/Serialization/ASTWriterDecl.cpp
    clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
    clang/test/CXX/module/basic/basic.link/p2.cppm
    clang/test/CXX/module/module.import/p2.cpp
    clang/test/CXX/module/module.interface/p7.cpp
    clang/test/CXX/module/module.reach/p5.cpp
    clang/test/Modules/Reachability-template-default-arg.cpp
    clang/test/Modules/cxx20-10-1-ex2.cpp
    clang/test/Modules/deduction-guide3.cppm
    clang/unittests/AST/ExternalASTSourceTest.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
    lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
    lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp

Removed: 
    clang/test/Modules/module-local-with-templates.cppm
    clang/test/Modules/pr90154.cppm


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c6bc95594f6133..6ac91f43e66d8b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -316,8 +316,6 @@ C++23 Feature Support
 C++20 Feature Support
 ^^^^^^^^^^^^^^^^^^^^^
 
-- Implemented module level lookup for C++20 modules. (#GH90154)
-
 
 Resolutions to C++ Defect Reports
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 91177c9a4b51fa..71ab9178509b2f 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -836,10 +836,6 @@ class alignas(8) Decl {
     return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();
   }
 
-  /// Get the top level owning named module that owns this declaration if any.
-  /// \returns nullptr if the declaration is not owned by a named module.
-  Module *getTopLevelOwningNamedModule() const;
-
   /// Get the module that owns this declaration for linkage purposes.
   /// There only ever is such a standard C++ module.
   Module *getOwningModuleForLinkage() const;
@@ -2726,12 +2722,6 @@ class DeclContext {
                    bool Deserialize = false) const;
 
 private:
-  /// Lookup all external visible declarations and the external declarations
-  /// within the same module specified by \c NamedModule. We can't
-  /// get it from \c this since the same declaration may be declared in
-  /// multiple modules. e.g., namespace.
-  lookup_result lookupImpl(DeclarationName Name, Module *NamedModule) const;
-
   /// Whether this declaration context has had externally visible
   /// storage added since the last lookup. In this case, \c LookupPtr's
   /// invariant may not hold and needs to be fixed before we perform

diff  --git a/clang/include/clang/AST/ExternalASTMerger.h b/clang/include/clang/AST/ExternalASTMerger.h
index 46f187c5e06948..ec4cfbe2175c02 100644
--- a/clang/include/clang/AST/ExternalASTMerger.h
+++ b/clang/include/clang/AST/ExternalASTMerger.h
@@ -141,8 +141,7 @@ class ExternalASTMerger : public ExternalASTSource {
 
   /// Implementation of the ExternalASTSource API.
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                      DeclarationName Name,
-                                      Module *NamedModule) override;
+                                      DeclarationName Name) override;
 
   /// Implementation of the ExternalASTSource API.
   void

diff  --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h
index ee4ad634977dc2..4d7ff822fceb75 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -51,7 +51,6 @@ class RecordDecl;
 class Selector;
 class Stmt;
 class TagDecl;
-class Module;
 
 /// Abstract interface for external sources of AST nodes.
 ///
@@ -146,20 +145,12 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
   /// Find all declarations with the given name in the given context,
   /// and add them to the context by calling SetExternalVisibleDeclsForName
   /// or SetNoExternalVisibleDeclsForName.
-  /// \param DC the context for lookup.
-  /// \param Name the name of the declarations to find.
-  /// \param NamedModule find declarations visible to the given module
-  /// \c NamedModule . This may be 
diff erent from owning module of \c DC since
-  /// there are declarations (e.g., namespace declaration) can appear in
-  /// multiple modules.
-  ///
-  /// \return \c true if any declarations might have been found, and \c false
-  /// if we definitely have no declarations with this name.
+  /// \return \c true if any declarations might have been found, \c false if
+  /// we definitely have no declarations with tbis name.
   ///
   /// The default implementation of this method is a no-op returning \c false.
-  virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                              DeclarationName Name,
-                                              Module *NamedModule);
+  virtual bool
+  FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
 
   /// Load all the external specializations for the Decl \param D if \param
   /// OnlyPartial is false. Otherwise, load all the external **partial**

diff  --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index 08d6143f7caaf3..0c92c52854c9e7 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -95,8 +95,7 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
   /// Find all declarations with the given name in the
   /// given context.
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                      DeclarationName Name,
-                                      Module *NamedModule) override;
+                                      DeclarationName Name) override;
 
   bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
 

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 40dae25f7b54b7..aac165130b7192 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -738,8 +738,6 @@ enum ASTRecordTypes {
   CXX_ADDED_TEMPLATE_SPECIALIZATION = 74,
 
   CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION = 75,
-
-  UPDATE_MODULE_LOCAL_VISIBLE = 76,
 };
 
 /// Record types used within a source manager block.
@@ -1336,10 +1334,6 @@ enum DeclCode {
   /// into a DeclContext via DeclContext::lookup.
   DECL_CONTEXT_VISIBLE,
 
-  /// A record containing the set of declarations that are
-  /// only visible from DeclContext in the same module.
-  DECL_CONTEXT_MODULE_LOCAL_VISIBLE,
-
   /// A LabelDecl record.
   DECL_LABEL,
 

diff  --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index ea12adaec3ee81..9f978762a6fb6b 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -353,7 +353,6 @@ class ASTIdentifierLookupTrait;
 
 /// The on-disk hash table(s) used for DeclContext name lookup.
 struct DeclContextLookupTable;
-struct ModuleLocalLookupTable;
 
 /// The on-disk hash table(s) used for specialization decls.
 struct LazySpecializationInfoLookupTable;
@@ -524,14 +523,9 @@ class ASTReader
   /// in the chain.
   DeclUpdateOffsetsMap DeclUpdateOffsets;
 
-  struct LookupBlockOffsets {
-    uint64_t LexicalOffset;
-    uint64_t VisibleOffset;
-    uint64_t ModuleLocalOffset;
-  };
-
   using DelayedNamespaceOffsetMapTy =
-      llvm::DenseMap<GlobalDeclID, LookupBlockOffsets>;
+      llvm::DenseMap<GlobalDeclID, std::pair</*LexicalOffset*/ uint64_t,
+                                             /*VisibleOffset*/ uint64_t>>;
 
   /// Mapping from global declaration IDs to the lexical and visible block
   /// offset for delayed namespace in reduced BMI.
@@ -637,9 +631,6 @@ class ASTReader
   /// Map from a DeclContext to its lookup tables.
   llvm::DenseMap<const DeclContext *,
                  serialization::reader::DeclContextLookupTable> Lookups;
-  llvm::DenseMap<const DeclContext *,
-                 serialization::reader::ModuleLocalLookupTable>
-      ModuleLocalLookups;
 
   using SpecLookupTableTy =
       llvm::DenseMap<const Decl *,
@@ -668,8 +659,6 @@ class ASTReader
   /// Updates to the visible declarations of declaration contexts that
   /// haven't been loaded yet.
   llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> PendingVisibleUpdates;
-  llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates>
-      PendingModuleLocalVisibleUpdates;
 
   using SpecializationsUpdate = SmallVector<UpdateData, 1>;
   using SpecializationsUpdateMap =
@@ -707,8 +696,7 @@ class ASTReader
   /// Read the record that describes the visible contents of a DC.
   bool ReadVisibleDeclContextStorage(ModuleFile &M,
                                      llvm::BitstreamCursor &Cursor,
-                                     uint64_t Offset, GlobalDeclID ID,
-                                     bool IsModuleLocal);
+                                     uint64_t Offset, GlobalDeclID ID);
 
   bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
                            uint64_t Offset, Decl *D, bool IsPartial);
@@ -1144,10 +1132,6 @@ class ASTReader
   /// Number of visible decl contexts read/total.
   unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
 
-  /// Number of module local visible decl contexts read/total.
-  unsigned NumModuleLocalVisibleDeclContexts = 0,
-           TotalModuleLocalVisibleDeclContexts = 0;
-
   /// Total size of modules, in bits, currently loaded
   uint64_t TotalModulesSizeInBits = 0;
 
@@ -1460,9 +1444,6 @@ class ASTReader
   const serialization::reader::DeclContextLookupTable *
   getLoadedLookupTables(DeclContext *Primary) const;
 
-  const serialization::reader::ModuleLocalLookupTable *
-  getModuleLocalLookupTables(DeclContext *Primary) const;
-
   /// Get the loaded specializations lookup tables for \p D,
   /// if any.
   serialization::reader::LazySpecializationInfoLookupTable *
@@ -2138,8 +2119,7 @@ class ASTReader
   /// The current implementation of this method just loads the entire
   /// lookup table as unmaterialized references.
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                      DeclarationName Name,
-                                      Module *NamedModule) override;
+                                      DeclarationName Name) override;
 
   /// Read all of the declarations lexically stored in a
   /// declaration context.
@@ -2627,10 +2607,6 @@ inline bool shouldSkipCheckingODR(const Decl *D) {
          (D->isFromGlobalModule() || D->isFromHeaderUnit());
 }
 
-/// Calculate a hash value for the primary module name of the given module.
-/// \returns std::nullopt if M is not a C++ standard module.
-std::optional<unsigned> getPrimaryModuleHash(const Module *M);
-
 } // namespace clang
 
 #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H

diff  --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index 53b09cc914392e..adb7cce522a803 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -492,10 +492,6 @@ class ASTWriter : public ASTDeserializationListener,
   /// file.
   unsigned NumVisibleDeclContexts = 0;
 
-  /// The number of module local visible declcontexts written to the AST
-  /// file.
-  unsigned NumModuleLocalDeclContexts = 0;
-
   /// A mapping from each known submodule to its ID number, which will
   /// be a positive integer.
   llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
@@ -591,15 +587,11 @@ class ASTWriter : public ASTDeserializationListener,
   uint64_t WriteSpecializationInfoLookupTable(
       const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
       bool IsPartial);
-  void
-  GenerateNameLookupTable(ASTContext &Context, const DeclContext *DC,
-                          llvm::SmallVectorImpl<char> &LookupTable,
-                          llvm::SmallVectorImpl<char> &ModuleLocalLookupTable);
+  void GenerateNameLookupTable(ASTContext &Context, const DeclContext *DC,
+                               llvm::SmallVectorImpl<char> &LookupTable);
   uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
                                         const DeclContext *DC);
-  void WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC,
-                                    uint64_t &VisibleBlockOffset,
-                                    uint64_t &ModuleLocalBlockOffset);
+  uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
   void WriteTypeDeclOffsets();
   void WriteFileDeclIDsMap();
   void WriteComments(ASTContext &Context);
@@ -632,9 +624,7 @@ class ASTWriter : public ASTDeserializationListener,
   unsigned DeclParmVarAbbrev = 0;
   unsigned DeclContextLexicalAbbrev = 0;
   unsigned DeclContextVisibleLookupAbbrev = 0;
-  unsigned DeclModuleLocalVisibleLookupAbbrev = 0;
   unsigned UpdateVisibleAbbrev = 0;
-  unsigned ModuleLocalUpdateVisibleAbbrev = 0;
   unsigned DeclRecordAbbrev = 0;
   unsigned DeclTypedefAbbrev = 0;
   unsigned DeclVarAbbrev = 0;

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 42daaa4f3dcc37..fb701f76231bcd 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1850,28 +1850,15 @@ void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
   }
 }
 
-Module *Decl::getTopLevelOwningNamedModule() const {
-  if (getOwningModule() &&
-      getOwningModule()->getTopLevelModule()->isNamedModule())
-    return getOwningModule()->getTopLevelModule();
-
-  return nullptr;
-}
-
 DeclContext::lookup_result
 DeclContext::lookup(DeclarationName Name) const {
-  return lookupImpl(Name, cast<Decl>(this)->getTopLevelOwningNamedModule());
-}
-
-DeclContext::lookup_result DeclContext::lookupImpl(DeclarationName Name,
-                                                   Module *NamedModule) const {
   // For transparent DeclContext, we should lookup in their enclosing context.
   if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
-    return getParent()->lookupImpl(Name, NamedModule);
+    return getParent()->lookup(Name);
 
   const DeclContext *PrimaryContext = getPrimaryContext();
   if (PrimaryContext != this)
-    return PrimaryContext->lookupImpl(Name, NamedModule);
+    return PrimaryContext->lookup(Name);
 
   // If we have an external source, ensure that any later redeclarations of this
   // context have been loaded, since they may add names to the result of this
@@ -1902,8 +1889,7 @@ DeclContext::lookup_result DeclContext::lookupImpl(DeclarationName Name,
     if (!R.second && !R.first->second.hasExternalDecls())
       return R.first->second.getLookupResult();
 
-    if (Source->FindExternalVisibleDeclsByName(this, Name, NamedModule) ||
-        !R.second) {
+    if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
       if (StoredDeclsMap *Map = LookupPtr) {
         StoredDeclsMap::iterator I = Map->find(Name);
         if (I != Map->end())
@@ -2129,8 +2115,7 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
     if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
       if (hasExternalVisibleStorage() &&
           Map->find(D->getDeclName()) == Map->end())
-        Source->FindExternalVisibleDeclsByName(
-            this, D->getDeclName(), D->getTopLevelOwningNamedModule());
+        Source->FindExternalVisibleDeclsByName(this, D->getDeclName());
 
   // Insert this declaration into the map.
   StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];

diff  --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp
index a33f6e3447679c..7f7816e1b10eae 100644
--- a/clang/lib/AST/ExternalASTMerger.cpp
+++ b/clang/lib/AST/ExternalASTMerger.cpp
@@ -472,8 +472,7 @@ static bool importSpecializationsIfNeeded(Decl *D, ASTImporter *Importer) {
 }
 
 bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                                       DeclarationName Name,
-                                                       Module *NamedModule) {
+                                                       DeclarationName Name) {
   llvm::SmallVector<NamedDecl *, 1> Decls;
   llvm::SmallVector<Candidate, 4> Candidates;
 

diff  --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp
index 4a29f4944f73c0..543846c0093af8 100644
--- a/clang/lib/AST/ExternalASTSource.cpp
+++ b/clang/lib/AST/ExternalASTSource.cpp
@@ -90,9 +90,9 @@ ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
   return nullptr;
 }
 
-bool ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                                       DeclarationName Name,
-                                                       Module *NamedModule) {
+bool
+ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
+                                                  DeclarationName Name) {
   return false;
 }
 

diff  --git a/clang/lib/Interpreter/CodeCompletion.cpp b/clang/lib/Interpreter/CodeCompletion.cpp
index 9092d4705ca58a..bbc8830d76bc00 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -228,8 +228,7 @@ class ExternalSource : public clang::ExternalASTSource {
   ExternalSource(ASTContext &ChildASTCtxt, FileManager &ChildFM,
                  ASTContext &ParentASTCtxt, FileManager &ParentFM);
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                      DeclarationName Name,
-                                      Module *NamedModule) override;
+                                      DeclarationName Name) override;
   void
   completeVisibleDeclsMap(const clang::DeclContext *childDeclContext) override;
 };
@@ -272,8 +271,7 @@ ExternalSource::ExternalSource(ASTContext &ChildASTCtxt, FileManager &ChildFM,
 }
 
 bool ExternalSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                                    DeclarationName Name,
-                                                    Module *NamedModule) {
+                                                    DeclarationName Name) {
 
   IdentifierTable &ParentIdTable = ParentASTCtxt.Idents;
 

diff  --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp
index c19a0f980c1e9a..54944267b4868a 100644
--- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp
+++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp
@@ -107,12 +107,11 @@ MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) {
   return EK_ReplyHazy;
 }
 
-bool MultiplexExternalSemaSource::FindExternalVisibleDeclsByName(
-    const DeclContext *DC, DeclarationName Name, Module *NamedModule) {
+bool MultiplexExternalSemaSource::
+FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
   bool AnyDeclsFound = false;
   for (size_t i = 0; i < Sources.size(); ++i)
-    AnyDeclsFound |=
-        Sources[i]->FindExternalVisibleDeclsByName(DC, Name, NamedModule);
+    AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
   return AnyDeclsFound;
 }
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 06853a227215e0..7361cace49dd7b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1235,7 +1235,7 @@ unsigned DeclarationNameKey::getHash() const {
 }
 
 ModuleFile *
-ASTDeclContextNameLookupTraitBase::ReadFileRef(const unsigned char *&d) {
+ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) {
   using namespace llvm::support;
 
   uint32_t ModuleFileID =
@@ -1244,12 +1244,12 @@ ASTDeclContextNameLookupTraitBase::ReadFileRef(const unsigned char *&d) {
 }
 
 std::pair<unsigned, unsigned>
-ASTDeclContextNameLookupTraitBase::ReadKeyDataLength(const unsigned char *&d) {
+ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) {
   return readULEBKeyDataLength(d);
 }
 
-DeclarationNameKey
-ASTDeclContextNameLookupTraitBase::ReadKeyBase(const unsigned char *&d) {
+ASTDeclContextNameLookupTrait::internal_key_type
+ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
   using namespace llvm::support;
 
   auto Kind = (DeclarationName::NameKind)*d++;
@@ -1283,13 +1283,10 @@ ASTDeclContextNameLookupTraitBase::ReadKeyBase(const unsigned char *&d) {
   return DeclarationNameKey(Kind, Data);
 }
 
-ASTDeclContextNameLookupTrait::internal_key_type
-ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
-  return ReadKeyBase(d);
-}
-
-void ASTDeclContextNameLookupTraitBase::ReadDataIntoImpl(
-    const unsigned char *d, unsigned DataLen, data_type_builder &Val) {
+void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type,
+                                                 const unsigned char *d,
+                                                 unsigned DataLen,
+                                                 data_type_builder &Val) {
   using namespace llvm::support;
 
   for (unsigned NumDecls = DataLen / sizeof(DeclID); NumDecls; --NumDecls) {
@@ -1299,47 +1296,6 @@ void ASTDeclContextNameLookupTraitBase::ReadDataIntoImpl(
   }
 }
 
-void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type,
-                                                 const unsigned char *d,
-                                                 unsigned DataLen,
-                                                 data_type_builder &Val) {
-  ReadDataIntoImpl(d, DataLen, Val);
-}
-
-ModuleLocalNameLookupTrait::hash_value_type
-ModuleLocalNameLookupTrait::ComputeHash(const internal_key_type &Key) {
-  llvm::FoldingSetNodeID ID;
-  ID.AddInteger(Key.first.getHash());
-  ID.AddInteger(Key.second);
-  return ID.computeStableHash();
-}
-
-ModuleLocalNameLookupTrait::internal_key_type
-ModuleLocalNameLookupTrait::GetInternalKey(const external_key_type &Key) {
-  DeclarationNameKey Name(Key.first);
-
-  std::optional<unsigned> ModuleHash = getPrimaryModuleHash(Key.second);
-  if (!ModuleHash)
-    return {Name, 0};
-
-  return {Name, *ModuleHash};
-}
-
-ModuleLocalNameLookupTrait::internal_key_type
-ModuleLocalNameLookupTrait::ReadKey(const unsigned char *d, unsigned) {
-  DeclarationNameKey Name = ReadKeyBase(d);
-  unsigned PrimaryModuleHash =
-      llvm::support::endian::readNext<uint32_t, llvm::endianness::little>(d);
-  return {Name, PrimaryModuleHash};
-}
-
-void ModuleLocalNameLookupTrait::ReadDataInto(internal_key_type,
-                                              const unsigned char *d,
-                                              unsigned DataLen,
-                                              data_type_builder &Val) {
-  ReadDataIntoImpl(d, DataLen, Val);
-}
-
 ModuleFile *
 LazySpecializationInfoLookupTrait::ReadFileRef(const unsigned char *&d) {
   using namespace llvm::support;
@@ -1427,8 +1383,8 @@ bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
 
 bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
                                               BitstreamCursor &Cursor,
-                                              uint64_t Offset, GlobalDeclID ID,
-                                              bool IsModuleLocal) {
+                                              uint64_t Offset,
+                                              GlobalDeclID ID) {
   assert(Offset != 0);
 
   SavedStreamPosition SavedPosition(Cursor);
@@ -1452,22 +1408,15 @@ bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M,
     return true;
   }
   unsigned RecCode = MaybeRecCode.get();
-  if (!IsModuleLocal && RecCode != DECL_CONTEXT_VISIBLE) {
+  if (RecCode != DECL_CONTEXT_VISIBLE) {
     Error("Expected visible lookup table block");
     return true;
   }
-  if (IsModuleLocal && RecCode != DECL_CONTEXT_MODULE_LOCAL_VISIBLE) {
-    Error("Expected module local visible lookup table block");
-    return true;
-  }
 
   // We can't safely determine the primary context yet, so delay attaching the
   // lookup table until we're done with recursive deserialization.
   auto *Data = (const unsigned char*)Blob.data();
-  if (!IsModuleLocal)
-    PendingVisibleUpdates[ID].push_back(UpdateData{&M, Data});
-  else
-    PendingModuleLocalVisibleUpdates[ID].push_back(UpdateData{&M, Data});
+  PendingVisibleUpdates[ID].push_back(UpdateData{&M, Data});
   return false;
 }
 
@@ -3600,19 +3549,6 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
       break;
     }
 
-    case UPDATE_MODULE_LOCAL_VISIBLE: {
-      unsigned Idx = 0;
-      GlobalDeclID ID = ReadDeclID(F, Record, Idx);
-      auto *Data = (const unsigned char *)Blob.data();
-      PendingModuleLocalVisibleUpdates[ID].push_back(UpdateData{&F, Data});
-      // If we've already loaded the decl, perform the updates when we finish
-      // loading this block.
-      if (Decl *D = GetExistingDecl(ID))
-        PendingUpdateRecords.push_back(
-            PendingUpdateRecord(ID, D, /*JustLoaded=*/false));
-      break;
-    }
-
     case CXX_ADDED_TEMPLATE_SPECIALIZATION: {
       unsigned Idx = 0;
       GlobalDeclID ID = ReadDeclID(F, Record, Idx);
@@ -3716,7 +3652,6 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
       TotalNumMacros += Record[1];
       TotalLexicalDeclContexts += Record[2];
       TotalVisibleDeclContexts += Record[3];
-      TotalModuleLocalVisibleDeclContexts += Record[4];
       break;
 
     case UNUSED_FILESCOPED_DECLS:
@@ -4002,7 +3937,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
       break;
 
     case DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD: {
-      if (Record.size() % 4 != 0)
+      if (Record.size() % 3 != 0)
         return llvm::createStringError(
             std::errc::illegal_byte_sequence,
             "invalid DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD block in AST "
@@ -4018,12 +3953,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
         uint64_t LocalVisibleOffset = Record[I++];
         uint64_t VisibleOffset =
             LocalVisibleOffset ? BaseOffset + LocalVisibleOffset : 0;
-        uint64_t LocalModuleLocalOffset = Record[I++];
-        uint64_t ModuleLocalOffset =
-            LocalModuleLocalOffset ? BaseOffset + LocalModuleLocalOffset : 0;
 
-        DelayedNamespaceOffsetMap[ID] = {LexicalOffset, VisibleOffset,
-                                         ModuleLocalOffset};
+        DelayedNamespaceOffsetMap[ID] = {LexicalOffset, VisibleOffset};
 
         assert(!GetExistingDecl(ID) &&
                "We shouldn't load the namespace in the front of delayed "
@@ -8435,42 +8366,31 @@ void ASTReader::FindFileRegionDecls(FileID File,
         *DInfo.Mod, LocalDeclID::get(*this, *DInfo.Mod, *DIt))));
 }
 
-bool ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                               DeclarationName Name,
-                                               Module *NamedModule) {
+bool
+ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
+                                          DeclarationName Name) {
   assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
          "DeclContext has no visible decls in storage");
   if (!Name)
     return false;
 
-  // Load the list of declarations.
-  SmallVector<NamedDecl *, 64> Decls;
-  llvm::SmallPtrSet<NamedDecl *, 8> Found;
+  auto It = Lookups.find(DC);
+  if (It == Lookups.end())
+    return false;
 
   Deserializing LookupResults(this);
 
-  // FIXME: Clear the redundancy with templated lambda in C++20 when that's
-  // available.
-  if (auto It = Lookups.find(DC); It != Lookups.end()) {
-    ++NumVisibleDeclContextsRead;
-    for (GlobalDeclID ID : It->second.Table.find(Name)) {
-      NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
-      if (ND->getDeclName() == Name && Found.insert(ND).second)
-        Decls.push_back(ND);
-    }
-  }
+  // Load the list of declarations.
+  SmallVector<NamedDecl *, 64> Decls;
+  llvm::SmallPtrSet<NamedDecl *, 8> Found;
 
-  if (NamedModule) {
-    if (auto It = ModuleLocalLookups.find(DC); It != ModuleLocalLookups.end()) {
-      ++NumModuleLocalVisibleDeclContexts;
-      for (GlobalDeclID ID : It->second.Table.find({Name, NamedModule})) {
-        NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
-        if (ND->getDeclName() == Name && Found.insert(ND).second)
-          Decls.push_back(ND);
-      }
-    }
+  for (GlobalDeclID ID : It->second.Table.find(Name)) {
+    NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
+    if (ND->getDeclName() == Name && Found.insert(ND).second)
+      Decls.push_back(ND);
   }
 
+  ++NumVisibleDeclContextsRead;
   SetExternalVisibleDeclsForName(DC, Name, Decls);
   return !Decls.empty();
 }
@@ -8479,25 +8399,18 @@ void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) {
   if (!DC->hasExternalVisibleStorage())
     return;
 
-  DeclsMap Decls;
-
-  auto findAll = [&](auto &LookupTables, unsigned &NumRead) {
-    auto It = LookupTables.find(DC);
-    if (It == LookupTables.end())
-      return;
-
-    NumRead++;
+  auto It = Lookups.find(DC);
+  assert(It != Lookups.end() &&
+         "have external visible storage but no lookup tables");
 
-    for (GlobalDeclID ID : It->second.Table.findAll()) {
-      NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
-      Decls[ND->getDeclName()].push_back(ND);
-    }
+  DeclsMap Decls;
 
-    // FIXME: Why a PCH test is failing if we remove the iterator after findAll?
-  };
+  for (GlobalDeclID ID : It->second.Table.findAll()) {
+    NamedDecl *ND = cast<NamedDecl>(GetDecl(ID));
+    Decls[ND->getDeclName()].push_back(ND);
+  }
 
-  findAll(Lookups, NumVisibleDeclContextsRead);
-  findAll(ModuleLocalLookups, NumModuleLocalVisibleDeclContexts);
+  ++NumVisibleDeclContextsRead;
 
   for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
     SetExternalVisibleDeclsForName(DC, I->first, I->second);
@@ -8511,12 +8424,6 @@ ASTReader::getLoadedLookupTables(DeclContext *Primary) const {
   return I == Lookups.end() ? nullptr : &I->second;
 }
 
-const serialization::reader::ModuleLocalLookupTable *
-ASTReader::getModuleLocalLookupTables(DeclContext *Primary) const {
-  auto I = ModuleLocalLookups.find(Primary);
-  return I == ModuleLocalLookups.end() ? nullptr : &I->second;
-}
-
 serialization::reader::LazySpecializationInfoLookupTable *
 ASTReader::getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial) {
   assert(D->isCanonicalDecl());
@@ -8626,12 +8533,6 @@ void ASTReader::PrintStats() {
                  NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
                  ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
                   * 100));
-  if (TotalModuleLocalVisibleDeclContexts)
-    std::fprintf(
-        stderr, "  %u/%u module local visible declcontexts read (%f%%)\n",
-        NumModuleLocalVisibleDeclContexts, TotalModuleLocalVisibleDeclContexts,
-        ((float)NumModuleLocalVisibleDeclContexts /
-         TotalModuleLocalVisibleDeclContexts * 100));
   if (TotalNumMethodPoolEntries)
     std::fprintf(stderr, "  %u/%u method pool entries read (%f%%)\n",
                  NumMethodPoolEntriesRead, TotalNumMethodPoolEntries,
@@ -12738,25 +12639,3 @@ void ASTRecordReader::readOpenACCClauseList(
   for (unsigned I = 0; I < Clauses.size(); ++I)
     Clauses[I] = readOpenACCClause();
 }
-
-static unsigned getStableHashForModuleName(StringRef PrimaryModuleName) {
-  // TODO: Maybe it is better to check PrimaryModuleName is a valid
-  // module name?
-  llvm::FoldingSetNodeID ID;
-  ID.AddString(PrimaryModuleName);
-  return ID.computeStableHash();
-}
-
-std::optional<unsigned> clang::getPrimaryModuleHash(const Module *M) {
-  if (!M)
-    return std::nullopt;
-
-  if (M->isHeaderLikeModule())
-    return std::nullopt;
-
-  if (M->isGlobalModule())
-    return std::nullopt;
-
-  StringRef PrimaryModuleName = M->getPrimaryModuleInterfaceName();
-  return getStableHashForModuleName(PrimaryModuleName);
-}

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 1c51a7b5e460f6..95abd75920c8fe 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -413,8 +413,7 @@ class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
   void VisitEmptyDecl(EmptyDecl *D);
   void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
 
-  void VisitDeclContext(DeclContext *DC, uint64_t &LexicalOffset,
-                        uint64_t &VisibleOffset, uint64_t &ModuleLocalOffset);
+  std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
 
   template <typename T>
   RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
@@ -1856,10 +1855,7 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
 
 void ASTDeclReader::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
   VisitNamedDecl(D);
-  uint64_t LexicalOffset = 0;
-  uint64_t VisibleOffset = 0;
-  uint64_t ModuleLocalOffset = 0;
-  VisitDeclContext(D, LexicalOffset, VisibleOffset, ModuleLocalOffset);
+  VisitDeclContext(D);
   D->IsCBuffer = Record.readBool();
   D->KwLoc = readSourceLocation();
   D->LBraceLoc = readSourceLocation();
@@ -2768,12 +2764,11 @@ void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
   mergeMergeable(D);
 }
 
-void ASTDeclReader::VisitDeclContext(DeclContext *DC, uint64_t &LexicalOffset,
-                                     uint64_t &VisibleOffset,
-                                     uint64_t &ModuleLocalOffset) {
-  LexicalOffset = ReadLocalOffset();
-  VisibleOffset = ReadLocalOffset();
-  ModuleLocalOffset = ReadLocalOffset();
+std::pair<uint64_t, uint64_t>
+ASTDeclReader::VisitDeclContext(DeclContext *DC) {
+  uint64_t LexicalOffset = ReadLocalOffset();
+  uint64_t VisibleOffset = ReadLocalOffset();
+  return std::make_pair(LexicalOffset, VisibleOffset);
 }
 
 template <typename T>
@@ -3874,7 +3869,6 @@ Decl *ASTReader::ReadDeclRecord(GlobalDeclID ID) {
   switch ((DeclCode)MaybeDeclCode.get()) {
   case DECL_CONTEXT_LEXICAL:
   case DECL_CONTEXT_VISIBLE:
-  case DECL_CONTEXT_MODULE_LOCAL_VISIBLE:
   case DECL_SPECIALIZATIONS:
   case DECL_PARTIAL_SPECIALIZATIONS:
     llvm_unreachable("Record cannot be de-serialized with readDeclRecord");
@@ -4182,35 +4176,21 @@ Decl *ASTReader::ReadDeclRecord(GlobalDeclID ID) {
   // If this declaration is also a declaration context, get the
   // offsets for its tables of lexical and visible declarations.
   if (auto *DC = dyn_cast<DeclContext>(D)) {
-    uint64_t LexicalOffset = 0;
-    uint64_t VisibleOffset = 0;
-    uint64_t ModuleLocalOffset = 0;
-
-    Reader.VisitDeclContext(DC, LexicalOffset, VisibleOffset,
-                            ModuleLocalOffset);
+    std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
 
     // Get the lexical and visible block for the delayed namespace.
     // It is sufficient to judge if ID is in DelayedNamespaceOffsetMap.
     // But it may be more efficient to filter the other cases.
-    if (!LexicalOffset && !VisibleOffset && !ModuleLocalOffset &&
-        isa<NamespaceDecl>(D))
+    if (!Offsets.first && !Offsets.second && isa<NamespaceDecl>(D))
       if (auto Iter = DelayedNamespaceOffsetMap.find(ID);
-          Iter != DelayedNamespaceOffsetMap.end()) {
-        LexicalOffset = Iter->second.LexicalOffset;
-        VisibleOffset = Iter->second.VisibleOffset;
-        ModuleLocalOffset = Iter->second.ModuleLocalOffset;
-      }
+          Iter != DelayedNamespaceOffsetMap.end())
+        Offsets = Iter->second;
 
-    if (LexicalOffset &&
-        ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, LexicalOffset, DC))
-      return nullptr;
-    if (VisibleOffset &&
-        ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, VisibleOffset, ID,
-                                      /*IsModuleLocal=*/false))
+    if (Offsets.first &&
+        ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
       return nullptr;
-    if (ModuleLocalOffset &&
-        ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, ModuleLocalOffset,
-                                      ID, /*IsModuleLocal=*/true))
+    if (Offsets.second &&
+        ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
       return nullptr;
   }
   assert(Record.getIdx() == Record.size());
@@ -4348,8 +4328,8 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
   }
 
   // Load the pending visible updates for this decl context, if it has any.
-  if (auto I = PendingVisibleUpdates.find(ID);
-      I != PendingVisibleUpdates.end()) {
+  auto I = PendingVisibleUpdates.find(ID);
+  if (I != PendingVisibleUpdates.end()) {
     auto VisibleUpdates = std::move(I->second);
     PendingVisibleUpdates.erase(I);
 
@@ -4361,21 +4341,6 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
     DC->setHasExternalVisibleStorage(true);
   }
 
-  if (auto I = PendingModuleLocalVisibleUpdates.find(ID);
-      I != PendingModuleLocalVisibleUpdates.end()) {
-    auto ModuleLocalVisibleUpdates = std::move(I->second);
-    PendingModuleLocalVisibleUpdates.erase(I);
-
-    auto *DC = cast<DeclContext>(D)->getPrimaryContext();
-    for (const auto &Update : ModuleLocalVisibleUpdates)
-      ModuleLocalLookups[DC].Table.add(
-          Update.Mod, Update.Data,
-          reader::ModuleLocalNameLookupTrait(*this, *Update.Mod));
-    // NOTE: Can we optimize the case that the data being loaded
-    // is not related to current module?
-    DC->setHasExternalVisibleStorage(true);
-  }
-
   // Load any pending related decls.
   if (D->isCanonicalDecl()) {
     if (auto IT = RelatedDeclsMap.find(ID); IT != RelatedDeclsMap.end()) {

diff  --git a/clang/lib/Serialization/ASTReaderInternals.h b/clang/lib/Serialization/ASTReaderInternals.h
index 4be2b2323ec401..be0d22d1f4094f 100644
--- a/clang/lib/Serialization/ASTReaderInternals.h
+++ b/clang/lib/Serialization/ASTReaderInternals.h
@@ -31,7 +31,6 @@ class FileEntry;
 struct HeaderFileInfo;
 class HeaderSearch;
 class ObjCMethodDecl;
-class Module;
 
 namespace serialization {
 
@@ -39,8 +38,9 @@ class ModuleFile;
 
 namespace reader {
 
-class ASTDeclContextNameLookupTraitBase {
-protected:
+/// Class that performs name lookup into a DeclContext stored
+/// in an AST file.
+class ASTDeclContextNameLookupTrait {
   ASTReader &Reader;
   ModuleFile &F;
 
@@ -80,38 +80,12 @@ class ASTDeclContextNameLookupTraitBase {
   using offset_type = unsigned;
   using file_type = ModuleFile *;
 
-protected:
-  explicit ASTDeclContextNameLookupTraitBase(ASTReader &Reader, ModuleFile &F)
-      : Reader(Reader), F(F) {}
-
-public:
-  static std::pair<unsigned, unsigned>
-  ReadKeyDataLength(const unsigned char *&d);
-
-  void ReadDataIntoImpl(const unsigned char *d, unsigned DataLen,
-                        data_type_builder &Val);
-
-  static void MergeDataInto(const data_type &From, data_type_builder &To) {
-    To.Data.reserve(To.Data.size() + From.size());
-    for (GlobalDeclID ID : From)
-      To.insert(ID);
-  }
-
-  file_type ReadFileRef(const unsigned char *&d);
-
-  DeclarationNameKey ReadKeyBase(const unsigned char *&d);
-};
-
-/// Class that performs name lookup into a DeclContext stored
-/// in an AST file.
-class ASTDeclContextNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
-public:
-  explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
-      : ASTDeclContextNameLookupTraitBase(Reader, F) {}
-
   using external_key_type = DeclarationName;
   using internal_key_type = DeclarationNameKey;
 
+  explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
+      : Reader(Reader), F(F) {}
+
   static bool EqualKey(const internal_key_type &a, const internal_key_type &b) {
     return a == b;
   }
@@ -124,39 +98,25 @@ class ASTDeclContextNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
     return Name;
   }
 
+  static std::pair<unsigned, unsigned>
+  ReadKeyDataLength(const unsigned char *&d);
+
   internal_key_type ReadKey(const unsigned char *d, unsigned);
 
   void ReadDataInto(internal_key_type, const unsigned char *d,
                     unsigned DataLen, data_type_builder &Val);
-};
 
-struct DeclContextLookupTable {
-  MultiOnDiskHashTable<ASTDeclContextNameLookupTrait> Table;
-};
-
-class ModuleLocalNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
-public:
-  explicit ModuleLocalNameLookupTrait(ASTReader &Reader, ModuleFile &F)
-      : ASTDeclContextNameLookupTraitBase(Reader, F) {}
-
-  using external_key_type = std::pair<DeclarationName, const Module *>;
-  using internal_key_type = std::pair<DeclarationNameKey, unsigned>;
-
-  static bool EqualKey(const internal_key_type &a, const internal_key_type &b) {
-    return a == b;
+  static void MergeDataInto(const data_type &From, data_type_builder &To) {
+    To.Data.reserve(To.Data.size() + From.size());
+    for (GlobalDeclID ID : From)
+      To.insert(ID);
   }
 
-  static hash_value_type ComputeHash(const internal_key_type &Key);
-  static internal_key_type GetInternalKey(const external_key_type &Key);
-
-  internal_key_type ReadKey(const unsigned char *d, unsigned);
-
-  void ReadDataInto(internal_key_type, const unsigned char *d, unsigned DataLen,
-                    data_type_builder &Val);
+  file_type ReadFileRef(const unsigned char *&d);
 };
 
-struct ModuleLocalLookupTable {
-  MultiOnDiskHashTable<ModuleLocalNameLookupTrait> Table;
+struct DeclContextLookupTable {
+  MultiOnDiskHashTable<ASTDeclContextNameLookupTrait> Table;
 };
 
 using LazySpecializationInfo = GlobalDeclID;

diff  --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 1cc6a9b7950078..0ae2157eed4ecc 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1088,7 +1088,6 @@ void ASTWriter::WriteBlockInfoBlock() {
   RECORD(DECL_BLOCK);
   RECORD(DECL_CONTEXT_LEXICAL);
   RECORD(DECL_CONTEXT_VISIBLE);
-  RECORD(DECL_CONTEXT_MODULE_LOCAL_VISIBLE);
   RECORD(DECL_NAMESPACE);
   RECORD(DECL_NAMESPACE_ALIAS);
   RECORD(DECL_USING);
@@ -4027,13 +4026,15 @@ void ASTWriter::handleVTable(CXXRecordDecl *RD) {
 
 namespace {
 
-class ASTDeclContextNameLookupTraitBase {
-protected:
+// Trait used for the on-disk hash table used in the method pool.
+class ASTDeclContextNameLookupTrait {
   ASTWriter &Writer;
-  using DeclIDsTy = llvm::SmallVector<LocalDeclID, 64>;
-  DeclIDsTy DeclIDs;
+  llvm::SmallVector<LocalDeclID, 64> DeclIDs;
 
 public:
+  using key_type = DeclarationNameKey;
+  using key_type_ref = key_type;
+
   /// A start and end index into DeclIDs, representing a sequence of decls.
   using data_type = std::pair<unsigned, unsigned>;
   using data_type_ref = const data_type &;
@@ -4041,11 +4042,31 @@ class ASTDeclContextNameLookupTraitBase {
   using hash_value_type = unsigned;
   using offset_type = unsigned;
 
-protected:
-  explicit ASTDeclContextNameLookupTraitBase(ASTWriter &Writer)
-      : Writer(Writer) {}
+  explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) {}
+
+  template<typename Coll>
+  data_type getData(const Coll &Decls) {
+    unsigned Start = DeclIDs.size();
+    for (NamedDecl *D : Decls) {
+      NamedDecl *DeclForLocalLookup =
+          getDeclForLocalLookup(Writer.getLangOpts(), D);
+
+      if (Writer.getDoneWritingDeclsAndTypes() &&
+          !Writer.wasDeclEmitted(DeclForLocalLookup))
+        continue;
+
+      // Try to avoid writing internal decls to reduced BMI.
+      // See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
+      if (Writer.isGeneratingReducedBMI() &&
+          !DeclForLocalLookup->isFromExplicitGlobalModule() &&
+          IsInternalDeclFromFileContext(DeclForLocalLookup))
+        continue;
+
+      DeclIDs.push_back(Writer.GetDeclRef(DeclForLocalLookup));
+    }
+    return std::make_pair(Start, DeclIDs.size());
+  }
 
-public:
   data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) {
     unsigned Start = DeclIDs.size();
     DeclIDs.insert(
@@ -4055,6 +4076,14 @@ class ASTDeclContextNameLookupTraitBase {
     return std::make_pair(Start, DeclIDs.size());
   }
 
+  static bool EqualKey(key_type_ref a, key_type_ref b) {
+    return a == b;
+  }
+
+  hash_value_type ComputeHash(DeclarationNameKey Name) {
+    return Name.getHash();
+  }
+
   void EmitFileRef(raw_ostream &Out, ModuleFile *F) const {
     assert(Writer.hasChain() &&
            "have reference to loaded module file but no chain?");
@@ -4065,9 +4094,9 @@ class ASTDeclContextNameLookupTraitBase {
                             llvm::endianness::little);
   }
 
-  std::pair<unsigned, unsigned> EmitKeyDataLengthBase(raw_ostream &Out,
-                                                      DeclarationNameKey Name,
-                                                      data_type_ref Lookup) {
+  std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out,
+                                                  DeclarationNameKey Name,
+                                                  data_type_ref Lookup) {
     unsigned KeyLen = 1;
     switch (Name.getKind()) {
     case DeclarationName::Identifier:
@@ -4093,10 +4122,10 @@ class ASTDeclContextNameLookupTraitBase {
     // length of DeclIDs.
     unsigned DataLen = sizeof(DeclID) * (Lookup.second - Lookup.first);
 
-    return {KeyLen, DataLen};
+    return emitULEBKeyDataLength(KeyLen, DataLen, Out);
   }
 
-  void EmitKeyBase(raw_ostream &Out, DeclarationNameKey Name) {
+  void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) {
     using namespace llvm::support;
 
     endian::Writer LE(Out, llvm::endianness::little);
@@ -4127,7 +4156,8 @@ class ASTDeclContextNameLookupTraitBase {
     llvm_unreachable("Invalid name kind?");
   }
 
-  void EmitDataBase(raw_ostream &Out, data_type Lookup, unsigned DataLen) {
+  void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
+                unsigned DataLen) {
     using namespace llvm::support;
 
     endian::Writer LE(Out, llvm::endianness::little);
@@ -4138,129 +4168,6 @@ class ASTDeclContextNameLookupTraitBase {
   }
 };
 
-class ModuleLocalNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
-public:
-  using primary_module_hash_type = unsigned;
-
-  using key_type = std::pair<DeclarationNameKey, primary_module_hash_type>;
-  using key_type_ref = key_type;
-
-  explicit ModuleLocalNameLookupTrait(ASTWriter &Writer)
-      : ASTDeclContextNameLookupTraitBase(Writer) {}
-
-  data_type getData(const DeclIDsTy &LocalIDs) {
-    unsigned Start = DeclIDs.size();
-    for (auto ID : LocalIDs)
-      DeclIDs.push_back(ID);
-    return std::make_pair(Start, DeclIDs.size());
-  }
-
-  static bool EqualKey(key_type_ref a, key_type_ref b) { return a == b; }
-
-  hash_value_type ComputeHash(key_type Key) {
-    llvm::FoldingSetNodeID ID;
-    ID.AddInteger(Key.first.getHash());
-    ID.AddInteger(Key.second);
-    return ID.computeStableHash();
-  }
-
-  std::pair<unsigned, unsigned>
-  EmitKeyDataLength(raw_ostream &Out, key_type Key, data_type_ref Lookup) {
-    auto [KeyLen, DataLen] = EmitKeyDataLengthBase(Out, Key.first, Lookup);
-    KeyLen += sizeof(Key.second);
-    return emitULEBKeyDataLength(KeyLen, DataLen, Out);
-  }
-
-  void EmitKey(raw_ostream &Out, key_type Key, unsigned) {
-    EmitKeyBase(Out, Key.first);
-    llvm::support::endian::Writer LE(Out, llvm::endianness::little);
-    LE.write<primary_module_hash_type>(Key.second);
-  }
-
-  void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
-                unsigned DataLen) {
-    EmitDataBase(Out, Lookup, DataLen);
-  }
-};
-
-// Trait used for the on-disk hash table used in the method pool.
-class ASTDeclContextNameLookupTrait : public ASTDeclContextNameLookupTraitBase {
-public:
-  using ModuleLocalDeclsMapTy =
-      llvm::DenseMap<ModuleLocalNameLookupTrait::key_type, DeclIDsTy>;
-
-private:
-  ModuleLocalDeclsMapTy ModuleLocalDeclsMap;
-
-public:
-  using key_type = DeclarationNameKey;
-  using key_type_ref = key_type;
-
-  explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer)
-      : ASTDeclContextNameLookupTraitBase(Writer) {}
-
-  template <typename Coll> data_type getData(const Coll &Decls) {
-    unsigned Start = DeclIDs.size();
-    for (NamedDecl *D : Decls) {
-      NamedDecl *DeclForLocalLookup =
-          getDeclForLocalLookup(Writer.getLangOpts(), D);
-
-      if (Writer.getDoneWritingDeclsAndTypes() &&
-          !Writer.wasDeclEmitted(DeclForLocalLookup))
-        continue;
-
-      // Try to avoid writing internal decls to reduced BMI.
-      // See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
-      if (Writer.isGeneratingReducedBMI() &&
-          !DeclForLocalLookup->isFromExplicitGlobalModule() &&
-          IsInternalDeclFromFileContext(DeclForLocalLookup))
-        continue;
-
-      auto ID = Writer.GetDeclRef(DeclForLocalLookup);
-
-      if (D->getFormalLinkage() == Linkage::Module) {
-        if (std::optional<unsigned> PrimaryModuleHash =
-                getPrimaryModuleHash(D->getOwningModule())) {
-          auto Key = std::make_pair(D->getDeclName(), *PrimaryModuleHash);
-          auto Iter = ModuleLocalDeclsMap.find(Key);
-          if (Iter == ModuleLocalDeclsMap.end())
-            ModuleLocalDeclsMap.insert({Key, DeclIDsTy{ID}});
-          else
-            Iter->second.push_back(ID);
-          continue;
-        }
-      }
-
-      DeclIDs.push_back(ID);
-    }
-    return std::make_pair(Start, DeclIDs.size());
-  }
-
-  const ModuleLocalDeclsMapTy &getModuleLocalDecls() {
-    return ModuleLocalDeclsMap;
-  }
-
-  static bool EqualKey(key_type_ref a, key_type_ref b) { return a == b; }
-
-  hash_value_type ComputeHash(key_type Name) { return Name.getHash(); }
-
-  std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out,
-                                                  DeclarationNameKey Name,
-                                                  data_type_ref Lookup) {
-    auto [KeyLen, DataLen] = EmitKeyDataLengthBase(Out, Name, Lookup);
-    return emitULEBKeyDataLength(KeyLen, DataLen, Out);
-  }
-
-  void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) {
-    return EmitKeyBase(Out, Name);
-  }
-
-  void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup,
-                unsigned DataLen) {
-    EmitDataBase(Out, Lookup, DataLen);
-  }
-};
-
 } // namespace
 
 namespace {
@@ -4466,8 +4373,7 @@ static bool isLookupResultNotInteresting(ASTWriter &Writer,
 
 void ASTWriter::GenerateNameLookupTable(
     ASTContext &Context, const DeclContext *ConstDC,
-    llvm::SmallVectorImpl<char> &LookupTable,
-    llvm::SmallVectorImpl<char> &ModuleLocalLookupTable) {
+    llvm::SmallVectorImpl<char> &LookupTable) {
   assert(!ConstDC->hasLazyLocalLexicalLookups() &&
          !ConstDC->hasLazyExternalLexicalLookups() &&
          "must call buildLookups first");
@@ -4649,28 +4555,6 @@ void ASTWriter::GenerateNameLookupTable(
   // merged table if there is one.
   auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr;
   Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr);
-
-  const auto &ModuleLocalDecls = Trait.getModuleLocalDecls();
-  if (ModuleLocalDecls.empty())
-    return;
-
-  MultiOnDiskHashTableGenerator<reader::ModuleLocalNameLookupTrait,
-                                ModuleLocalNameLookupTrait>
-      ModuleLocalLookupGenerator;
-  ModuleLocalNameLookupTrait ModuleLocalTrait(*this);
-
-  for (const auto &ModuleLocalIter : ModuleLocalDecls) {
-    const auto &Key = ModuleLocalIter.first;
-    const auto &IDs = ModuleLocalIter.second;
-    ModuleLocalLookupGenerator.insert(Key, ModuleLocalTrait.getData(IDs),
-                                      ModuleLocalTrait);
-  }
-
-  auto *ModuleLocalLookups =
-      Chain ? Chain->getModuleLocalLookupTables(DC) : nullptr;
-  ModuleLocalLookupGenerator.emit(
-      ModuleLocalLookupTable, ModuleLocalTrait,
-      ModuleLocalLookups ? &ModuleLocalLookups->Table : nullptr);
 }
 
 /// Write the block containing all of the declaration IDs
@@ -4678,10 +4562,8 @@ void ASTWriter::GenerateNameLookupTable(
 ///
 /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the
 /// bitstream, or 0 if no block was written.
-void ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
-                                             DeclContext *DC,
-                                             uint64_t &VisibleBlockOffset,
-                                             uint64_t &ModuleLocalBlockOffset) {
+uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
+                                                 DeclContext *DC) {
   // If we imported a key declaration of this namespace, write the visible
   // lookup results as an update record for it rather than including them
   // on this declaration. We will only look at key declarations on reload.
@@ -4691,7 +4573,7 @@ void ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
     for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev;
          Prev = Prev->getPreviousDecl())
       if (!Prev->isFromASTFile())
-        return;
+        return 0;
 
     // Note that we need to emit an update record for the primary context.
     UpdatedDeclContexts.insert(DC->getPrimaryContext());
@@ -4740,53 +4622,41 @@ void ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
       }
     }
 
-    return;
+    return 0;
   }
 
   if (DC->getPrimaryContext() != DC)
-    return;
+    return 0;
 
   // Skip contexts which don't support name lookup.
   if (!DC->isLookupContext())
-    return;
+    return 0;
 
   // If not in C++, we perform name lookup for the translation unit via the
   // IdentifierInfo chains, don't bother to build a visible-declarations table.
   if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus)
-    return;
+    return 0;
 
   // Serialize the contents of the mapping used for lookup. Note that,
   // although we have two very 
diff erent code paths, the serialized
   // representation is the same for both cases: a declaration name,
   // followed by a size, followed by references to the visible
   // declarations that have that name.
+  uint64_t Offset = Stream.GetCurrentBitNo();
   StoredDeclsMap *Map = DC->buildLookup();
   if (!Map || Map->empty())
-    return;
+    return 0;
 
-  VisibleBlockOffset = Stream.GetCurrentBitNo();
   // Create the on-disk hash table in a buffer.
   SmallString<4096> LookupTable;
-  SmallString<4096> ModuleLocalLookupTable;
-  GenerateNameLookupTable(Context, DC, LookupTable, ModuleLocalLookupTable);
+  GenerateNameLookupTable(Context, DC, LookupTable);
 
   // Write the lookup table
   RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE};
   Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record,
                             LookupTable);
   ++NumVisibleDeclContexts;
-
-  if (ModuleLocalLookupTable.empty())
-    return;
-
-  ModuleLocalBlockOffset = Stream.GetCurrentBitNo();
-  assert(ModuleLocalBlockOffset > VisibleBlockOffset);
-  // Write the lookup table
-  RecordData::value_type ModuleLocalRecord[] = {
-      DECL_CONTEXT_MODULE_LOCAL_VISIBLE};
-  Stream.EmitRecordWithBlob(DeclModuleLocalVisibleLookupAbbrev,
-                            ModuleLocalRecord, ModuleLocalLookupTable);
-  ++NumModuleLocalDeclContexts;
+  return Offset;
 }
 
 /// Write an UPDATE_VISIBLE block for the given context.
@@ -4803,8 +4673,7 @@ void ASTWriter::WriteDeclContextVisibleUpdate(ASTContext &Context,
 
   // Create the on-disk hash table in a buffer.
   SmallString<4096> LookupTable;
-  SmallString<4096> ModuleLocalLookupTable;
-  GenerateNameLookupTable(Context, DC, LookupTable, ModuleLocalLookupTable);
+  GenerateNameLookupTable(Context, DC, LookupTable);
 
   // If we're updating a namespace, select a key declaration as the key for the
   // update record; those are the only ones that will be checked on reload.
@@ -4815,15 +4684,6 @@ void ASTWriter::WriteDeclContextVisibleUpdate(ASTContext &Context,
   RecordData::value_type Record[] = {UPDATE_VISIBLE,
                                      getDeclID(cast<Decl>(DC)).getRawValue()};
   Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable);
-
-  if (ModuleLocalLookupTable.empty())
-    return;
-
-  // Write the module local lookup table
-  RecordData::value_type ModuleLocalRecord[] = {
-      UPDATE_MODULE_LOCAL_VISIBLE, getDeclID(cast<Decl>(DC)).getRawValue()};
-  Stream.EmitRecordWithBlob(ModuleLocalUpdateVisibleAbbrev, ModuleLocalRecord,
-                            ModuleLocalLookupTable);
 }
 
 /// Write an FP_PRAGMA_OPTIONS block for the given FPOptions.
@@ -6007,8 +5867,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot,
 
   // Some simple statistics
   RecordData::value_type Record[] = {
-      NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts,
-      NumModuleLocalDeclContexts};
+      NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts};
   Stream.EmitRecord(STATISTICS, Record);
   Stream.ExitBlock();
   Stream.FlushToWord();
@@ -6085,9 +5944,7 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) {
   RecordData DelayedNamespaceRecord;
   for (NamespaceDecl *NS : DelayedNamespace) {
     uint64_t LexicalOffset = WriteDeclContextLexicalBlock(Context, NS);
-    uint64_t VisibleOffset = 0;
-    uint64_t ModuleLocalOffset = 0;
-    WriteDeclContextVisibleBlock(Context, NS, VisibleOffset, ModuleLocalOffset);
+    uint64_t VisibleOffset = WriteDeclContextVisibleBlock(Context, NS);
 
     // Write the offset relative to current block.
     if (LexicalOffset)
@@ -6096,13 +5953,9 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) {
     if (VisibleOffset)
       VisibleOffset -= DeclTypesBlockStartOffset;
 
-    if (ModuleLocalOffset)
-      ModuleLocalOffset -= DeclTypesBlockStartOffset;
-
     AddDeclRef(NS, DelayedNamespaceRecord);
     DelayedNamespaceRecord.push_back(LexicalOffset);
     DelayedNamespaceRecord.push_back(VisibleOffset);
-    DelayedNamespaceRecord.push_back(ModuleLocalOffset);
   }
 
   // The process of writing lexical and visible block for delayed namespace
@@ -6182,12 +6035,6 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) {
   Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
   UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
-  Abv = std::make_shared<llvm::BitCodeAbbrev>();
-  Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_MODULE_LOCAL_VISIBLE));
-  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6));
-  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
-  ModuleLocalUpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv));
-
   // And a visible updates block for the translation unit.
   WriteDeclContextVisibleUpdate(Context, TU);
 

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 7a494cfe1ac64c..3b357f3c50dadb 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2068,7 +2068,6 @@ void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
 
   uint64_t LexicalOffset = 0;
   uint64_t VisibleOffset = 0;
-  uint64_t ModuleLocalOffset = 0;
 
   if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(DC) &&
       cast<NamespaceDecl>(DC)->isFromExplicitGlobalModule()) {
@@ -2079,13 +2078,12 @@ void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
   } else {
     LexicalOffset =
         Writer.WriteDeclContextLexicalBlock(Record.getASTContext(), DC);
-    Writer.WriteDeclContextVisibleBlock(Record.getASTContext(), DC,
-                                        VisibleOffset, ModuleLocalOffset);
+    VisibleOffset =
+        Writer.WriteDeclContextVisibleBlock(Record.getASTContext(), DC);
   }
 
   Record.AddOffset(LexicalOffset);
   Record.AddOffset(VisibleOffset);
-  Record.AddOffset(ModuleLocalOffset);
 }
 
 const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
@@ -2440,7 +2438,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DC
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LexicalOffset
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // VisibleOffset
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // ModuleLocalOffset
   DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
   // Abbreviation for DECL_RECORD
@@ -2493,7 +2490,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DC
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LexicalOffset
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // VisibleOffset
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // ModuleLocalOffset
   DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
   // Abbreviation for DECL_PARM_VAR
@@ -2831,11 +2827,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
   DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
 
-  Abv = std::make_shared<BitCodeAbbrev>();
-  Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_MODULE_LOCAL_VISIBLE));
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
-  DeclModuleLocalVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
-
   Abv = std::make_shared<BitCodeAbbrev>();
   Abv->Add(BitCodeAbbrevOp(serialization::DECL_SPECIALIZATIONS));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));

diff  --git a/clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp b/clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
index 54ec6aa61ec37b..d69db40062dae9 100644
--- a/clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
+++ b/clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
@@ -62,8 +62,8 @@ void test_late() {
 
   not_exported = 1;
 #ifndef IMPLEMENTATION
-  // expected-error at -2 {{use of undeclared identifier 'not_exported'; did you mean 'exported'?}}
-  // expected-note at p2.cpp:18 {{'exported' declared here}}
+  // expected-error at -2 {{declaration of 'not_exported' must be imported from module 'A' before it is required}}
+  // expected-note at p2.cpp:19 {{declaration here is not visible}}
 #endif
 
   internal = 1;

diff  --git a/clang/test/CXX/module/basic/basic.link/p2.cppm b/clang/test/CXX/module/basic/basic.link/p2.cppm
index 5a497304201dce..19761fb3359cec 100644
--- a/clang/test/CXX/module/basic/basic.link/p2.cppm
+++ b/clang/test/CXX/module/basic/basic.link/p2.cppm
@@ -62,11 +62,12 @@ import M;
 
 void use_from_module_impl() {
   external_linkage_fn();
-  module_linkage_fn();   // expected-error {{use of undeclared identifier 'module_linkage_fn'}}
+  module_linkage_fn();   // expected-error {{declaration of 'module_linkage_fn' must be imported}}
   internal_linkage_fn(); // expected-error {{declaration of 'internal_linkage_fn' must be imported}}
   (void)external_linkage_class{};
   (void)module_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}}
   (void)internal_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}}
+  // expected-note at M.cppm:9 {{declaration here is not visible}}
   // expected-note at M.cppm:10 {{declaration here is not visible}}
   (void)external_linkage_var;
   (void)module_linkage_var; // expected-error {{undeclared identifier}}

diff  --git a/clang/test/CXX/module/module.import/p2.cpp b/clang/test/CXX/module/module.import/p2.cpp
index 0ad3bc815beac7..6b8e32f746b628 100644
--- a/clang/test/CXX/module/module.import/p2.cpp
+++ b/clang/test/CXX/module/module.import/p2.cpp
@@ -23,7 +23,10 @@ export A f();
 //--- Use.cpp
 import M;
 void test() {
-  A a; // expected-error {{unknown type name 'A'}}
+  A a; // expected-error {{definition of 'A' must be imported from module 'M' before it is required}}
+       // expected-error at -1 {{definition of 'A' must be imported from module 'M' before it is required}} expected-error at -1 {{}}
+       // expected-note at impl.cppm:2 {{declaration here is not visible}}
+       // expected-note at impl.cppm:2 {{definition here is not reachable}} expected-note at impl.cppm:2 {{}}
 }
 
 //--- UseInPartA.cppm
@@ -37,7 +40,10 @@ void test() {
 export module B;
 import M;
 void test() {
-  A a; // expected-error {{unknown type name 'A'}}
+  A a; // expected-error {{declaration of 'A' must be imported from module 'M'}}
+       // expected-error at -1 {{definition of 'A' must be imported from module 'M'}} expected-error at -1 {{}}
+       // expected-note at impl.cppm:2 {{declaration here is not visible}}
+       // expected-note at impl.cppm:2 {{definition here is not reachable}} expected-note at impl.cppm:2 {{}}
 }
 
 //--- Private.cppm

diff  --git a/clang/test/CXX/module/module.interface/p7.cpp b/clang/test/CXX/module/module.interface/p7.cpp
index cff5df91e43d4d..1572390f0d2899 100644
--- a/clang/test/CXX/module/module.interface/p7.cpp
+++ b/clang/test/CXX/module/module.interface/p7.cpp
@@ -57,10 +57,12 @@ void test() {
 void test2() {
   auto a = E1::e1;               // OK, namespace-scope name E1 is visible and e1 is reachable
   auto b = e1;                   // OK, namespace-scope name e1 is visible
-  auto c = E2::e2;               // expected-error {{use of undeclared identifier 'E2'}}
-  auto d = e2;                   // expected-error {{use of undeclared identifier 'e2'}}
+  auto c = E2::e2;               // expected-error {{declaration of 'E2' must be imported from module}}
+                                 // expected-note@* {{declaration here is not visible}}
+  auto d = e2;                   // should be error, namespace-scope name e2 is not visible
   auto e = E2U::e2;              // OK, namespace-scope name E2U is visible and E2::e2 is reachable
-  auto f = E3::e3;               // expected-error {{use of undeclared identifier 'E3'}}
-  auto g = e3;                   // expected-error {{use of undeclared identifier 'e3'}}
+  auto f = E3::e3;               // expected-error {{declaration of 'E3' must be imported from module 'p7' before it is required}}
+                                 // expected-note@* {{declaration here is not visible}}
+  auto g = e3;                   // should be error, namespace-scope name e3 is not visible
   auto h = decltype(func())::e3; // OK, namespace-scope name f is visible and E3::e3 is reachable
 }

diff  --git a/clang/test/CXX/module/module.reach/p5.cpp b/clang/test/CXX/module/module.reach/p5.cpp
index 947fd082553ec6..9c498a260530f8 100644
--- a/clang/test/CXX/module/module.reach/p5.cpp
+++ b/clang/test/CXX/module/module.reach/p5.cpp
@@ -14,4 +14,5 @@ export using Y = X;
 export module B;
 import A;
 Y y; // OK, definition of X is reachable
-X x; // expected-error {{unknown type name 'X'}}
+X x; // expected-error {{declaration of 'X' must be imported from module 'A' before it is required}}
+     // expected-note@* {{declaration here is not visible}}

diff  --git a/clang/test/Modules/Reachability-template-default-arg.cpp b/clang/test/Modules/Reachability-template-default-arg.cpp
index a7da86b8cc2d51..35c647d0d344ba 100644
--- a/clang/test/Modules/Reachability-template-default-arg.cpp
+++ b/clang/test/Modules/Reachability-template-default-arg.cpp
@@ -21,5 +21,6 @@ struct A {
 import template_default_arg;
 void bar() {
   A<> a0;
-  A<t> a1; // expected-error {{use of undeclared identifier 't'}}
+  A<t> a1; // expected-error {{declaration of 't' must be imported from module 'template_default_arg' before it is required}}
+           // expected-note@* {{declaration here is not visible}}
 }

diff  --git a/clang/test/Modules/cxx20-10-1-ex2.cpp b/clang/test/Modules/cxx20-10-1-ex2.cpp
index 8611d6d64c851f..fc61d89926d448 100644
--- a/clang/test/Modules/cxx20-10-1-ex2.cpp
+++ b/clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -78,7 +78,8 @@ int &c = n; // OK
 //--- std10-1-ex2-tu6.cpp
 import B;
 // error, n is module-local and this is not a module.
-int &c = n; // expected-error {{use of undeclared identifier 'n'}}
+int &c = n; // expected-error {{declaration of 'n' must be imported}}
+            // expected-note@* {{declaration here is not visible}}
 
 //--- std10-1-ex2-tu7.cpp
 // expected-no-diagnostics

diff  --git a/clang/test/Modules/deduction-guide3.cppm b/clang/test/Modules/deduction-guide3.cppm
index f7990004cec7c2..1165dd40bcfb8c 100644
--- a/clang/test/Modules/deduction-guide3.cppm
+++ b/clang/test/Modules/deduction-guide3.cppm
@@ -22,6 +22,8 @@ Templ(T t) -> Templ<T>;
 //--- Use.cpp
 import Templ;
 void func() {
-    Templ t(5); // expected-error {{unknown type name 'Templ'}}
+    Templ t(5); // expected-error {{declaration of 'Templ' must be imported from module 'Templ' before it is required}}
+                // expected-error at -1 {{unknown type name 'Templ'}}
+                // expected-note at Templ.cppm:3 {{declaration here is not visible}}
 }
 

diff  --git a/clang/test/Modules/module-local-with-templates.cppm b/clang/test/Modules/module-local-with-templates.cppm
deleted file mode 100644
index 87955bdd3f99ee..00000000000000
--- a/clang/test/Modules/module-local-with-templates.cppm
+++ /dev/null
@@ -1,79 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-// RUN: split-file %s %t
-//
-// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-//
-// Test again with reduced BMI
-// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-// RUN: %clang_cc1 -std=c++20 %t/a.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-
-
-//--- a.cppm
-export module a;
-
-constexpr int x = 43;
-
-export constexpr int f() { return x; }
-
-export template <typename T>
-constexpr T g() {
-    return x;
-}
-
-namespace nn {
-
-constexpr int x = 88;
-
-export constexpr int f() { return x; }
-
-export template <typename T>
-constexpr T g() {
-    return x;
-}
-}
-
-//--- use.cc
-// expected-no-diagnostics
-import a;
-
-static_assert(f() == 43, "");
-
-constexpr int x = 99;
-
-static_assert(g<int>() == 43, "");
-
-static_assert(x == 99, "");
-
-namespace nn {
-static_assert(f() == 88, "");
-
-constexpr int x = 1000;
-
-static_assert(g<int>() == 88, "");
-
-static_assert(x == 1000, "");
-
-}
-
-//--- a-part.cppm
-module a:impl;
-import a;
-
-static_assert(x == 43, "");
-
-constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
-                        // expected-note@* {{previous definition is here}}
-
-//--- a.cc
-module a;
-
-static_assert(x == 43, "");
-
-constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
-                        // expected-note@* {{previous definition is here}}
-

diff  --git a/clang/test/Modules/pr90154.cppm b/clang/test/Modules/pr90154.cppm
deleted file mode 100644
index d626646fbc4885..00000000000000
--- a/clang/test/Modules/pr90154.cppm
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-// RUN: split-file %s %t
-//
-// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-//
-// Test again with reduced BMI
-// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
-
-//--- a.cppm
-export module a;
-int b = 99;
-namespace a { int a = 43; }
-
-//--- use.cc
-// expected-no-diagnostics
-import a;
-
-namespace a {
-    double a = 43.0;
-}
-
-int b = 883;

diff  --git a/clang/unittests/AST/ExternalASTSourceTest.cpp b/clang/unittests/AST/ExternalASTSourceTest.cpp
index b42a3be05e9bb1..8e1bde1247f660 100644
--- a/clang/unittests/AST/ExternalASTSourceTest.cpp
+++ b/clang/unittests/AST/ExternalASTSourceTest.cpp
@@ -68,8 +68,7 @@ TEST(ExternalASTSourceTest, FailedLookupOccursOnce) {
     TestSource(unsigned &Calls) : Calls(Calls) {}
 
     bool FindExternalVisibleDeclsByName(const DeclContext *,
-                                        DeclarationName Name,
-                                        clang::Module *NamedModule) override {
+                                        DeclarationName Name) override {
       if (Name.getAsString() == "j")
         ++Calls;
       return false;

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
index 7403b79be6cc0f..d5c68a436e0903 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
@@ -71,9 +71,8 @@ class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
   }
 
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
-                                      clang::DeclarationName Name,
-                                      clang::Module *NamedModule) override {
-    return m_Source->FindExternalVisibleDeclsByName(DC, Name, NamedModule);
+                                      clang::DeclarationName Name) override {
+    return m_Source->FindExternalVisibleDeclsByName(DC, Name);
   }
 
   bool LoadExternalSpecializations(const clang::Decl *D,
@@ -389,10 +388,9 @@ class SemaSourceWithPriorities : public clang::ExternalSemaSource {
   }
 
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
-                                      clang::DeclarationName Name,
-                                      clang::Module *NamedModule) override {
+                                      clang::DeclarationName Name) override {
     for (size_t i = 0; i < Sources.size(); ++i)
-      if (Sources[i]->FindExternalVisibleDeclsByName(DC, Name, NamedModule))
+      if (Sources[i]->FindExternalVisibleDeclsByName(DC, Name))
         return true;
     return false;
   }

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 94ce867ef4a0f9..e41efdd3f61c75 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -99,8 +99,7 @@ void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
 
 // The core lookup interface.
 bool ClangASTSource::FindExternalVisibleDeclsByName(
-    const DeclContext *decl_ctx, DeclarationName clang_decl_name,
-    clang::Module *NamedModule) {
+    const DeclContext *decl_ctx, DeclarationName clang_decl_name) {
   if (!m_ast_context) {
     SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
     return false;

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
index 6dc4ecc94e0edc..83c910477acc8d 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -84,8 +84,7 @@ class ClangASTSource : public clang::ExternalASTSource,
   /// \return
   ///     Whatever SetExternalVisibleDeclsForName returns.
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
-                                      clang::DeclarationName Name,
-                                      clang::Module *NamedModule) override;
+                                      clang::DeclarationName Name) override;
 
   /// Enumerate all Decls in a given lexical context.
   ///
@@ -213,9 +212,8 @@ class ClangASTSource : public clang::ExternalASTSource,
     ClangASTSourceProxy(ClangASTSource &original) : m_original(original) {}
 
     bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
-                                        clang::DeclarationName Name,
-                                        clang::Module *NamedModule) override {
-      return m_original.FindExternalVisibleDeclsByName(DC, Name, NamedModule);
+                                        clang::DeclarationName Name) override {
+      return m_original.FindExternalVisibleDeclsByName(DC, Name);
     }
 
     void FindExternalLexicalDecls(

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
index bf4537e69eb636..e746e6afe39bea 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
@@ -50,8 +50,7 @@ void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
 }
 
 bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
-    const clang::DeclContext *DC, clang::DeclarationName Name,
-    clang::Module *NamedModule) {
+    const clang::DeclContext *DC, clang::DeclarationName Name) {
   llvm::SmallVector<clang::NamedDecl *, 4> decls;
   // Objective-C methods are not added into the LookupPtr when they originate
   // from an external source. SetExternalVisibleDeclsForName() adds them.

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
index d2e9c1552fd38c..6bd18186a567d9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
@@ -38,8 +38,7 @@ class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {
       llvm::SmallVectorImpl<clang::Decl *> &Result) override;
 
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
-                                      clang::DeclarationName Name,
-                                      clang::Module *NamedModule) override;
+                                      clang::DeclarationName Name) override;
 
   void CompleteType(clang::TagDecl *tag_decl) override;
 

diff  --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
index 24fc5bb2c047fe..96a259b811b5e7 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -30,8 +30,7 @@ class lldb_private::AppleObjCExternalASTSource
       : m_decl_vendor(decl_vendor) {}
 
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *decl_ctx,
-                                      clang::DeclarationName name,
-                                      clang::Module *NamedModule) override {
+                                      clang::DeclarationName name) override {
 
     Log *log(GetLog(
         LLDBLog::Expressions)); // FIXME - a more appropriate log channel?


        


More information about the lldb-commits mailing list