Skip to content

Commit 8a6c540

Browse files
committed
[CodeCompletion][NFC] Collect possible callees instead of params
in context type analysis. Still NFC, but this is needed by later commits.
1 parent 1af8078 commit 8a6c540

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
@@ -4971,11 +4971,11 @@ namespace {
49714971
} // end anonymous namespace
49724972

49734973
namespace {
4974-
using FunctionParams = ArrayRef<AnyFunctionType::Param>;
4974+
using FunctionTypeAndDecl = std::pair<AnyFunctionType *, ValueDecl *>;
49754975

4976-
void collectPossibleParamListByQualifiedLookup(
4976+
void collectPossibleCalleesByQualifiedLookup(
49774977
DeclContext &DC, Type baseTy, DeclBaseName name,
4978-
SmallVectorImpl<FunctionParams> &candidates) {
4978+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
49794979

49804980
SmallVector<ValueDecl *, 2> decls;
49814981
auto resolver = DC.getASTContext().getLazyResolver();
@@ -5000,14 +5000,14 @@ void collectPossibleParamListByQualifiedLookup(
50005000
if (!fnType || fnType->hasError())
50015001
continue;
50025002
if (auto *AFT = fnType->getAs<AnyFunctionType>()) {
5003-
candidates.push_back(AFT->getParams());
5003+
candidates.emplace_back(AFT, VD);
50045004
}
50055005
}
50065006
}
50075007

5008-
void collectPossibleParamListByQualifiedLookup(
5008+
void collectPossibleCalleesByQualifiedLookup(
50095009
DeclContext &DC, Expr *baseExpr, DeclBaseName name,
5010-
SmallVectorImpl<FunctionParams> &candidates) {
5010+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
50115011
ConcreteDeclRef ref = nullptr;
50125012
auto baseTyOpt = getTypeOfCompletionContextExpr(
50135013
DC.getASTContext(), &DC, CompletionTypeCheckKind::Normal, baseExpr, ref);
@@ -5017,31 +5017,31 @@ void collectPossibleParamListByQualifiedLookup(
50175017
if (!baseTy->mayHaveMembers())
50185018
return;
50195019

5020-
collectPossibleParamListByQualifiedLookup(DC, baseTy, name, candidates);
5020+
collectPossibleCalleesByQualifiedLookup(DC, baseTy, name, candidates);
50215021
}
50225022

5023-
bool collectPossibleParamListsApply(
5023+
bool collectPossibleCalleesForApply(
50245024
DeclContext &DC, ApplyExpr *callExpr,
5025-
SmallVectorImpl<FunctionParams> &candidates) {
5025+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
50265026
auto *fnExpr = callExpr->getFn();
50275027

50285028
if (auto type = fnExpr->getType()) {
50295029
if (auto *funcType = type->getAs<AnyFunctionType>())
5030-
candidates.push_back(funcType->getParams());
5030+
candidates.emplace_back(funcType, fnExpr->getReferencedDecl().getDecl());
50315031
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
50325032
if (auto *decl = DRE->getDecl()) {
50335033
auto declType = decl->getInterfaceType();
50345034
if (auto *funcType = declType->getAs<AnyFunctionType>())
5035-
candidates.push_back(funcType->getParams());
5035+
candidates.emplace_back(funcType, decl);
50365036
}
50375037
} else if (auto *OSRE = dyn_cast<OverloadSetRefExpr>(fnExpr)) {
50385038
for (auto *decl : OSRE->getDecls()) {
50395039
auto declType = decl->getInterfaceType();
50405040
if (auto *funcType = declType->getAs<AnyFunctionType>())
5041-
candidates.push_back(funcType->getParams());
5041+
candidates.emplace_back(funcType, decl);
50425042
}
50435043
} else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
5044-
collectPossibleParamListByQualifiedLookup(
5044+
collectPossibleCalleesByQualifiedLookup(
50455045
DC, UDE->getBase(), UDE->getName().getBaseName(), candidates);
50465046
}
50475047

@@ -5053,31 +5053,31 @@ bool collectPossibleParamListsApply(
50535053
return false;
50545054

50555055
if (auto *AFT = (*fnType)->getAs<AnyFunctionType>()) {
5056-
candidates.push_back(AFT->getParams());
5056+
candidates.emplace_back(AFT, ref.getDecl());
50575057
} else if (auto *AMT = (*fnType)->getAs<AnyMetatypeType>()) {
50585058
auto baseTy = AMT->getInstanceType();
50595059
if (baseTy->mayHaveMembers())
5060-
collectPossibleParamListByQualifiedLookup(
5060+
collectPossibleCalleesByQualifiedLookup(
50615061
DC, baseTy, DeclBaseName::createConstructor(), candidates);
50625062
}
50635063
}
50645064

50655065
return !candidates.empty();
50665066
}
50675067

5068-
bool collectPossibleParamListsSubscript(
5068+
bool collectPossibleCalleesForSubscript(
50695069
DeclContext &DC, SubscriptExpr *subscriptExpr,
5070-
SmallVectorImpl<FunctionParams> &candidates) {
5070+
SmallVectorImpl<FunctionTypeAndDecl> &candidates) {
50715071
if (subscriptExpr->hasDecl()) {
50725072
if (auto SD = dyn_cast<SubscriptDecl>(subscriptExpr->getDecl().getDecl())) {
50735073
auto declType = SD->getInterfaceType();
50745074
if (auto *funcType = declType->getAs<AnyFunctionType>())
5075-
candidates.push_back(funcType->getParams());
5075+
candidates.emplace_back(funcType, SD);
50765076
}
50775077
} else {
5078-
collectPossibleParamListByQualifiedLookup(DC, subscriptExpr->getBase(),
5079-
DeclBaseName::createSubscript(),
5080-
candidates);
5078+
collectPossibleCalleesByQualifiedLookup(DC, subscriptExpr->getBase(),
5079+
DeclBaseName::createSubscript(),
5080+
candidates);
50815081
}
50825082
return !candidates.empty();
50835083
}
@@ -5166,14 +5166,14 @@ class CodeCompletionTypeContextAnalyzer {
51665166

51675167
bool collectArgumentExpectation(DeclContext &DC, Expr *E, Expr *CCExpr) {
51685168
// Collect parameter lists for possible func decls.
5169-
SmallVector<FunctionParams, 4> Candidates;
5169+
SmallVector<FunctionTypeAndDecl, 4> Candidates;
51705170
Expr *Arg = nullptr;
51715171
if (auto *applyExpr = dyn_cast<ApplyExpr>(E)) {
5172-
if (!collectPossibleParamListsApply(DC, applyExpr, Candidates))
5172+
if (!collectPossibleCalleesForApply(DC, applyExpr, Candidates))
51735173
return false;
51745174
Arg = applyExpr->getArg();
51755175
} else if (auto *subscriptExpr = dyn_cast<SubscriptExpr>(E)) {
5176-
if (!collectPossibleParamListsSubscript(DC, subscriptExpr, Candidates))
5176+
if (!collectPossibleCalleesForSubscript(DC, subscriptExpr, Candidates))
51775177
return false;
51785178
Arg = subscriptExpr->getIndex();
51795179
}
@@ -5192,7 +5192,8 @@ class CodeCompletionTypeContextAnalyzer {
51925192
(isa<CallExpr>(E) | isa<SubscriptExpr>(E));
51935193
SmallPtrSet<TypeBase *, 4> seenTypes;
51945194
SmallPtrSet<Identifier, 4> seenNames;
5195-
for (auto Params : Candidates) {
5195+
for (auto &typeAndDecl : Candidates) {
5196+
auto Params = typeAndDecl.first->getParams();
51965197
if (Position >= Params.size())
51975198
continue;
51985199
const auto &Param = Params[Position];

0 commit comments

Comments
 (0)