Skip to content

Commit 6ac69d8

Browse files
committed
Remove findMacroForCustomAttr in favor of namelookup::lookupMacros
The former was effectively a copy of the latter.
1 parent f0f74e6 commit 6ac69d8

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

include/swift/AST/MacroDeclaration.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ StringRef getMacroIntroducedDeclNameString(
116116

117117
class CustomAttr;
118118

119-
/// Perform lookup to determine whether the given custom attribute refers to
120-
/// a macro declaration, and populate the \c macros vector with the lookup
121-
/// results that are attached macros.
122-
void findMacroForCustomAttr(CustomAttr *attr, DeclContext *dc,
123-
llvm::TinyPtrVector<ValueDecl *> &macros);
124-
125119
class MacroIntroducedDeclName {
126120
public:
127121
using Kind = MacroIntroducedDeclNameKind;

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,40 +3474,19 @@ GenericParamListRequest::evaluate(Evaluator &evaluator, GenericContext *value) c
34743474
parsedGenericParams->getRAngleLoc());
34753475
}
34763476

3477-
void swift::findMacroForCustomAttr(CustomAttr *attr, DeclContext *dc,
3478-
llvm::TinyPtrVector<ValueDecl *> &macros) {
3479-
auto *identTypeRepr = dyn_cast_or_null<IdentTypeRepr>(attr->getTypeRepr());
3480-
if (!identTypeRepr)
3481-
return;
3482-
3483-
// Look for macros at module scope. They can only occur at module scope, and
3484-
// we need to be sure not to trigger name lookup into type contexts along
3485-
// the way.
3486-
auto moduleScopeDC = dc->getModuleScopeContext();
3487-
ASTContext &ctx = moduleScopeDC->getASTContext();
3488-
UnqualifiedLookupDescriptor descriptor(
3489-
identTypeRepr->getNameRef(), moduleScopeDC
3490-
);
3491-
auto lookup = evaluateOrDefault(
3492-
ctx.evaluator, UnqualifiedLookupRequest{descriptor}, {});
3493-
for (const auto &result : lookup.allResults()) {
3494-
// Only keep attached macros, which can be spelled as custom attributes.
3495-
if (auto macro = dyn_cast<MacroDecl>(result.getValueDecl()))
3496-
if (isAttachedMacro(macro->getMacroRoles()))
3497-
macros.push_back(macro);
3498-
}
3499-
}
3500-
35013477
NominalTypeDecl *
35023478
CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
35033479
CustomAttr *attr, DeclContext *dc) const {
35043480
// Look for names at module scope, so we don't trigger name lookup for
35053481
// nested scopes. At this point, we're looking to see whether there are
35063482
// any suitable macros.
3507-
llvm::TinyPtrVector<ValueDecl *> macros;
3508-
findMacroForCustomAttr(attr, dc, macros);
3509-
if (!macros.empty())
3510-
return nullptr;
3483+
if (auto *identTypeRepr =
3484+
dyn_cast_or_null<IdentTypeRepr>(attr->getTypeRepr())) {
3485+
auto macros = namelookup::lookupMacros(
3486+
dc, identTypeRepr->getNameRef(), getAttachedMacroRoles());
3487+
if (!macros.empty())
3488+
return nullptr;
3489+
}
35113490

35123491
// Find the types referenced by the custom attribute.
35133492
auto &ctx = dc->getASTContext();

0 commit comments

Comments
 (0)