Skip to content

Commit f6a76f5

Browse files
committed
Utilize forEachTypeWitness()/forEachValueWitness()
1 parent 32e68c7 commit f6a76f5

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,17 +4164,12 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41644164
if (Access < AccessLevel::Public &&
41654165
!isa<ProtocolDecl>(VD->getDeclContext())) {
41664166
for (auto Conformance : CurrentNominal->getAllConformances()) {
4167-
auto Proto = Conformance->getProtocol();
4168-
for (auto Member : Proto->getMembers()) {
4169-
auto Requirement = dyn_cast<ValueDecl>(Member);
4170-
if (!Requirement || !Requirement->isProtocolRequirement() ||
4171-
isa<AssociatedTypeDecl>(Requirement))
4172-
continue;
4173-
4174-
auto Witness = Conformance->getWitnessDecl(Requirement);
4175-
if (Witness == VD)
4176-
Access = std::max(Access, Requirement->getFormalAccess());
4177-
}
4167+
Conformance->getRootConformance()->forEachValueWitness(
4168+
[&](ValueDecl *req, Witness witness) {
4169+
if (witness.getDecl() == VD)
4170+
Access = std::max(
4171+
Access, Conformance->getProtocol()->getFormalAccess());
4172+
});
41784173
}
41794174
}
41804175

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,11 @@ static void synthesizeMemberDeclsForLookup(NominalTypeDecl *NTD,
513513
Conformance->getRootConformance());
514514
if (!NormalConformance)
515515
continue;
516-
for (auto Member : Proto->getMembers()) {
517-
auto *VD = dyn_cast<ValueDecl>(Member);
518-
if (!VD || !VD->isProtocolRequirement())
519-
continue;
520-
if (auto *ATD = dyn_cast<AssociatedTypeDecl>(Member))
521-
(void)NormalConformance->getTypeWitnessAndDecl(ATD);
522-
else
523-
(void)NormalConformance->getWitness(VD);
524-
}
516+
NormalConformance->forEachTypeWitness(
517+
[](AssociatedTypeDecl *, Type, TypeDecl *) { return false; },
518+
/*useResolver=*/true);
519+
NormalConformance->forEachValueWitness([](ValueDecl *, Witness) {},
520+
/*useResolver=*/true);
525521
}
526522

527523
synthesizePropertyWrapperStorageWrapperProperties(NTD);

0 commit comments

Comments
 (0)