Skip to content

Commit a534050

Browse files
committed
[CodeCompletion] Use CompletionLookup.CurrModule instance property
(cherry picked from commit 3c957de)
1 parent a3e3d3e commit a534050

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17651765
llvm::StringSet<> ImportedModules;
17661766
collectImportedModules(ImportedModules);
17671767

1768-
auto mainModuleName = CurrDeclContext->getParentModule()->getName();
1768+
auto mainModuleName = CurrModule->getName();
17691769
for (auto ModuleName : ModuleNames) {
17701770
if (ModuleName.str().startswith("_") ||
17711771
ModuleName == mainModuleName ||
@@ -1822,8 +1822,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
18221822
return SemanticContextKind::OutsideNominal;
18231823

18241824
case DeclVisibilityKind::VisibleAtTopLevel:
1825-
if (CurrDeclContext &&
1826-
D->getModuleContext() == CurrDeclContext->getParentModule()) {
1825+
if (CurrDeclContext && D->getModuleContext() == CurrModule) {
18271826
// Treat global variables from the same source file as local when
18281827
// completing at top-level.
18291828
if (isa<VarDecl>(D) && isTopLevelContext(CurrDeclContext) &&
@@ -1936,28 +1935,28 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19361935
/// protocol compositions.
19371936
///
19381937
/// FIXME: Perhaps this should be an option in PrintOptions instead.
1939-
Type eraseArchetypes(ModuleDecl *M, Type type, GenericSignature *genericSig) {
1938+
Type eraseArchetypes(Type type, GenericSignature *genericSig) {
19401939
if (!genericSig)
19411940
return type;
19421941

19431942
auto buildProtocolComposition = [&](ArrayRef<ProtocolDecl *> protos) -> Type {
19441943
SmallVector<Type, 2> types;
19451944
for (auto proto : protos)
19461945
types.push_back(proto->getDeclaredInterfaceType());
1947-
return ProtocolCompositionType::get(M->getASTContext(), types,
1946+
return ProtocolCompositionType::get(Ctx, types,
19481947
/*HasExplicitAnyObject=*/false);
19491948
};
19501949

19511950
if (auto *genericFuncType = type->getAs<GenericFunctionType>()) {
19521951
SmallVector<AnyFunctionType::Param, 8> erasedParams;
19531952
for (const auto &param : genericFuncType->getParams()) {
1954-
auto erasedTy = eraseArchetypes(M, param.getPlainType(), genericSig);
1953+
auto erasedTy = eraseArchetypes(param.getPlainType(), genericSig);
19551954
erasedParams.emplace_back(erasedTy, param.getLabel(),
19561955
param.getParameterFlags());
19571956
}
19581957
return GenericFunctionType::get(genericSig,
19591958
erasedParams,
1960-
eraseArchetypes(M, genericFuncType->getResult(), genericSig),
1959+
eraseArchetypes(genericFuncType->getResult(), genericSig),
19611960
genericFuncType->getExtInfo());
19621961
}
19631962

@@ -1996,7 +1995,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19961995
}
19971996

19981997
Type getTypeOfMember(const ValueDecl *VD, Type ExprType) {
1999-
auto *M = CurrDeclContext->getParentModule();
20001998
auto *GenericSig = VD->getInnermostDeclContext()
20011999
->getGenericSignatureOfContext();
20022000

@@ -2037,7 +2035,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
20372035
return T;
20382036

20392037
// For everything else, substitute in the base type.
2040-
auto Subs = MaybeNominalType->getMemberSubstitutionMap(M, VD);
2038+
auto Subs = MaybeNominalType->getMemberSubstitutionMap(CurrModule, VD);
20412039

20422040
// Pass in DesugarMemberTypes so that we see the actual
20432041
// concrete type witnesses instead of type alias types.
@@ -2047,7 +2045,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
20472045
}
20482046
}
20492047

2050-
return eraseArchetypes(M, T, GenericSig);
2048+
return eraseArchetypes(T, GenericSig);
20512049
}
20522050

20532051
Type getAssociatedTypeType(const AssociatedTypeDecl *ATD) {
@@ -2307,7 +2305,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23072305

23082306
if (calleeDC->isLocalContext())
23092307
return SemanticContextKind::Local;
2310-
if (calleeDC->getParentModule() == CurrDeclContext->getParentModule())
2308+
if (calleeDC->getParentModule() == CurrModule)
23112309
return SemanticContextKind::CurrentModule;
23122310

23132311
return SemanticContextKind::OtherModule;
@@ -2318,8 +2316,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23182316
foundFunction(AFT);
23192317
auto genericSig =
23202318
SD->getInnermostDeclContext()->getGenericSignatureOfContext();
2321-
AFT = eraseArchetypes(CurrDeclContext->getParentModule(),
2322-
const_cast<AnyFunctionType *>(AFT), genericSig)
2319+
AFT = eraseArchetypes(const_cast<AnyFunctionType *>(AFT), genericSig)
23232320
->castTo<AnyFunctionType>();
23242321

23252322
CommandWordsPairs Pairs;
@@ -2349,8 +2346,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23492346
if (AFD) {
23502347
auto genericSig =
23512348
AFD->getInnermostDeclContext()->getGenericSignatureOfContext();
2352-
AFT = eraseArchetypes(CurrDeclContext->getParentModule(),
2353-
const_cast<AnyFunctionType *>(AFT), genericSig)
2349+
AFT = eraseArchetypes(const_cast<AnyFunctionType *>(AFT), genericSig)
23542350
->castTo<AnyFunctionType>();
23552351
}
23562352

@@ -3173,7 +3169,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31733169
bool tryModuleCompletions(Type ExprType) {
31743170
if (auto MT = ExprType->getAs<ModuleType>()) {
31753171
ModuleDecl *M = MT->getModule();
3176-
if (CurrDeclContext->getParentModule() != M) {
3172+
if (CurrModule != M) {
31773173
// Only use the cache if it is not the current module.
31783174
RequestedCachedResults.push_back(
31793175
RequestedResultsTy::fromModule(M).needLeadingDot(needDot()));
@@ -3721,7 +3717,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37213717
if (auto NT = T->getAs<NominalType>()) {
37223718
if (auto NTD = NT->getDecl()) {
37233719
if (!isa<ProtocolDecl>(NTD) &&
3724-
NTD->getModuleContext() != CurrDeclContext->getParentModule()) {
3720+
NTD->getModuleContext() != CurrModule) {
37253721
addNominalTypeRef(NT->getDecl(),
37263722
DeclVisibilityKind::VisibleAtTopLevel, {});
37273723
}
@@ -3782,7 +3778,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37823778
if (!T->mayHaveMembers())
37833779
return;
37843780

3785-
ModuleDecl *CurrModule = CurrDeclContext->getParentModule();
37863781
DeclContext *DC = const_cast<DeclContext *>(CurrDeclContext);
37873782

37883783
// We can only say .foo where foo is a static member of the contextual
@@ -3925,10 +3920,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39253920
void collectPrecedenceGroups() {
39263921
assert(CurrDeclContext);
39273922

3928-
auto M = CurrDeclContext->getParentModule();
3929-
3930-
if (M) {
3931-
for (auto FU: M->getFiles()) {
3923+
if (CurrModule) {
3924+
for (auto FU: CurrModule->getFiles()) {
39323925
// We are looking through the current module,
39333926
// inspect only source files.
39343927
if (FU->getKind() != FileUnitKind::Source)
@@ -3944,7 +3937,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39443937
CurrDeclContext->getParentSourceFile()
39453938
->forAllVisibleModules([&](ModuleDecl::ImportedModule Import) {
39463939
auto Module = Import.second;
3947-
if (Module == M)
3940+
if (Module == CurrModule)
39483941
return;
39493942

39503943
RequestedCachedResults.push_back(
@@ -3998,9 +3991,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39983991
Kind = OnlyTypes ? LookupKind::TypeInDeclContext
39993992
: LookupKind::ValueInDeclContext;
40003993
NeedLeadingDot = false;
4001-
ModuleDecl *M = CurrDeclContext->getParentModule();
40023994
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
4003-
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
3995+
CurrModule->lookupVisibleDecls({}, FilteringConsumer,
3996+
NLKind::UnqualifiedLookup);
40043997
}
40053998

40063999
void getVisibleDeclsOfModule(const ModuleDecl *TheModule,

0 commit comments

Comments
 (0)