@@ -700,34 +700,41 @@ bool ConstraintSystem::isAnyHashableType(Type type) {
700
700
return false ;
701
701
}
702
702
703
+ static Type withParens (ConstraintSystem &cs, Type type, ParenType *parenType) {
704
+ auto flags = parenType->getParameterFlags ().withInOut (type->is <InOutType>());
705
+ return ParenType::get (cs.getASTContext (), type->getInOutObjectType (), flags);
706
+ }
707
+
703
708
Type ConstraintSystem::getFixedTypeRecursive (Type type,
704
709
TypeMatchOptions &flags,
705
710
bool wantRValue,
706
711
bool retainParens) {
707
712
708
- if (wantRValue)
709
- type = type-> getRValueType ();
713
+ // FIXME: This function doesn't strictly honor retainParens
714
+ // everywhere.
710
715
711
716
if (retainParens) {
712
- if (auto parenTy = dyn_cast<ParenType>(type.getPointer ())) {
713
- type = getFixedTypeRecursive (parenTy->getUnderlyingType (), flags,
714
- wantRValue, retainParens);
715
- auto flags = parenTy->getParameterFlags ().withInOut (type->is <InOutType>());
716
- return ParenType::get (getASTContext (), type->getInOutObjectType (), flags);
717
+ if (wantRValue)
718
+ type = type->getRValueType ();
719
+
720
+ if (auto *parenTy = dyn_cast<ParenType>(type.getPointer ())) {
721
+ auto fixed = getFixedTypeRecursive (parenTy->getUnderlyingType (), flags,
722
+ wantRValue, retainParens);
723
+ return withParens (*this , fixed, parenTy);
717
724
}
718
725
}
719
726
720
727
while (true ) {
728
+ if (wantRValue)
729
+ type = type->getRValueType ();
730
+
721
731
if (auto depMemType = type->getAs <DependentMemberType>()) {
722
732
if (!depMemType->getBase ()->isTypeVariableOrMember ()) return type;
723
733
724
734
// FIXME: Perform a more limited simplification?
725
735
Type newType = simplifyType (type);
726
736
if (newType.getPointer () == type.getPointer ()) return type;
727
737
728
- if (wantRValue)
729
- newType = newType->getRValueType ();
730
-
731
738
type = newType;
732
739
733
740
// Once we've simplified a dependent member type, we need to generate a
@@ -736,35 +743,21 @@ Type ConstraintSystem::getFixedTypeRecursive(Type type,
736
743
continue ;
737
744
}
738
745
739
- if (auto typeVar = type->getAs <TypeVariableType>()) {
740
- bool hasRepresentative = false ;
741
- if (auto *repr = getRepresentative (typeVar)) {
742
- if (typeVar != repr) {
743
- hasRepresentative = true ;
744
- typeVar = repr;
745
- }
746
- }
747
-
748
- if (auto fixed = getFixedType (typeVar)) {
749
- if (wantRValue)
750
- fixed = fixed->getRValueType ();
751
-
752
- type = fixed;
753
- continue ;
754
- }
755
-
756
- // If type variable has a representative but
757
- // no fixed type, reflect that in the type itself.
758
- if (hasRepresentative)
759
- type = typeVar;
746
+ auto typeVar = type->getAs <TypeVariableType>();
747
+ if (!typeVar)
748
+ return type;
760
749
761
- break ;
750
+ if (auto fixed = getFixedType (typeVar)) {
751
+ type = fixed;
752
+ continue ;
762
753
}
763
754
764
- break ;
765
- }
755
+ if (retainParens)
756
+ if (auto *parenType = dyn_cast<ParenType>(type.getPointer ()))
757
+ return withParens (*this , getRepresentative (typeVar), parenType);
766
758
767
- return type;
759
+ return getRepresentative (typeVar);
760
+ }
768
761
}
769
762
770
763
// / Does a var or subscript produce an l-value?
@@ -2022,12 +2015,10 @@ Type ConstraintSystem::simplifyType(Type type) {
2022
2015
return simplifyTypeImpl (
2023
2016
*this , type,
2024
2017
[&](TypeVariableType *tvt) -> Type {
2025
- tvt = getRepresentative (tvt);
2026
- if (auto fixed = getFixedType (tvt)) {
2018
+ if (auto fixed = getFixedType (tvt))
2027
2019
return simplifyType (fixed);
2028
- }
2029
2020
2030
- return tvt;
2021
+ return getRepresentative ( tvt) ;
2031
2022
});
2032
2023
}
2033
2024
0 commit comments