@@ -831,8 +831,7 @@ int swift::compareAssociatedTypes(AssociatedTypeDecl *assocType1,
831831 return 0 ;
832832}
833833
834- // / Canonical ordering for type parameters.
835- int swift::compareDependentTypes (Type type1, Type type2) {
834+ static int compareDependentTypesRec (Type type1, Type type2) {
836835 // Fast-path check for equality.
837836 if (type1->isEqual (type2)) return 0 ;
838837
@@ -853,7 +852,7 @@ int swift::compareDependentTypes(Type type1, Type type2) {
853852
854853 // - by base, so t_0_n.`P.T` < t_1_m.`P.T`
855854 if (int compareBases =
856- compareDependentTypes (depMemTy1->getBase (), depMemTy2->getBase ()))
855+ compareDependentTypesRec (depMemTy1->getBase (), depMemTy2->getBase ()))
857856 return compareBases;
858857
859858 // - by name, so t_n_m.`P.T` < t_n_m.`P.U`
@@ -869,6 +868,17 @@ int swift::compareDependentTypes(Type type1, Type type2) {
869868 return 0 ;
870869}
871870
871+ // / Canonical ordering for type parameters.
872+ int swift::compareDependentTypes (Type type1, Type type2) {
873+ auto *root1 = type1->getRootGenericParam ();
874+ auto *root2 = type2->getRootGenericParam ();
875+ if (root1->getWeight () != root2->getWeight ()) {
876+ return root2->getWeight () ? -1 : +1 ;
877+ }
878+
879+ return compareDependentTypesRec (type1, type2);
880+ }
881+
872882#pragma mark Generic signature verification
873883
874884void GenericSignature::verify () const {
0 commit comments