@@ -635,26 +635,23 @@ unsigned GenericSignatureImpl::getGenericParamOrdinal(
635635 return GenericParamKey (param).findIndexIn (getGenericParams ());
636636}
637637
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 {
648639 assert (type->isTypeParameter ());
649640
650- bool hasExplicitAnyObject = requiresClass (type);
651-
652641 llvm::SmallVector<Type, 2 > types;
642+ unsigned rootDepth = type->getRootGenericParam ()->getDepth ();
643+
644+ bool hasExplicitAnyObject = requiresClass (type);
653645
654646 if (Type superclass = getSuperclassBound (type)) {
655647 do {
656648 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+ })) {
658655 break ;
659656 }
660657 } while ((superclass = superclass->getSuperclass ()));
@@ -684,31 +681,13 @@ Type GenericSignatureImpl::getUpperBound(Type type,
684681
685682 // If the reduced type is at a lower depth than the root generic
686683 // 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+ })) {
711689 argTypes.push_back (reducedType);
690+ }
712691 }
713692
714693 // If we have constrained all primary associated types, create a
@@ -721,7 +700,8 @@ Type GenericSignatureImpl::getUpperBound(Type type,
721700 //
722701 // In that case just add the base type in the default branch below.
723702 if (argTypes.size () == primaryAssocTypes.size ()) {
724- types.push_back (ParameterizedProtocolType::get (getASTContext (), baseType, argTypes));
703+ types.push_back (ParameterizedProtocolType::get (
704+ getASTContext (), baseType, argTypes));
725705 continue ;
726706 }
727707 }
0 commit comments