@@ -1713,13 +1713,24 @@ void NominalTypeDecl::prepareLookupTable() {
1713
1713
}
1714
1714
1715
1715
static TinyPtrVector<ValueDecl *>
1716
- maybeFilterOutAttrImplements (TinyPtrVector<ValueDecl *> decls,
1717
- DeclName name,
1718
- bool includeAttrImplements) {
1719
- if (includeAttrImplements)
1716
+ maybeFilterOutUnwantedDecls (TinyPtrVector<ValueDecl *> decls,
1717
+ DeclName name,
1718
+ bool includeAttrImplements,
1719
+ bool excludeMacroExpansions) {
1720
+ if (includeAttrImplements && !excludeMacroExpansions)
1720
1721
return decls;
1721
1722
TinyPtrVector<ValueDecl*> result;
1722
1723
for (auto V : decls) {
1724
+ // If we're supposed to exclude anything that comes from a macro expansion,
1725
+ // check whether the source location of the declaration is in a macro
1726
+ // expansion, and skip this declaration if it does.
1727
+ if (excludeMacroExpansions) {
1728
+ auto sourceFile =
1729
+ V->getModuleContext ()->getSourceFileContainingLocation (V->getLoc ());
1730
+ if (sourceFile && sourceFile->Kind == SourceFileKind::MacroExpansion)
1731
+ continue ;
1732
+ }
1733
+
1723
1734
// Filter-out any decl that doesn't have the name we're looking for
1724
1735
// (asserting as a consistency-check that such entries all have
1725
1736
// @_implements attrs for the name!)
@@ -1755,12 +1766,16 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1755
1766
decl->hasLazyMembers ());
1756
1767
const bool includeAttrImplements =
1757
1768
flags.contains (NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements);
1769
+ const bool excludeMacroExpansions =
1770
+ flags.contains (NominalTypeDecl::LookupDirectFlags::ExcludeMacroExpansions);
1758
1771
1759
1772
LLVM_DEBUG (llvm::dbgs () << decl->getNameStr () << " .lookupDirect("
1760
1773
<< name << " )"
1761
1774
<< " , hasLazyMembers()=" << decl->hasLazyMembers ()
1762
1775
<< " , useNamedLazyMemberLoading="
1763
1776
<< useNamedLazyMemberLoading
1777
+ << " , excludeMacroExpansions="
1778
+ << excludeMacroExpansions
1764
1779
<< " \n " );
1765
1780
1766
1781
decl->prepareLookupTable ();
@@ -1797,8 +1812,9 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1797
1812
if (!allFound.empty ()) {
1798
1813
auto known = Table.find (name);
1799
1814
if (known != Table.end ()) {
1800
- auto swiftLookupResult = maybeFilterOutAttrImplements (
1801
- known->second , name, includeAttrImplements);
1815
+ auto swiftLookupResult = maybeFilterOutUnwantedDecls (
1816
+ known->second , name, includeAttrImplements,
1817
+ excludeMacroExpansions);
1802
1818
for (auto foundSwiftDecl : swiftLookupResult) {
1803
1819
allFound.push_back (foundSwiftDecl);
1804
1820
}
@@ -1828,7 +1844,8 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1828
1844
}
1829
1845
1830
1846
DeclName macroExpansionKey = adjustLazyMacroExpansionNameKey (ctx, name);
1831
- if (!Table.isLazilyCompleteForMacroExpansion (macroExpansionKey)) {
1847
+ if (!excludeMacroExpansions &&
1848
+ !Table.isLazilyCompleteForMacroExpansion (macroExpansionKey)) {
1832
1849
populateLookupTableEntryFromMacroExpansions (
1833
1850
ctx, Table, macroExpansionKey, decl);
1834
1851
for (auto ext : decl->getExtensions ()) {
@@ -1845,8 +1862,9 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1845
1862
}
1846
1863
1847
1864
// We found something; return it.
1848
- return maybeFilterOutAttrImplements (known->second , name,
1849
- includeAttrImplements);
1865
+ return maybeFilterOutUnwantedDecls (known->second , name,
1866
+ includeAttrImplements,
1867
+ excludeMacroExpansions);
1850
1868
}
1851
1869
1852
1870
bool NominalTypeDecl::createObjCMethodLookup () {
@@ -2201,6 +2219,8 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
2201
2219
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
2202
2220
if (options & NL_IncludeAttributeImplements)
2203
2221
flags |= NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements;
2222
+ if (options & NL_ExcludeMacroExpansions)
2223
+ flags |= NominalTypeDecl::LookupDirectFlags::ExcludeMacroExpansions;
2204
2224
for (auto decl : current->lookupDirect (member.getFullName (), flags)) {
2205
2225
// If we're performing a type lookup, don't even attempt to validate
2206
2226
// the decl if its not a type.
0 commit comments