Skip to content

Commit 3c957de

Browse files
committed
[CodeCompletion] Use CompletionLookup.CurrModule instance property
1 parent 83084e2 commit 3c957de

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
@@ -1763,7 +1763,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17631763
llvm::StringSet<> ImportedModules;
17641764
collectImportedModules(ImportedModules);
17651765

1766-
auto mainModuleName = CurrDeclContext->getParentModule()->getName();
1766+
auto mainModuleName = CurrModule->getName();
17671767
for (auto ModuleName : ModuleNames) {
17681768
if (ModuleName.str().startswith("_") ||
17691769
ModuleName == mainModuleName ||
@@ -1820,8 +1820,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
18201820
return SemanticContextKind::OutsideNominal;
18211821

18221822
case DeclVisibilityKind::VisibleAtTopLevel:
1823-
if (CurrDeclContext &&
1824-
D->getModuleContext() == CurrDeclContext->getParentModule()) {
1823+
if (CurrDeclContext && D->getModuleContext() == CurrModule) {
18251824
// Treat global variables from the same source file as local when
18261825
// completing at top-level.
18271826
if (isa<VarDecl>(D) && isTopLevelContext(CurrDeclContext) &&
@@ -1934,28 +1933,28 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19341933
/// protocol compositions.
19351934
///
19361935
/// FIXME: Perhaps this should be an option in PrintOptions instead.
1937-
Type eraseArchetypes(ModuleDecl *M, Type type, GenericSignature *genericSig) {
1936+
Type eraseArchetypes(Type type, GenericSignature *genericSig) {
19381937
if (!genericSig)
19391938
return type;
19401939

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

19491948
if (auto *genericFuncType = type->getAs<GenericFunctionType>()) {
19501949
SmallVector<AnyFunctionType::Param, 8> erasedParams;
19511950
for (const auto &param : genericFuncType->getParams()) {
1952-
auto erasedTy = eraseArchetypes(M, param.getPlainType(), genericSig);
1951+
auto erasedTy = eraseArchetypes(param.getPlainType(), genericSig);
19531952
erasedParams.emplace_back(erasedTy, param.getLabel(),
19541953
param.getParameterFlags());
19551954
}
19561955
return GenericFunctionType::get(genericSig,
19571956
erasedParams,
1958-
eraseArchetypes(M, genericFuncType->getResult(), genericSig),
1957+
eraseArchetypes(genericFuncType->getResult(), genericSig),
19591958
genericFuncType->getExtInfo());
19601959
}
19611960

@@ -1994,7 +1993,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19941993
}
19951994

19961995
Type getTypeOfMember(const ValueDecl *VD, Type ExprType) {
1997-
auto *M = CurrDeclContext->getParentModule();
19981996
auto *GenericSig = VD->getInnermostDeclContext()
19991997
->getGenericSignatureOfContext();
20001998

@@ -2035,7 +2033,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
20352033
return T;
20362034

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

20402038
// Pass in DesugarMemberTypes so that we see the actual
20412039
// concrete type witnesses instead of type alias types.
@@ -2045,7 +2043,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
20452043
}
20462044
}
20472045

2048-
return eraseArchetypes(M, T, GenericSig);
2046+
return eraseArchetypes(T, GenericSig);
20492047
}
20502048

20512049
Type getAssociatedTypeType(const AssociatedTypeDecl *ATD) {
@@ -2305,7 +2303,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23052303

23062304
if (calleeDC->isLocalContext())
23072305
return SemanticContextKind::Local;
2308-
if (calleeDC->getParentModule() == CurrDeclContext->getParentModule())
2306+
if (calleeDC->getParentModule() == CurrModule)
23092307
return SemanticContextKind::CurrentModule;
23102308

23112309
return SemanticContextKind::OtherModule;
@@ -2316,8 +2314,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23162314
foundFunction(AFT);
23172315
auto genericSig =
23182316
SD->getInnermostDeclContext()->getGenericSignatureOfContext();
2319-
AFT = eraseArchetypes(CurrDeclContext->getParentModule(),
2320-
const_cast<AnyFunctionType *>(AFT), genericSig)
2317+
AFT = eraseArchetypes(const_cast<AnyFunctionType *>(AFT), genericSig)
23212318
->castTo<AnyFunctionType>();
23222319

23232320
CommandWordsPairs Pairs;
@@ -2347,8 +2344,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23472344
if (AFD) {
23482345
auto genericSig =
23492346
AFD->getInnermostDeclContext()->getGenericSignatureOfContext();
2350-
AFT = eraseArchetypes(CurrDeclContext->getParentModule(),
2351-
const_cast<AnyFunctionType *>(AFT), genericSig)
2347+
AFT = eraseArchetypes(const_cast<AnyFunctionType *>(AFT), genericSig)
23522348
->castTo<AnyFunctionType>();
23532349
}
23542350

@@ -3171,7 +3167,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31713167
bool tryModuleCompletions(Type ExprType) {
31723168
if (auto MT = ExprType->getAs<ModuleType>()) {
31733169
ModuleDecl *M = MT->getModule();
3174-
if (CurrDeclContext->getParentModule() != M) {
3170+
if (CurrModule != M) {
31753171
// Only use the cache if it is not the current module.
31763172
RequestedCachedResults.push_back(
31773173
RequestedResultsTy::fromModule(M).needLeadingDot(needDot()));
@@ -3718,7 +3714,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37183714
if (auto NT = T->getAs<NominalType>()) {
37193715
if (auto NTD = NT->getDecl()) {
37203716
if (!isa<ProtocolDecl>(NTD) &&
3721-
NTD->getModuleContext() != CurrDeclContext->getParentModule()) {
3717+
NTD->getModuleContext() != CurrModule) {
37223718
addNominalTypeRef(NT->getDecl(),
37233719
DeclVisibilityKind::VisibleAtTopLevel, {});
37243720
}
@@ -3779,7 +3775,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37793775
if (!T->mayHaveMembers())
37803776
return;
37813777

3782-
ModuleDecl *CurrModule = CurrDeclContext->getParentModule();
37833778
DeclContext *DC = const_cast<DeclContext *>(CurrDeclContext);
37843779

37853780
// We can only say .foo where foo is a static member of the contextual
@@ -3922,10 +3917,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39223917
void collectPrecedenceGroups() {
39233918
assert(CurrDeclContext);
39243919

3925-
auto M = CurrDeclContext->getParentModule();
3926-
3927-
if (M) {
3928-
for (auto FU: M->getFiles()) {
3920+
if (CurrModule) {
3921+
for (auto FU: CurrModule->getFiles()) {
39293922
// We are looking through the current module,
39303923
// inspect only source files.
39313924
if (FU->getKind() != FileUnitKind::Source)
@@ -3941,7 +3934,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39413934
CurrDeclContext->getParentSourceFile()
39423935
->forAllVisibleModules([&](ModuleDecl::ImportedModule Import) {
39433936
auto Module = Import.second;
3944-
if (Module == M)
3937+
if (Module == CurrModule)
39453938
return;
39463939

39473940
RequestedCachedResults.push_back(
@@ -3995,9 +3988,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39953988
Kind = OnlyTypes ? LookupKind::TypeInDeclContext
39963989
: LookupKind::ValueInDeclContext;
39973990
NeedLeadingDot = false;
3998-
ModuleDecl *M = CurrDeclContext->getParentModule();
39993991
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
4000-
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
3992+
CurrModule->lookupVisibleDecls({}, FilteringConsumer,
3993+
NLKind::UnqualifiedLookup);
40013994
}
40023995

40033996
void getVisibleDeclsOfModule(const ModuleDecl *TheModule,

0 commit comments

Comments
 (0)