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