Skip to content

Commit 6c22036

Browse files
committed
[CSSimplify] NFC: Perform assignments to a key path in a separate method
Previously key path type didn't have any requirements on their root and value types but now that they do, we need a dedicated place to perform an assignment and open/record all of the requirements.
1 parent f6c9177 commit 6c22036

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,6 +4186,21 @@ class ConstraintSystem {
41864186
bool resolveTapBody(TypeVariableType *typeVar, Type contextualType,
41874187
ConstraintLocatorBuilder locator);
41884188

4189+
/// Bind key path expression to the given contextual type and generate
4190+
/// constraints for its requirements.
4191+
///
4192+
/// \param typeVar The type variable representing the key path expression.
4193+
/// \param contextualType The contextual type this key path expression
4194+
/// would be bound to.
4195+
/// \param flags The flags associated with this assignment.
4196+
/// \param locator The locator associated with contextual type.
4197+
///
4198+
/// \returns `true` if it was possible to generate constraints for
4199+
/// the requirements and assign fixed type to the key path expression,
4200+
/// `false` otherwise.
4201+
bool resolveKeyPath(TypeVariableType *typeVar, Type contextualType,
4202+
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
4203+
41894204
/// Assign a fixed type to the given type variable.
41904205
///
41914206
/// \param typeVar The type variable to bind.

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,6 +4675,12 @@ ConstraintSystem::matchTypesBindTypeVar(
46754675
: getTypeMatchFailure(locator);
46764676
}
46774677

4678+
if (typeVar->getImpl().isKeyPathType()) {
4679+
return resolveKeyPath(typeVar, type, flags, locator)
4680+
? getTypeMatchSuccess()
4681+
: getTypeMatchFailure(locator);
4682+
}
4683+
46784684
assignFixedType(typeVar, type, /*updateState=*/true,
46794685
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
46804686

@@ -12257,6 +12263,15 @@ bool ConstraintSystem::resolveTapBody(TypeVariableType *typeVar,
1225712263
return !generateConstraints(tapExpr);
1225812264
}
1225912265

12266+
bool ConstraintSystem::resolveKeyPath(TypeVariableType *typeVar,
12267+
Type contextualType,
12268+
TypeMatchOptions flags,
12269+
ConstraintLocatorBuilder locator) {
12270+
assignFixedType(typeVar, contextualType, /*updateState=*/true,
12271+
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
12272+
return true;
12273+
}
12274+
1226012275
ConstraintSystem::SolutionKind
1226112276
ConstraintSystem::simplifyDynamicTypeOfConstraint(
1226212277
Type type1, Type type2,

0 commit comments

Comments
 (0)