@@ -466,92 +466,6 @@ lookupVisibleMemberDeclsImpl(Type BaseTy, VisibleDeclConsumer &Consumer,
466
466
GenericSignatureBuilder *GSB,
467
467
VisitedSet &Visited);
468
468
469
- // Filters out restated declarations from a protocol hierarchy
470
- // or equivalent requirements from protocol composition types.
471
- class RestateFilteringConsumer : public VisibleDeclConsumer {
472
- LazyResolver *resolver;
473
-
474
- using FoundDecl = std::pair<ValueDecl*, DeclVisibilityKind>;
475
- using NameAndType = std::pair<DeclName, CanType>;
476
-
477
- llvm::DenseMap<DeclName, FoundDecl> foundVars;
478
- llvm::DenseMap<NameAndType, FoundDecl> foundFuncs;
479
- llvm::MapVector<ValueDecl*, DeclVisibilityKind> declsToReport;
480
-
481
- template <typename K>
482
- void addDecl (llvm::DenseMap<K, FoundDecl> &Map, K Key, FoundDecl FD) {
483
- // Add the declaration if we haven't found an equivalent yet, otherwise
484
- // replace the equivalent if the found decl has a higher access level.
485
- auto existingDecl = Map.find (Key);
486
-
487
- if ((existingDecl == Map.end ()) ||
488
- (Map[Key].first ->getFormalAccess () < FD.first ->getFormalAccess ())) {
489
- if (existingDecl != Map.end ())
490
- declsToReport.erase ({existingDecl->getSecond ().first });
491
- Map[Key] = FD;
492
- declsToReport.insert (FD);
493
- }
494
- }
495
-
496
- CanType stripSelfRequirementsIfNeeded (ValueDecl *VD,
497
- GenericFunctionType *GFT) const {
498
- // Preserve the generic signature if this is a subscript, which are uncurried,
499
- // or if we have generic params other than Self. Otherwise, use
500
- // the resultType of the curried function type.
501
- // When we keep the generic signature, we remove the requirements
502
- // from Self to make sure they don't prevent us from recognizing restatements.
503
- auto params = GFT->getGenericParams ();
504
- if (params.size () == 1 && !isa<SubscriptDecl>(VD)) {
505
- return GFT->getResult ()->getCanonicalType ();
506
- }
507
- auto Self = VD->getDeclContext ()->getSelfInterfaceType ();
508
- SmallVector<Requirement, 4 > newReqs;
509
- for (auto req: GFT->getRequirements ()) {
510
- if (!Self->isEqual (req.getFirstType ()))
511
- newReqs.push_back (req);
512
- }
513
- auto newSig = GenericSignature::get (params, newReqs, false );
514
-
515
- return GenericFunctionType::get (newSig, GFT->getParams (),
516
- GFT->getResult (), GFT->getExtInfo ())
517
- ->getCanonicalType ();
518
- }
519
-
520
- public:
521
- RestateFilteringConsumer (Type baseTy, const DeclContext *DC,
522
- LazyResolver *resolver)
523
- : resolver(resolver) {
524
- assert (DC && baseTy && !baseTy->hasLValueType ());
525
- }
526
-
527
- void foundDecl (ValueDecl *VD, DeclVisibilityKind Reason) override {
528
- assert (VD);
529
- // If this isn't a protocol context, don't look further into the decl.
530
- if (!isa<ProtocolDecl>(VD->getDeclContext ())) {
531
- declsToReport.insert ({VD, Reason});
532
- return ;
533
- }
534
- if (resolver)
535
- resolver->resolveDeclSignature (VD);
536
-
537
- if (!VD->hasInterfaceType ()) {
538
- declsToReport.insert ({VD, Reason});
539
- return ;
540
- }
541
- if (auto GFT = VD->getInterfaceType ()->getAs <GenericFunctionType>()) {
542
- auto type = stripSelfRequirementsIfNeeded (VD, GFT);
543
- addDecl (foundFuncs, {VD->getFullName (), type}, {VD, Reason});
544
- return ;
545
- }
546
- addDecl (foundVars, VD->getFullName (), {VD, Reason});
547
- }
548
-
549
- void feedResultsToConsumer (VisibleDeclConsumer &Consumer) const {
550
- for (const auto entry: declsToReport)
551
- Consumer.foundDecl (entry.first , entry.second );
552
- }
553
- };
554
-
555
469
static void
556
470
lookupVisibleProtocolMemberDecls (Type BaseTy, ProtocolType *PT,
557
471
VisibleDeclConsumer &Consumer,
@@ -911,13 +825,11 @@ static void lookupVisibleMemberDecls(
911
825
LookupState LS, DeclVisibilityKind Reason, LazyResolver *TypeResolver,
912
826
GenericSignatureBuilder *GSB) {
913
827
OverrideFilteringConsumer overrideConsumer (BaseTy, CurrDC, TypeResolver);
914
- RestateFilteringConsumer restateConsumer (BaseTy, CurrDC, TypeResolver);
915
828
VisitedSet Visited;
916
- lookupVisibleMemberDeclsImpl (BaseTy, restateConsumer , CurrDC, LS, Reason,
829
+ lookupVisibleMemberDeclsImpl (BaseTy, overrideConsumer , CurrDC, LS, Reason,
917
830
TypeResolver, GSB, Visited);
918
831
919
832
// Report the declarations we found to the real consumer.
920
- restateConsumer.feedResultsToConsumer (overrideConsumer);
921
833
for (const auto &DeclAndReason : overrideConsumer.DeclsToReport )
922
834
Consumer.foundDecl (DeclAndReason.D , DeclAndReason.Reason );
923
835
}
0 commit comments