mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Macros] Ensure that name lookup can find uniquely-generated macro names
While a Swift program cannot directly utter one of the unique names produced by the macro expansion context outside of the macro itself, utilities such as type reconstruction require the ability to look up these names. Note that various kinds of macros can introduce unique names, and update the name lookup facilities for macro-generated names to account for them. Fixes rdar://106053984.
This commit is contained in:
@@ -160,6 +160,7 @@ class swift::SourceLookupCache {
|
||||
ValueDeclMap TopLevelValues;
|
||||
ValueDeclMap ClassMembers;
|
||||
bool MemberCachePopulated = false;
|
||||
DeclName UniqueMacroNamePlaceholder;
|
||||
|
||||
template<typename T>
|
||||
using OperatorMap = llvm::DenseMap<Identifier, TinyPtrVector<T *>>;
|
||||
@@ -179,6 +180,8 @@ class swift::SourceLookupCache {
|
||||
SmallVector<Decl *, 4> MayHaveAuxiliaryDecls;
|
||||
void populateAuxiliaryDeclCache();
|
||||
|
||||
SourceLookupCache(ASTContext &ctx);
|
||||
|
||||
public:
|
||||
SourceLookupCache(const SourceFile &SF);
|
||||
SourceLookupCache(const ModuleDecl &Mod);
|
||||
@@ -392,15 +395,22 @@ void SourceLookupCache::populateAuxiliaryDeclCache() {
|
||||
MayHaveAuxiliaryDecls.clear();
|
||||
}
|
||||
|
||||
SourceLookupCache::SourceLookupCache(ASTContext &ctx)
|
||||
: UniqueMacroNamePlaceholder(MacroDecl::getUniqueNamePlaceholder(ctx)) { }
|
||||
|
||||
/// Populate our cache on the first name lookup.
|
||||
SourceLookupCache::SourceLookupCache(const SourceFile &SF) {
|
||||
SourceLookupCache::SourceLookupCache(const SourceFile &SF)
|
||||
: SourceLookupCache(SF.getASTContext())
|
||||
{
|
||||
FrontendStatsTracer tracer(SF.getASTContext().Stats,
|
||||
"source-file-populate-cache");
|
||||
addToUnqualifiedLookupCache(SF.getTopLevelDecls(), false);
|
||||
addToUnqualifiedLookupCache(SF.getHoistedDecls(), false);
|
||||
}
|
||||
|
||||
SourceLookupCache::SourceLookupCache(const ModuleDecl &M) {
|
||||
SourceLookupCache::SourceLookupCache(const ModuleDecl &M)
|
||||
: SourceLookupCache(M.getASTContext())
|
||||
{
|
||||
FrontendStatsTracer tracer(M.getASTContext().Stats,
|
||||
"module-populate-cache");
|
||||
for (const FileUnit *file : M.getFiles()) {
|
||||
@@ -428,7 +438,10 @@ void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
|
||||
// FIXME: We need to not consider auxiliary decls if we're doing lookup
|
||||
// from inside a macro argument at module scope.
|
||||
populateAuxiliaryDeclCache();
|
||||
auto auxDecls = TopLevelAuxiliaryDecls.find(Name);
|
||||
DeclName keyName = MacroDecl::isUniqueMacroName(Name.getBaseName())
|
||||
? UniqueMacroNamePlaceholder
|
||||
: Name;
|
||||
auto auxDecls = TopLevelAuxiliaryDecls.find(keyName);
|
||||
if (auxDecls == TopLevelAuxiliaryDecls.end())
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user