Skip to content

Commit a5da413

Browse files
committed
[ConstraintSystem] Simplify getFixedTypeRecursive a bit.
1 parent 4ac4d42 commit a5da413

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -700,34 +700,41 @@ bool ConstraintSystem::isAnyHashableType(Type type) {
700700
return false;
701701
}
702702

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+
703708
Type ConstraintSystem::getFixedTypeRecursive(Type type,
704709
TypeMatchOptions &flags,
705710
bool wantRValue,
706711
bool retainParens) {
707712

708-
if (wantRValue)
709-
type = type->getRValueType();
713+
// FIXME: This function doesn't strictly honor retainParens
714+
// everywhere.
710715

711716
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);
717724
}
718725
}
719726

720727
while (true) {
728+
if (wantRValue)
729+
type = type->getRValueType();
730+
721731
if (auto depMemType = type->getAs<DependentMemberType>()) {
722732
if (!depMemType->getBase()->isTypeVariableOrMember()) return type;
723733

724734
// FIXME: Perform a more limited simplification?
725735
Type newType = simplifyType(type);
726736
if (newType.getPointer() == type.getPointer()) return type;
727737

728-
if (wantRValue)
729-
newType = newType->getRValueType();
730-
731738
type = newType;
732739

733740
// Once we've simplified a dependent member type, we need to generate a
@@ -736,35 +743,21 @@ Type ConstraintSystem::getFixedTypeRecursive(Type type,
736743
continue;
737744
}
738745

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;
760749

761-
break;
750+
if (auto fixed = getFixedType(typeVar)) {
751+
type = fixed;
752+
continue;
762753
}
763754

764-
break;
765-
}
755+
if (retainParens)
756+
if (auto *parenType = dyn_cast<ParenType>(type.getPointer()))
757+
return withParens(*this, getRepresentative(typeVar), parenType);
766758

767-
return type;
759+
return getRepresentative(typeVar);
760+
}
768761
}
769762

770763
/// Does a var or subscript produce an l-value?

0 commit comments

Comments
 (0)