@@ -90,6 +90,23 @@ template <typename Range> Decl *getElementAt(const Range &Decls, unsigned N) {
90
90
return nullptr ;
91
91
}
92
92
93
+ static ArrayRef<AccessorDecl *>
94
+ getParsedAccessors (AbstractStorageDecl *ASD,
95
+ SmallVectorImpl<AccessorDecl *> &scratch) {
96
+ ASSERT (scratch.empty ());
97
+ ASD->visitParsedAccessors ([&](auto *AD) {
98
+ // Ignore accessors added by macro expansions.
99
+ // TODO: This ought to be the default behavior of `visitParsedAccessors`,
100
+ // we ought to have a different entrypoint for clients that care about
101
+ // the semantic set of "explicit" accessors.
102
+ if (AD->isInMacroExpansionInContext ())
103
+ return ;
104
+
105
+ scratch.push_back (AD);
106
+ });
107
+ return scratch;
108
+ }
109
+
93
110
// / Find the equivalent \c DeclContext with \p DC from \p SF AST.
94
111
// / This assumes the AST which contains \p DC has exact the same structure with
95
112
// / \p SF.
@@ -117,7 +134,10 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
117
134
auto *storage = accessor->getStorage ();
118
135
if (!storage)
119
136
return nullptr ;
120
- auto accessorN = findIndexInRange (accessor, storage->getAllAccessors ());
137
+
138
+ SmallVector<AccessorDecl *, 4 > scratch;
139
+ auto accessorN =
140
+ findIndexInRange (accessor, getParsedAccessors (storage, scratch));
121
141
if (!accessorN)
122
142
return nullptr ;
123
143
IndexStack.push_back (*accessorN);
@@ -128,7 +148,7 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
128
148
N = findIndexInRange (D, parentSF->getTopLevelDecls ());
129
149
} else if (auto parentIDC = dyn_cast_or_null<IterableDeclContext>(
130
150
parentDC->getAsDecl ())) {
131
- N = findIndexInRange (D, parentIDC->getMembers ());
151
+ N = findIndexInRange (D, parentIDC->getParsedMembers ());
132
152
} else {
133
153
#ifndef NDEBUG
134
154
llvm_unreachable (" invalid DC kind for finding equivalent DC (indexpath)" );
@@ -155,15 +175,16 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
155
175
if (auto parentSF = dyn_cast<SourceFile>(newDC))
156
176
D = getElementAt (parentSF->getTopLevelDecls (), N);
157
177
else if (auto parentIDC = dyn_cast<IterableDeclContext>(newDC->getAsDecl ()))
158
- D = getElementAt (parentIDC->getMembers (), N);
178
+ D = getElementAt (parentIDC->getParsedMembers (), N);
159
179
else
160
180
llvm_unreachable (" invalid DC kind for finding equivalent DC (query)" );
161
181
162
182
if (auto storage = dyn_cast_or_null<AbstractStorageDecl>(D)) {
163
183
if (IndexStack.empty ())
164
184
return nullptr ;
165
185
auto accessorN = IndexStack.pop_back_val ();
166
- D = getElementAt (storage->getAllAccessors (), accessorN);
186
+ SmallVector<AccessorDecl *, 4 > scratch;
187
+ D = getElementAt (getParsedAccessors (storage, scratch), accessorN);
167
188
}
168
189
169
190
newDC = dyn_cast_or_null<DeclContext>(D);
@@ -358,7 +379,7 @@ bool IDEInspectionInstance::performCachedOperationIfPossible(
358
379
nullptr
359
380
}
360
381
);
361
- SM.recordSourceFile (newBufferID, AFD-> getParentSourceFile () );
382
+ SM.recordSourceFile (newBufferID, oldSF );
362
383
363
384
AFD->setBodyToBeReparsed (newBodyRange);
364
385
oldSF->clearScope ();
0 commit comments