Skip to content

Commit 731db2a

Browse files
committed
Revert "[C++20] [Modules] Support module level lookup (#122887)"
This reverts commit 7201cae.
1 parent 29e6332 commit 731db2a

35 files changed

+197
-736
lines changed

clang/docs/ReleaseNotes.rst

-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ C++23 Feature Support
316316
C++20 Feature Support
317317
^^^^^^^^^^^^^^^^^^^^^
318318

319-
- Implemented module level lookup for C++20 modules. (#GH90154)
320-
321319

322320
Resolutions to C++ Defect Reports
323321
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/DeclBase.h

-10
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,6 @@ class alignas(8) Decl {
836836
return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();
837837
}
838838

839-
/// Get the top level owning named module that owns this declaration if any.
840-
/// \returns nullptr if the declaration is not owned by a named module.
841-
Module *getTopLevelOwningNamedModule() const;
842-
843839
/// Get the module that owns this declaration for linkage purposes.
844840
/// There only ever is such a standard C++ module.
845841
Module *getOwningModuleForLinkage() const;
@@ -2726,12 +2722,6 @@ class DeclContext {
27262722
bool Deserialize = false) const;
27272723

27282724
private:
2729-
/// Lookup all external visible declarations and the external declarations
2730-
/// within the same module specified by \c NamedModule. We can't
2731-
/// get it from \c this since the same declaration may be declared in
2732-
/// multiple modules. e.g., namespace.
2733-
lookup_result lookupImpl(DeclarationName Name, Module *NamedModule) const;
2734-
27352725
/// Whether this declaration context has had externally visible
27362726
/// storage added since the last lookup. In this case, \c LookupPtr's
27372727
/// invariant may not hold and needs to be fixed before we perform

clang/include/clang/AST/ExternalASTMerger.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class ExternalASTMerger : public ExternalASTSource {
141141

142142
/// Implementation of the ExternalASTSource API.
143143
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
144-
DeclarationName Name,
145-
Module *NamedModule) override;
144+
DeclarationName Name) override;
146145

147146
/// Implementation of the ExternalASTSource API.
148147
void

clang/include/clang/AST/ExternalASTSource.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class RecordDecl;
5151
class Selector;
5252
class Stmt;
5353
class TagDecl;
54-
class Module;
5554

5655
/// Abstract interface for external sources of AST nodes.
5756
///
@@ -146,20 +145,12 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
146145
/// Find all declarations with the given name in the given context,
147146
/// and add them to the context by calling SetExternalVisibleDeclsForName
148147
/// or SetNoExternalVisibleDeclsForName.
149-
/// \param DC the context for lookup.
150-
/// \param Name the name of the declarations to find.
151-
/// \param NamedModule find declarations visible to the given module
152-
/// \c NamedModule . This may be different from owning module of \c DC since
153-
/// there are declarations (e.g., namespace declaration) can appear in
154-
/// multiple modules.
155-
///
156-
/// \return \c true if any declarations might have been found, and \c false
157-
/// if we definitely have no declarations with this name.
148+
/// \return \c true if any declarations might have been found, \c false if
149+
/// we definitely have no declarations with tbis name.
158150
///
159151
/// The default implementation of this method is a no-op returning \c false.
160-
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC,
161-
DeclarationName Name,
162-
Module *NamedModule);
152+
virtual bool
153+
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
163154

164155
/// Load all the external specializations for the Decl \param D if \param
165156
/// OnlyPartial is false. Otherwise, load all the external **partial**

clang/include/clang/Sema/MultiplexExternalSemaSource.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
9595
/// Find all declarations with the given name in the
9696
/// given context.
9797
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
98-
DeclarationName Name,
99-
Module *NamedModule) override;
98+
DeclarationName Name) override;
10099

101100
bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
102101

clang/include/clang/Serialization/ASTBitCodes.h

-6
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ enum ASTRecordTypes {
738738
CXX_ADDED_TEMPLATE_SPECIALIZATION = 74,
739739

740740
CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION = 75,
741-
742-
UPDATE_MODULE_LOCAL_VISIBLE = 76,
743741
};
744742

745743
/// Record types used within a source manager block.
@@ -1336,10 +1334,6 @@ enum DeclCode {
13361334
/// into a DeclContext via DeclContext::lookup.
13371335
DECL_CONTEXT_VISIBLE,
13381336

1339-
/// A record containing the set of declarations that are
1340-
/// only visible from DeclContext in the same module.
1341-
DECL_CONTEXT_MODULE_LOCAL_VISIBLE,
1342-
13431337
/// A LabelDecl record.
13441338
DECL_LABEL,
13451339

clang/include/clang/Serialization/ASTReader.h

+4-28
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ class ASTIdentifierLookupTrait;
353353

354354
/// The on-disk hash table(s) used for DeclContext name lookup.
355355
struct DeclContextLookupTable;
356-
struct ModuleLocalLookupTable;
357356

358357
/// The on-disk hash table(s) used for specialization decls.
359358
struct LazySpecializationInfoLookupTable;
@@ -524,14 +523,9 @@ class ASTReader
524523
/// in the chain.
525524
DeclUpdateOffsetsMap DeclUpdateOffsets;
526525

527-
struct LookupBlockOffsets {
528-
uint64_t LexicalOffset;
529-
uint64_t VisibleOffset;
530-
uint64_t ModuleLocalOffset;
531-
};
532-
533526
using DelayedNamespaceOffsetMapTy =
534-
llvm::DenseMap<GlobalDeclID, LookupBlockOffsets>;
527+
llvm::DenseMap<GlobalDeclID, std::pair</*LexicalOffset*/ uint64_t,
528+
/*VisibleOffset*/ uint64_t>>;
535529

536530
/// Mapping from global declaration IDs to the lexical and visible block
537531
/// offset for delayed namespace in reduced BMI.
@@ -637,9 +631,6 @@ class ASTReader
637631
/// Map from a DeclContext to its lookup tables.
638632
llvm::DenseMap<const DeclContext *,
639633
serialization::reader::DeclContextLookupTable> Lookups;
640-
llvm::DenseMap<const DeclContext *,
641-
serialization::reader::ModuleLocalLookupTable>
642-
ModuleLocalLookups;
643634

644635
using SpecLookupTableTy =
645636
llvm::DenseMap<const Decl *,
@@ -668,8 +659,6 @@ class ASTReader
668659
/// Updates to the visible declarations of declaration contexts that
669660
/// haven't been loaded yet.
670661
llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> PendingVisibleUpdates;
671-
llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates>
672-
PendingModuleLocalVisibleUpdates;
673662

674663
using SpecializationsUpdate = SmallVector<UpdateData, 1>;
675664
using SpecializationsUpdateMap =
@@ -707,8 +696,7 @@ class ASTReader
707696
/// Read the record that describes the visible contents of a DC.
708697
bool ReadVisibleDeclContextStorage(ModuleFile &M,
709698
llvm::BitstreamCursor &Cursor,
710-
uint64_t Offset, GlobalDeclID ID,
711-
bool IsModuleLocal);
699+
uint64_t Offset, GlobalDeclID ID);
712700

713701
bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
714702
uint64_t Offset, Decl *D, bool IsPartial);
@@ -1144,10 +1132,6 @@ class ASTReader
11441132
/// Number of visible decl contexts read/total.
11451133
unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
11461134

1147-
/// Number of module local visible decl contexts read/total.
1148-
unsigned NumModuleLocalVisibleDeclContexts = 0,
1149-
TotalModuleLocalVisibleDeclContexts = 0;
1150-
11511135
/// Total size of modules, in bits, currently loaded
11521136
uint64_t TotalModulesSizeInBits = 0;
11531137

@@ -1460,9 +1444,6 @@ class ASTReader
14601444
const serialization::reader::DeclContextLookupTable *
14611445
getLoadedLookupTables(DeclContext *Primary) const;
14621446

1463-
const serialization::reader::ModuleLocalLookupTable *
1464-
getModuleLocalLookupTables(DeclContext *Primary) const;
1465-
14661447
/// Get the loaded specializations lookup tables for \p D,
14671448
/// if any.
14681449
serialization::reader::LazySpecializationInfoLookupTable *
@@ -2138,8 +2119,7 @@ class ASTReader
21382119
/// The current implementation of this method just loads the entire
21392120
/// lookup table as unmaterialized references.
21402121
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
2141-
DeclarationName Name,
2142-
Module *NamedModule) override;
2122+
DeclarationName Name) override;
21432123

21442124
/// Read all of the declarations lexically stored in a
21452125
/// declaration context.
@@ -2627,10 +2607,6 @@ inline bool shouldSkipCheckingODR(const Decl *D) {
26272607
(D->isFromGlobalModule() || D->isFromHeaderUnit());
26282608
}
26292609

2630-
/// Calculate a hash value for the primary module name of the given module.
2631-
/// \returns std::nullopt if M is not a C++ standard module.
2632-
std::optional<unsigned> getPrimaryModuleHash(const Module *M);
2633-
26342610
} // namespace clang
26352611

26362612
#endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H

clang/include/clang/Serialization/ASTWriter.h

+3-13
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,6 @@ class ASTWriter : public ASTDeserializationListener,
492492
/// file.
493493
unsigned NumVisibleDeclContexts = 0;
494494

495-
/// The number of module local visible declcontexts written to the AST
496-
/// file.
497-
unsigned NumModuleLocalDeclContexts = 0;
498-
499495
/// A mapping from each known submodule to its ID number, which will
500496
/// be a positive integer.
501497
llvm::DenseMap<const Module *, unsigned> SubmoduleIDs;
@@ -591,15 +587,11 @@ class ASTWriter : public ASTDeserializationListener,
591587
uint64_t WriteSpecializationInfoLookupTable(
592588
const NamedDecl *D, llvm::SmallVectorImpl<const Decl *> &Specializations,
593589
bool IsPartial);
594-
void
595-
GenerateNameLookupTable(ASTContext &Context, const DeclContext *DC,
596-
llvm::SmallVectorImpl<char> &LookupTable,
597-
llvm::SmallVectorImpl<char> &ModuleLocalLookupTable);
590+
void GenerateNameLookupTable(ASTContext &Context, const DeclContext *DC,
591+
llvm::SmallVectorImpl<char> &LookupTable);
598592
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
599593
const DeclContext *DC);
600-
void WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC,
601-
uint64_t &VisibleBlockOffset,
602-
uint64_t &ModuleLocalBlockOffset);
594+
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
603595
void WriteTypeDeclOffsets();
604596
void WriteFileDeclIDsMap();
605597
void WriteComments(ASTContext &Context);
@@ -632,9 +624,7 @@ class ASTWriter : public ASTDeserializationListener,
632624
unsigned DeclParmVarAbbrev = 0;
633625
unsigned DeclContextLexicalAbbrev = 0;
634626
unsigned DeclContextVisibleLookupAbbrev = 0;
635-
unsigned DeclModuleLocalVisibleLookupAbbrev = 0;
636627
unsigned UpdateVisibleAbbrev = 0;
637-
unsigned ModuleLocalUpdateVisibleAbbrev = 0;
638628
unsigned DeclRecordAbbrev = 0;
639629
unsigned DeclTypedefAbbrev = 0;
640630
unsigned DeclVarAbbrev = 0;

clang/lib/AST/DeclBase.cpp

+4-19
Original file line numberDiff line numberDiff line change
@@ -1850,28 +1850,15 @@ void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
18501850
}
18511851
}
18521852

1853-
Module *Decl::getTopLevelOwningNamedModule() const {
1854-
if (getOwningModule() &&
1855-
getOwningModule()->getTopLevelModule()->isNamedModule())
1856-
return getOwningModule()->getTopLevelModule();
1857-
1858-
return nullptr;
1859-
}
1860-
18611853
DeclContext::lookup_result
18621854
DeclContext::lookup(DeclarationName Name) const {
1863-
return lookupImpl(Name, cast<Decl>(this)->getTopLevelOwningNamedModule());
1864-
}
1865-
1866-
DeclContext::lookup_result DeclContext::lookupImpl(DeclarationName Name,
1867-
Module *NamedModule) const {
18681855
// For transparent DeclContext, we should lookup in their enclosing context.
18691856
if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
1870-
return getParent()->lookupImpl(Name, NamedModule);
1857+
return getParent()->lookup(Name);
18711858

18721859
const DeclContext *PrimaryContext = getPrimaryContext();
18731860
if (PrimaryContext != this)
1874-
return PrimaryContext->lookupImpl(Name, NamedModule);
1861+
return PrimaryContext->lookup(Name);
18751862

18761863
// If we have an external source, ensure that any later redeclarations of this
18771864
// 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,
19021889
if (!R.second && !R.first->second.hasExternalDecls())
19031890
return R.first->second.getLookupResult();
19041891

1905-
if (Source->FindExternalVisibleDeclsByName(this, Name, NamedModule) ||
1906-
!R.second) {
1892+
if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
19071893
if (StoredDeclsMap *Map = LookupPtr) {
19081894
StoredDeclsMap::iterator I = Map->find(Name);
19091895
if (I != Map->end())
@@ -2129,8 +2115,7 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
21292115
if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
21302116
if (hasExternalVisibleStorage() &&
21312117
Map->find(D->getDeclName()) == Map->end())
2132-
Source->FindExternalVisibleDeclsByName(
2133-
this, D->getDeclName(), D->getTopLevelOwningNamedModule());
2118+
Source->FindExternalVisibleDeclsByName(this, D->getDeclName());
21342119

21352120
// Insert this declaration into the map.
21362121
StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];

clang/lib/AST/ExternalASTMerger.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ static bool importSpecializationsIfNeeded(Decl *D, ASTImporter *Importer) {
472472
}
473473

474474
bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC,
475-
DeclarationName Name,
476-
Module *NamedModule) {
475+
DeclarationName Name) {
477476
llvm::SmallVector<NamedDecl *, 1> Decls;
478477
llvm::SmallVector<Candidate, 4> Candidates;
479478

clang/lib/AST/ExternalASTSource.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
9090
return nullptr;
9191
}
9292

93-
bool ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
94-
DeclarationName Name,
95-
Module *NamedModule) {
93+
bool
94+
ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
95+
DeclarationName Name) {
9696
return false;
9797
}
9898

clang/lib/Interpreter/CodeCompletion.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ class ExternalSource : public clang::ExternalASTSource {
228228
ExternalSource(ASTContext &ChildASTCtxt, FileManager &ChildFM,
229229
ASTContext &ParentASTCtxt, FileManager &ParentFM);
230230
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
231-
DeclarationName Name,
232-
Module *NamedModule) override;
231+
DeclarationName Name) override;
233232
void
234233
completeVisibleDeclsMap(const clang::DeclContext *childDeclContext) override;
235234
};
@@ -272,8 +271,7 @@ ExternalSource::ExternalSource(ASTContext &ChildASTCtxt, FileManager &ChildFM,
272271
}
273272

274273
bool ExternalSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
275-
DeclarationName Name,
276-
Module *NamedModule) {
274+
DeclarationName Name) {
277275

278276
IdentifierTable &ParentIdTable = ParentASTCtxt.Idents;
279277

clang/lib/Sema/MultiplexExternalSemaSource.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) {
107107
return EK_ReplyHazy;
108108
}
109109

110-
bool MultiplexExternalSemaSource::FindExternalVisibleDeclsByName(
111-
const DeclContext *DC, DeclarationName Name, Module *NamedModule) {
110+
bool MultiplexExternalSemaSource::
111+
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
112112
bool AnyDeclsFound = false;
113113
for (size_t i = 0; i < Sources.size(); ++i)
114-
AnyDeclsFound |=
115-
Sources[i]->FindExternalVisibleDeclsByName(DC, Name, NamedModule);
114+
AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
116115
return AnyDeclsFound;
117116
}
118117

0 commit comments

Comments
 (0)