@@ -635,26 +635,23 @@ unsigned GenericSignatureImpl::getGenericParamOrdinal(
635
635
return GenericParamKey (param).findIndexIn (getGenericParams ());
636
636
}
637
637
638
- Type GenericSignatureImpl::getNonDependentUpperBounds (Type type) const {
639
- return getUpperBound (type);
640
- }
641
-
642
- Type GenericSignatureImpl::getDependentUpperBounds (Type type) const {
643
- return getUpperBound (type, /* wantDependentBound=*/ true );
644
- }
645
-
646
- Type GenericSignatureImpl::getUpperBound (Type type,
647
- bool wantDependentBound) const {
638
+ Type GenericSignatureImpl::getUpperBound (Type type) const {
648
639
assert (type->isTypeParameter ());
649
640
650
- bool hasExplicitAnyObject = requiresClass (type);
651
-
652
641
llvm::SmallVector<Type, 2 > types;
642
+ unsigned rootDepth = type->getRootGenericParam ()->getDepth ();
643
+
644
+ bool hasExplicitAnyObject = requiresClass (type);
653
645
654
646
if (Type superclass = getSuperclassBound (type)) {
655
647
do {
656
648
superclass = getReducedType (superclass);
657
- if (wantDependentBound || !superclass->hasTypeParameter ()) {
649
+
650
+ if (!superclass.findIf ([&](Type t) {
651
+ if (auto *paramTy = t->getAs <GenericTypeParamType>())
652
+ return (paramTy->getDepth () == rootDepth);
653
+ return false ;
654
+ })) {
658
655
break ;
659
656
}
660
657
} while ((superclass = superclass->getSuperclass ()));
@@ -684,31 +681,13 @@ Type GenericSignatureImpl::getUpperBound(Type type,
684
681
685
682
// If the reduced type is at a lower depth than the root generic
686
683
// parameter of T, then it's constrained.
687
- bool hasOuterGenericParam = false ;
688
- bool hasInnerGenericParam = false ;
689
- reducedType.visit ([&](Type t) {
690
- if (auto *paramTy = t->getAs <GenericTypeParamType>()) {
691
- unsigned rootDepth = type->getRootGenericParam ()->getDepth ();
692
- if (paramTy->getDepth () == rootDepth)
693
- hasInnerGenericParam = true ;
694
- else {
695
- assert (paramTy->getDepth () < rootDepth);
696
- hasOuterGenericParam = true ;
697
- }
698
- }
699
- });
700
-
701
- if (hasInnerGenericParam && hasOuterGenericParam) {
702
- llvm::errs () << " Weird same-type requirements?\n " ;
703
- llvm::errs () << " Interface type: " << type << " \n " ;
704
- llvm::errs () << " Member type: " << memberType << " \n " ;
705
- llvm::errs () << " Reduced member type: " << reducedType << " \n " ;
706
- llvm::errs () << GenericSignature (this ) << " \n " ;
707
- abort ();
708
- }
709
-
710
- if (!hasInnerGenericParam && (wantDependentBound || !hasOuterGenericParam))
684
+ if (!reducedType.findIf ([&](Type t) {
685
+ if (auto *paramTy = t->getAs <GenericTypeParamType>())
686
+ return (paramTy->getDepth () == rootDepth);
687
+ return false ;
688
+ })) {
711
689
argTypes.push_back (reducedType);
690
+ }
712
691
}
713
692
714
693
// If we have constrained all primary associated types, create a
@@ -721,7 +700,8 @@ Type GenericSignatureImpl::getUpperBound(Type type,
721
700
//
722
701
// In that case just add the base type in the default branch below.
723
702
if (argTypes.size () == primaryAssocTypes.size ()) {
724
- types.push_back (ParameterizedProtocolType::get (getASTContext (), baseType, argTypes));
703
+ types.push_back (ParameterizedProtocolType::get (
704
+ getASTContext (), baseType, argTypes));
725
705
continue ;
726
706
}
727
707
}
0 commit comments