@@ -160,6 +160,7 @@ class swift::SourceLookupCache {
160160 ValueDeclMap TopLevelValues;
161161 ValueDeclMap ClassMembers;
162162 bool MemberCachePopulated = false ;
163+ DeclName UniqueMacroNamePlaceholder;
163164
164165 template <typename T>
165166 using OperatorMap = llvm::DenseMap<Identifier, TinyPtrVector<T *>>;
@@ -179,6 +180,8 @@ class swift::SourceLookupCache {
179180 SmallVector<Decl *, 4 > MayHaveAuxiliaryDecls;
180181 void populateAuxiliaryDeclCache ();
181182
183+ SourceLookupCache (ASTContext &ctx);
184+
182185public:
183186 SourceLookupCache (const SourceFile &SF);
184187 SourceLookupCache (const ModuleDecl &Mod);
@@ -392,15 +395,22 @@ void SourceLookupCache::populateAuxiliaryDeclCache() {
392395 MayHaveAuxiliaryDecls.clear ();
393396}
394397
398+ SourceLookupCache::SourceLookupCache (ASTContext &ctx)
399+ : UniqueMacroNamePlaceholder(MacroDecl::getUniqueNamePlaceholder(ctx)) { }
400+
395401// / Populate our cache on the first name lookup.
396- SourceLookupCache::SourceLookupCache (const SourceFile &SF) {
402+ SourceLookupCache::SourceLookupCache (const SourceFile &SF)
403+ : SourceLookupCache(SF.getASTContext())
404+ {
397405 FrontendStatsTracer tracer (SF.getASTContext ().Stats ,
398406 " source-file-populate-cache" );
399407 addToUnqualifiedLookupCache (SF.getTopLevelDecls (), false );
400408 addToUnqualifiedLookupCache (SF.getHoistedDecls (), false );
401409}
402410
403- SourceLookupCache::SourceLookupCache (const ModuleDecl &M) {
411+ SourceLookupCache::SourceLookupCache (const ModuleDecl &M)
412+ : SourceLookupCache(M.getASTContext())
413+ {
404414 FrontendStatsTracer tracer (M.getASTContext ().Stats ,
405415 " module-populate-cache" );
406416 for (const FileUnit *file : M.getFiles ()) {
@@ -428,7 +438,10 @@ void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
428438 // FIXME: We need to not consider auxiliary decls if we're doing lookup
429439 // from inside a macro argument at module scope.
430440 populateAuxiliaryDeclCache ();
431- auto auxDecls = TopLevelAuxiliaryDecls.find (Name);
441+ DeclName keyName = MacroDecl::isUniqueMacroName (Name.getBaseName ())
442+ ? UniqueMacroNamePlaceholder
443+ : Name;
444+ auto auxDecls = TopLevelAuxiliaryDecls.find (keyName);
432445 if (auxDecls == TopLevelAuxiliaryDecls.end ())
433446 return ;
434447
0 commit comments