mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Change FailureDiagnostic::resolveType to replace
holes with generic parameters directly when possible.
This commit is contained in:
@@ -2250,9 +2250,8 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
Type simplifyTypeImpl(const ConstraintSystem &cs, Type type,
|
||||
Fn getFixedTypeFn) {
|
||||
Type ConstraintSystem::simplifyTypeImpl(Type type,
|
||||
llvm::function_ref<Type(TypeVariableType *)> getFixedTypeFn) const {
|
||||
return type.transform([&](Type type) -> Type {
|
||||
if (auto tvt = dyn_cast<TypeVariableType>(type.getPointer()))
|
||||
return getFixedTypeFn(tvt);
|
||||
@@ -2261,7 +2260,7 @@ Type simplifyTypeImpl(const ConstraintSystem &cs, Type type,
|
||||
// the base to a non-type-variable, perform lookup.
|
||||
if (auto depMemTy = dyn_cast<DependentMemberType>(type.getPointer())) {
|
||||
// Simplify the base.
|
||||
Type newBase = simplifyTypeImpl(cs, depMemTy->getBase(), getFixedTypeFn);
|
||||
Type newBase = simplifyTypeImpl(depMemTy->getBase(), getFixedTypeFn);
|
||||
|
||||
// If nothing changed, we're done.
|
||||
if (newBase.getPointer() == depMemTy->getBase().getPointer())
|
||||
@@ -2279,7 +2278,7 @@ Type simplifyTypeImpl(const ConstraintSystem &cs, Type type,
|
||||
|
||||
if (lookupBaseType->mayHaveMembers()) {
|
||||
auto *proto = assocType->getProtocol();
|
||||
auto conformance = cs.DC->getParentModule()->lookupConformance(
|
||||
auto conformance = DC->getParentModule()->lookupConformance(
|
||||
lookupBaseType, proto);
|
||||
if (!conformance)
|
||||
return DependentMemberType::get(lookupBaseType, assocType);
|
||||
@@ -2298,21 +2297,15 @@ Type simplifyTypeImpl(const ConstraintSystem &cs, Type type,
|
||||
});
|
||||
}
|
||||
|
||||
Type ConstraintSystem::simplifyType(Type type, bool forDiagnostics) const {
|
||||
Type ConstraintSystem::simplifyType(Type type) const {
|
||||
if (!type->hasTypeVariable())
|
||||
return type;
|
||||
|
||||
// Map type variables down to the fixed types of their representatives.
|
||||
return simplifyTypeImpl(
|
||||
*this, type,
|
||||
return simplifyTypeImpl(type,
|
||||
[&](TypeVariableType *tvt) -> Type {
|
||||
if (auto fixed = getFixedType(tvt)) {
|
||||
if (forDiagnostics && fixed->isHole() &&
|
||||
tvt->getImpl().getLocator()->isForGenericParameter())
|
||||
return tvt->getImpl().getLocator()->getGenericParameter();
|
||||
|
||||
if (auto fixed = getFixedType(tvt))
|
||||
return simplifyType(fixed);
|
||||
}
|
||||
|
||||
return getRepresentative(tvt);
|
||||
});
|
||||
@@ -2323,8 +2316,7 @@ Type Solution::simplifyType(Type type) const {
|
||||
return type;
|
||||
|
||||
// Map type variables to fixed types from bindings.
|
||||
return simplifyTypeImpl(
|
||||
getConstraintSystem(), type,
|
||||
return getConstraintSystem().simplifyTypeImpl(type,
|
||||
[&](TypeVariableType *tvt) -> Type {
|
||||
auto known = typeBindings.find(tvt);
|
||||
assert(known != typeBindings.end());
|
||||
|
||||
Reference in New Issue
Block a user