Skip to content

Commit 58b85c5

Browse files
committed
[CodeCompletion][NFC] Collect possible callees instead of params
in context type analysis. Still NFC, but this is needed by later commits. (cherry picked from commit 8a6c540)
1 parent bfa5ea2 commit 58b85c5

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,11 +5093,11 @@ namespace {
50935093
} // end anonymous namespace
50945094

50955095
namespace {
5096-
using FunctionParams = ArrayRef<AnyFunctionType::Param>;
5096+
using FunctionTypeAndDecl = std::pair<AnyFunctionType *, ValueDecl *>;
50975097

5098-
void collectPossibleParamListByQualifiedLookup(
5098+
void collectPossibleCalleesByQualifiedLookup(
50995099
DeclContext &DC, Type baseTy, DeclBaseName name,
5100-
SmallVectorImpl<FunctionParams> &candidates) {
5100+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
51015101

51025102
SmallVector<ValueDecl *, 2> decls;
51035103
auto resolver = DC.getASTContext().getLazyResolver();
@@ -5122,14 +5122,14 @@ void collectPossibleParamListByQualifiedLookup(
51225122
if (!fnType || fnType->hasError())
51235123
continue;
51245124
if (auto *AFT = fnType->getAs<AnyFunctionType>()) {
5125-
candidates.push_back(AFT->getParams());
5125+
candidates.emplace_back(AFT, VD);
51265126
}
51275127
}
51285128
}
51295129

5130-
void collectPossibleParamListByQualifiedLookup(
5130+
void collectPossibleCalleesByQualifiedLookup(
51315131
DeclContext &DC, Expr *baseExpr, DeclBaseName name,
5132-
SmallVectorImpl<FunctionParams> &candidates) {
5132+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
51335133
ConcreteDeclRef ref = nullptr;
51345134
auto baseTyOpt = getTypeOfCompletionContextExpr(
51355135
DC.getASTContext(), &DC, CompletionTypeCheckKind::Normal, baseExpr, ref);
@@ -5139,31 +5139,31 @@ void collectPossibleParamListByQualifiedLookup(
51395139
if (!baseTy->mayHaveMembers())
51405140
return;
51415141

5142-
collectPossibleParamListByQualifiedLookup(DC, baseTy, name, candidates);
5142+
collectPossibleCalleesByQualifiedLookup(DC, baseTy, name, candidates);
51435143
}
51445144

5145-
bool collectPossibleParamListsApply(
5145+
bool collectPossibleCalleesForApply(
51465146
DeclContext &DC, ApplyExpr *callExpr,
5147-
SmallVectorImpl<FunctionParams> &candidates) {
5147+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
51485148
auto *fnExpr = callExpr->getFn();
51495149

51505150
if (auto type = fnExpr->getType()) {
51515151
if (auto *funcType = type->getAs<AnyFunctionType>())
5152-
candidates.push_back(funcType->getParams());
5152+
candidates.emplace_back(funcType, fnExpr->getReferencedDecl().getDecl());
51535153
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
51545154
if (auto *decl = DRE->getDecl()) {
51555155
auto declType = decl->getInterfaceType();
51565156
if (auto *funcType = declType->getAs<AnyFunctionType>())
5157-
candidates.push_back(funcType->getParams());
5157+
candidates.emplace_back(funcType, decl);
51585158
}
51595159
} else if (auto *OSRE = dyn_cast<OverloadSetRefExpr>(fnExpr)) {
51605160
for (auto *decl : OSRE->getDecls()) {
51615161
auto declType = decl->getInterfaceType();
51625162
if (auto *funcType = declType->getAs<AnyFunctionType>())
5163-
candidates.push_back(funcType->getParams());
5163+
candidates.emplace_back(funcType, decl);
51645164
}
51655165
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
5166-
collectPossibleParamListByQualifiedLookup(
5166+
collectPossibleCalleesByQualifiedLookup(
51675167
DC, UDE->getBase(), UDE->getName().getBaseName(), candidates);
51685168
}
51695169

@@ -5175,31 +5175,31 @@ bool collectPossibleParamListsApply(
51755175
return false;
51765176

51775177
if (auto *AFT = (*fnType)->getAs<AnyFunctionType>()) {
5178-
candidates.push_back(AFT->getParams());
5178+
candidates.emplace_back(AFT, ref.getDecl());
51795179
} else if (auto *AMT = (*fnType)->getAs<AnyMetatypeType>()) {
51805180
auto baseTy = AMT->getInstanceType();
51815181
if (baseTy->mayHaveMembers())
5182-
collectPossibleParamListByQualifiedLookup(
5182+
collectPossibleCalleesByQualifiedLookup(
51835183
DC, baseTy, DeclBaseName::createConstructor(), candidates);
51845184
}
51855185
}
51865186

51875187
return !candidates.empty();
51885188
}
51895189

5190-
bool collectPossibleParamListsSubscript(
5190+
bool collectPossibleCalleesForSubscript(
51915191
DeclContext &DC, SubscriptExpr *subscriptExpr,
5192-
SmallVectorImpl<FunctionParams> &candidates) {
5192+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
51935193
if (subscriptExpr->hasDecl()) {
51945194
if (auto SD = dyn_cast<SubscriptDecl>(subscriptExpr->getDecl().getDecl())) {
51955195
auto declType = SD->getInterfaceType();
51965196
if (auto *funcType = declType->getAs<AnyFunctionType>())
5197-
candidates.push_back(funcType->getParams());
5197+
candidates.emplace_back(funcType, SD);
51985198
}
51995199
} else {
5200-
collectPossibleParamListByQualifiedLookup(DC, subscriptExpr->getBase(),
5201-
DeclBaseName::createSubscript(),
5202-
candidates);
5200+
collectPossibleCalleesByQualifiedLookup(DC, subscriptExpr->getBase(),
5201+
DeclBaseName::createSubscript(),
5202+
candidates);
52035203
}
52045204
return !candidates.empty();
52055205
}
@@ -5288,14 +5288,14 @@ class CodeCompletionTypeContextAnalyzer {
52885288

52895289
bool collectArgumentExpectation(DeclContext &DC, Expr *E, Expr *CCExpr) {
52905290
// Collect parameter lists for possible func decls.
5291-
SmallVector<FunctionParams, 4> Candidates;
5291+
SmallVector<FunctionTypeAndDecl, 4> Candidates;
52925292
Expr *Arg = nullptr;
52935293
if (auto *applyExpr = dyn_cast<ApplyExpr>(E)) {
5294-
if (!collectPossibleParamListsApply(DC, applyExpr, Candidates))
5294+
if (!collectPossibleCalleesForApply(DC, applyExpr, Candidates))
52955295
return false;
52965296
Arg = applyExpr->getArg();
52975297
} else if (auto *subscriptExpr = dyn_cast<SubscriptExpr>(E)) {
5298-
if (!collectPossibleParamListsSubscript(DC, subscriptExpr, Candidates))
5298+
if (!collectPossibleCalleesForSubscript(DC, subscriptExpr, Candidates))
52995299
return false;
53005300
Arg = subscriptExpr->getIndex();
53015301
}
@@ -5314,7 +5314,8 @@ class CodeCompletionTypeContextAnalyzer {
53145314
(isa<CallExpr>(E) | isa<SubscriptExpr>(E));
53155315
SmallPtrSet<TypeBase *, 4> seenTypes;
53165316
SmallPtrSet<Identifier, 4> seenNames;
5317-
for (auto Params : Candidates) {
5317+
for (auto &typeAndDecl : Candidates) {
5318+
auto Params = typeAndDecl.first->getParams();
53185319
if (Position >= Params.size())
53195320
continue;
53205321
const auto &Param = Params[Position];

0 commit comments

Comments
 (0)