@@ -247,10 +247,10 @@ static ConstructorComparison compareConstructors(ConstructorDecl *ctor1,
247
247
248
248
// / Given a set of declarations whose names and signatures have matched,
249
249
// / figure out which of these declarations have been shadowed by others.
250
- static void recordShadowedDeclsAfterSignatureMatch (
251
- ArrayRef<ValueDecl *> decls,
252
- const DeclContext *dc,
253
- llvm::SmallPtrSetImpl<ValueDecl * > &shadowed) {
250
+ template < typename T>
251
+ static void
252
+ recordShadowedDeclsAfterSignatureMatch (ArrayRef<T> decls, const DeclContext *dc,
253
+ llvm::SmallPtrSetImpl<T > &shadowed) {
254
254
assert (decls.size () > 1 && " Nothing collided" );
255
255
256
256
// Compare each declaration to every other declaration. This is
@@ -354,9 +354,9 @@ static void recordShadowedDeclsAfterSignatureMatch(
354
354
// This is due to the fact that in Swift 4, we only gave custom overload
355
355
// types to properties in extensions of generic types, otherwise we
356
356
// used the null type.
357
- if (!ctx.isSwiftVersionAtLeast (5 )) {
358
- auto secondSig = secondDecl->getOverloadSignature ();
359
- auto firstSig = firstDecl->getOverloadSignature ();
357
+ if (!ctx.isSwiftVersionAtLeast (5 ) && isa<ValueDecl>(firstDecl) ) {
358
+ auto secondSig = cast<ValueDecl>( secondDecl) ->getOverloadSignature ();
359
+ auto firstSig = cast<ValueDecl>( firstDecl) ->getOverloadSignature ();
360
360
if (firstSig.IsVariable && secondSig.IsVariable )
361
361
if (firstSig.InExtensionOfGenericType !=
362
362
secondSig.InExtensionOfGenericType )
@@ -583,8 +583,8 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
583
583
584
584
// Check whether we have shadowing for signature collisions.
585
585
for (auto signature : collisionTypes) {
586
- recordShadowedDeclsAfterSignatureMatch ( collisions[signature], dc,
587
- shadowed);
586
+ ArrayRef<ValueDecl *> collidingDecls = collisions[signature];
587
+ recordShadowedDeclsAfterSignatureMatch (collidingDecls, dc, shadowed);
588
588
}
589
589
590
590
// Check whether we have shadowing for imported initializer collisions.
@@ -594,11 +594,25 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
594
594
}
595
595
}
596
596
597
- bool swift::removeShadowedDecls (SmallVectorImpl<ValueDecl*> &decls,
598
- const DeclContext *dc) {
597
+ static void
598
+ recordShadowedDecls (ArrayRef<OperatorDecl *> decls, const DeclContext *dc,
599
+ llvm::SmallPtrSetImpl<OperatorDecl *> &shadowed) {
600
+ // Always considered to have the same signature.
601
+ recordShadowedDeclsAfterSignatureMatch (decls, dc, shadowed);
602
+ }
603
+
604
+ static void
605
+ recordShadowedDecls (ArrayRef<PrecedenceGroupDecl *> decls,
606
+ const DeclContext *dc,
607
+ llvm::SmallPtrSetImpl<PrecedenceGroupDecl *> &shadowed) {
608
+ // Always considered to have the same signature.
609
+ recordShadowedDeclsAfterSignatureMatch (decls, dc, shadowed);
610
+ }
611
+
612
+ template <typename T, typename Container>
613
+ static bool removeShadowedDeclsImpl (Container &decls, const DeclContext *dc) {
599
614
// Collect declarations with the same (full) name.
600
- llvm::SmallDenseMap<DeclName, llvm::TinyPtrVector<ValueDecl *>>
601
- collidingDeclGroups;
615
+ llvm::SmallDenseMap<DeclName, llvm::TinyPtrVector<T>> collidingDeclGroups;
602
616
bool anyCollisions = false ;
603
617
for (auto decl : decls) {
604
618
// Record this declaration based on its full name.
@@ -614,7 +628,7 @@ bool swift::removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
614
628
return false ;
615
629
616
630
// Walk through the declarations again, marking any declarations that shadow.
617
- llvm::SmallPtrSet<ValueDecl * , 4 > shadowed;
631
+ llvm::SmallPtrSet<T , 4 > shadowed;
618
632
for (auto decl : decls) {
619
633
auto known = collidingDeclGroups.find (decl->getName ());
620
634
if (known == collidingDeclGroups.end ()) {
@@ -633,8 +647,8 @@ bool swift::removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
633
647
// Remove shadowed declarations from the list of declarations.
634
648
bool anyRemoved = false ;
635
649
decls.erase (std::remove_if (decls.begin (), decls.end (),
636
- [&](ValueDecl *vd ) {
637
- if (shadowed.count (vd ) > 0 ) {
650
+ [&](T decl ) {
651
+ if (shadowed.count (decl ) > 0 ) {
638
652
anyRemoved = true ;
639
653
return true ;
640
654
}
@@ -646,6 +660,28 @@ bool swift::removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
646
660
return anyRemoved;
647
661
}
648
662
663
+ bool swift::removeShadowedDecls (SmallVectorImpl<ValueDecl *> &decls,
664
+ const DeclContext *dc) {
665
+ return removeShadowedDeclsImpl<ValueDecl *>(decls, dc);
666
+ }
667
+
668
+ bool swift::removeShadowedDecls (TinyPtrVector<OperatorDecl *> &decls,
669
+ const DeclContext *dc) {
670
+ #ifndef NDEBUG
671
+ // Make sure all the operators have the same fixity.
672
+ if (decls.size () > 1 ) {
673
+ for (auto *op : decls)
674
+ assert (op->getFixity () == decls[0 ]->getFixity ());
675
+ }
676
+ #endif
677
+ return removeShadowedDeclsImpl<OperatorDecl *>(decls, dc);
678
+ }
679
+
680
+ bool swift::removeShadowedDecls (TinyPtrVector<PrecedenceGroupDecl *> &decls,
681
+ const DeclContext *dc) {
682
+ return removeShadowedDeclsImpl<PrecedenceGroupDecl *>(decls, dc);
683
+ }
684
+
649
685
namespace {
650
686
enum class DiscriminatorMatch {
651
687
NoDiscriminator,
0 commit comments