@@ -1721,14 +1721,29 @@ void Solution::recordSingleArgMatchingChoice(ConstraintLocator *locator) {
1721
1721
MatchCallArgumentResult::forArity (1 )});
1722
1722
}
1723
1723
1724
- Type Solution::simplifyType (Type type) const {
1724
+ Type Solution::simplifyType (Type type, bool wantInterfaceType) const {
1725
+ // If we've been asked for an interface type, start by mapping any archetypes
1726
+ // out of context.
1727
+ if (wantInterfaceType)
1728
+ type = type->mapTypeOutOfContext ();
1729
+
1725
1730
if (!(type->hasTypeVariable () || type->hasPlaceholder ()))
1726
1731
return type;
1727
1732
1728
1733
// Map type variables to fixed types from bindings.
1729
1734
auto &cs = getConstraintSystem ();
1730
- auto resolvedType = cs.simplifyTypeImpl (
1731
- type, [&](TypeVariableType *tvt) -> Type { return getFixedType (tvt); });
1735
+ auto resolvedType =
1736
+ cs.simplifyTypeImpl (type, [&](TypeVariableType *tvt) -> Type {
1737
+ // If we want the interface type, use the generic parameter if we
1738
+ // have one, otherwise map the fixed type out of context.
1739
+ if (wantInterfaceType) {
1740
+ if (auto *gp = tvt->getImpl ().getGenericParameter ())
1741
+ return gp;
1742
+ return getFixedType (tvt)->mapTypeOutOfContext ();
1743
+ }
1744
+ return getFixedType (tvt);
1745
+ });
1746
+ ASSERT (!(wantInterfaceType && resolvedType->hasPrimaryArchetype ()));
1732
1747
1733
1748
// Placeholders shouldn't be reachable through a solution, they are only
1734
1749
// useful to determine what went wrong exactly.
@@ -4007,32 +4022,6 @@ ASTNode ConstraintSystem::includingParentApply(ASTNode node) {
4007
4022
return node;
4008
4023
}
4009
4024
4010
- Type Solution::resolveInterfaceType (Type type) const {
4011
- auto resolvedType = type.transformRec ([&](Type type) -> std::optional<Type> {
4012
- if (auto *tvt = type->getAs <TypeVariableType>()) {
4013
- // If this type variable is for a generic parameter, return that.
4014
- if (auto *gp = tvt->getImpl ().getGenericParameter ())
4015
- return gp;
4016
-
4017
- // Otherwise resolve its fixed type, mapped out of context.
4018
- auto fixed = simplifyType (tvt);
4019
- return resolveInterfaceType (fixed->mapTypeOutOfContext ());
4020
- }
4021
- if (auto *dmt = type->getAs <DependentMemberType>()) {
4022
- // For a dependent member, first resolve the base.
4023
- auto newBase = resolveInterfaceType (dmt->getBase ());
4024
-
4025
- // Then reconstruct using its associated type.
4026
- assert (dmt->getAssocType ());
4027
- return DependentMemberType::get (newBase, dmt->getAssocType ());
4028
- }
4029
- return std::nullopt;
4030
- });
4031
-
4032
- assert (!resolvedType->hasArchetype ());
4033
- return resolvedType;
4034
- }
4035
-
4036
4025
std::optional<FunctionArgApplyInfo>
4037
4026
Solution::getFunctionArgApplyInfo (ConstraintLocator *locator) const {
4038
4027
// It's only valid to use `&` in argument positions, but we need
@@ -4125,13 +4114,12 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
4125
4114
auto *callee = choice ? choice->getDeclOrNull () : nullptr ;
4126
4115
if (callee && callee->hasInterfaceType ()) {
4127
4116
// If we have a callee with an interface type, we can use it. This is
4128
- // preferable to resolveInterfaceType , as this will allow us to get a
4129
- // GenericFunctionType for generic decls.
4117
+ // preferable to simplifyType for the function , as this will allow us to get
4118
+ // a GenericFunctionType for generic decls.
4130
4119
//
4131
4120
// Note that it's possible to find a callee without an interface type. This
4132
4121
// can happen for example with closure parameters, where the interface type
4133
- // isn't set until the solution is applied. In that case, use
4134
- // resolveInterfaceType.
4122
+ // isn't set until the solution is applied. In that case, use simplifyType.
4135
4123
fnInterfaceType = callee->getInterfaceType ();
4136
4124
4137
4125
// Strip off the curried self parameter if necessary.
@@ -4152,7 +4140,7 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
4152
4140
}
4153
4141
#endif
4154
4142
} else {
4155
- fnInterfaceType = resolveInterfaceType (rawFnType);
4143
+ fnInterfaceType = simplifyType (rawFnType, /* wantInterfaceType */ true );
4156
4144
}
4157
4145
4158
4146
auto argIdx = applyArgElt->getArgIdx ();
0 commit comments