Skip to content

Commit 0466387

Browse files
committed
AST: Add excludeMacroExpansions parameter to computeExtendedNominal()
1 parent 15f968f commit 0466387

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,8 @@ class ExtensionDecl final : public GenericContext, public Decl,
20642064
NominalTypeDecl *getExtendedNominal() const;
20652065

20662066
/// Compute the nominal type declaration that is being extended.
2067-
NominalTypeDecl *computeExtendedNominal() const;
2067+
NominalTypeDecl *computeExtendedNominal(
2068+
bool excludeMacroExpansions=false) const;
20682069

20692070
/// \c hasBeenBound means nothing if this extension can never been bound
20702071
/// because it is not at the top level.

include/swift/AST/NameLookupRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class HasMissingDesignatedInitializersRequest :
267267
/// Request the nominal declaration extended by a given extension declaration.
268268
class ExtendedNominalRequest
269269
: public SimpleRequest<
270-
ExtendedNominalRequest, NominalTypeDecl *(ExtensionDecl *),
270+
ExtendedNominalRequest, NominalTypeDecl *(ExtensionDecl *, bool),
271271
RequestFlags::SeparatelyCached | RequestFlags::DependencySink> {
272272
public:
273273
using SimpleRequest::SimpleRequest;
@@ -276,8 +276,8 @@ class ExtendedNominalRequest
276276
friend SimpleRequest;
277277

278278
// Evaluation.
279-
NominalTypeDecl *
280-
evaluate(Evaluator &evaluator, ExtensionDecl *ext) const;
279+
NominalTypeDecl * evaluate(Evaluator &evaluator, ExtensionDecl *ext,
280+
bool excludeMacroExpansions) const;
281281

282282
public:
283283
// Separate caching.

lib/AST/Decl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,11 +2075,14 @@ NominalTypeDecl *ExtensionDecl::getExtendedNominal() const {
20752075
"Extension must have already been bound (by bindExtensions)");
20762076
}
20772077

2078-
NominalTypeDecl *ExtensionDecl::computeExtendedNominal() const {
2078+
NominalTypeDecl *ExtensionDecl::computeExtendedNominal(
2079+
bool excludeMacroExpansions) const {
20792080
ASTContext &ctx = getASTContext();
2080-
return evaluateOrDefault(
2081-
ctx.evaluator, ExtendedNominalRequest{const_cast<ExtensionDecl *>(this)},
2082-
nullptr);
2081+
return evaluateOrDefault(ctx.evaluator,
2082+
ExtendedNominalRequest{
2083+
const_cast<ExtensionDecl *>(this),
2084+
excludeMacroExpansions},
2085+
nullptr);
20832086
}
20842087

20852088
bool ExtensionDecl::canNeverBeBound() const {

lib/AST/NameLookup.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,9 @@ enum class DirectlyReferencedTypeLookupFlags {
11251125
/// Include members that would normally be excluded because they come from
11261126
/// modules that have not been imported directly.
11271127
IgnoreMissingImports = 1 << 3,
1128+
1129+
/// Whenther we should exclude macro expansions.
1130+
ExcludeMacroExpansions = 1 << 4,
11281131
};
11291132

11301133
using DirectlyReferencedTypeLookupOptions =
@@ -3065,6 +3068,10 @@ static DirectlyReferencedTypeDecls directReferencesForUnqualifiedTypeLookup(
30653068
DirectlyReferencedTypeLookupFlags::IgnoreMissingImports))
30663069
options |= UnqualifiedLookupFlags::IgnoreMissingImports;
30673070

3071+
if (typeLookupOptions.contains(
3072+
DirectlyReferencedTypeLookupFlags::ExcludeMacroExpansions))
3073+
options |= UnqualifiedLookupFlags::ExcludeMacroExpansions;
3074+
30683075
// Manually exclude macro expansions here since the source location
30693076
// is overridden below.
30703077
if (namelookup::isInMacroArgument(dc->getParentSourceFile(), loc))
@@ -3147,6 +3154,10 @@ static llvm::TinyPtrVector<TypeDecl *> directReferencesForQualifiedTypeLookup(
31473154
DirectlyReferencedTypeLookupFlags::IgnoreMissingImports))
31483155
options |= NL_IgnoreMissingImports;
31493156

3157+
if (typeLookupOptions.contains(
3158+
DirectlyReferencedTypeLookupFlags::ExcludeMacroExpansions))
3159+
options |= NL_ExcludeMacroExpansions;
3160+
31503161
// Look through the type declarations we were given, resolving them down
31513162
// to nominal type declarations, module declarations, and
31523163
SmallVector<ModuleDecl *, 2> moduleDecls;
@@ -3574,7 +3585,8 @@ ProtocolRequirementsRequest::evaluate(Evaluator &evaluator,
35743585

35753586
NominalTypeDecl *
35763587
ExtendedNominalRequest::evaluate(Evaluator &evaluator,
3577-
ExtensionDecl *ext) const {
3588+
ExtensionDecl *ext,
3589+
bool excludeMacroExpansions) const {
35783590
auto typeRepr = ext->getExtendedTypeRepr();
35793591
if (!typeRepr) {
35803592
// We must've seen 'extension { ... }' during parsing.
@@ -3583,9 +3595,15 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
35833595

35843596
ASTContext &ctx = ext->getASTContext();
35853597
auto options = defaultDirectlyReferencedTypeLookupOptions;
3598+
35863599
if (ext->isInSpecializeExtensionContext()) {
35873600
options |= DirectlyReferencedTypeLookupFlags::AllowUsableFromInline;
35883601
}
3602+
3603+
if (excludeMacroExpansions) {
3604+
options |= DirectlyReferencedTypeLookupFlags::ExcludeMacroExpansions;
3605+
}
3606+
35893607
DirectlyReferencedTypeDecls referenced = directReferencesForTypeRepr(
35903608
evaluator, ctx, typeRepr, ext->getParent(), options);
35913609

0 commit comments

Comments
 (0)