Skip to content

[ConstraintSystem] Simplify getFixedTypeRecursive a little. #18478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,54 +710,39 @@ Type ConstraintSystem::getFixedTypeRecursive(Type type,
bool wantRValue,
bool retainParens) {

// FIXME: This function doesn't strictly honor retainParens
// everywhere.
if (wantRValue)
type = type->getRValueType();

if (retainParens) {
if (wantRValue)
type = type->getRValueType();

if (auto *parenTy = dyn_cast<ParenType>(type.getPointer())) {
if (auto *parenTy = dyn_cast<ParenType>(type.getPointer())) {
if (retainParens) {
auto fixed = getFixedTypeRecursive(parenTy->getUnderlyingType(), flags,
wantRValue, retainParens);
return withParens(*this, fixed, parenTy);
}
}

while (true) {
if (wantRValue)
type = type->getRValueType();

if (auto depMemType = type->getAs<DependentMemberType>()) {
if (!depMemType->getBase()->isTypeVariableOrMember()) return type;
if (auto depMemType = type->getAs<DependentMemberType>()) {
if (!depMemType->getBase()->isTypeVariableOrMember()) return type;

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

type = newType;

// Once we've simplified a dependent member type, we need to generate a
// new constraint.
flags |= TMF_GenerateConstraints;
continue;
}

auto typeVar = type->getAs<TypeVariableType>();
if (!typeVar)
return type;
// Once we've simplified a dependent member type, we need to generate a
// new constraint.
flags |= TMF_GenerateConstraints;

if (auto fixed = getFixedType(typeVar)) {
type = fixed;
continue;
}
return getFixedTypeRecursive(newType, flags, wantRValue, retainParens);
}

if (retainParens)
if (auto *parenType = dyn_cast<ParenType>(type.getPointer()))
return withParens(*this, getRepresentative(typeVar), parenType);
if (auto typeVar = type->getAs<TypeVariableType>()) {
if (auto fixed = getFixedType(typeVar))
return getFixedTypeRecursive(fixed, flags, wantRValue, retainParens);

return getRepresentative(typeVar);
}

return type;
}

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