Skip to content

Commit 1d8e7ef

Browse files
author
Amritpan Kaur
committed
[CSGen] Record keypath for use across constraint system.
1 parent dab7dbf commit 1d8e7ef

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,11 @@ class ConstraintSystem {
34203420
void recordCallAsFunction(UnresolvedDotExpr *root, ArgumentList *arguments,
34213421
ConstraintLocator *locator);
34223422

3423+
/// Record root, value, and declContext of keypath expression for use across
3424+
/// constraint system.
3425+
void recordKeyPath(KeyPathExpr *keypath, TypeVariableType *root,
3426+
TypeVariableType *value, DeclContext *dc);
3427+
34233428
/// Walk a closure AST to determine its effects.
34243429
///
34253430
/// \returns a function's extended info describing the effects, as

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,8 +3607,8 @@ namespace {
36073607
auto rootLocator =
36083608
CS.getConstraintLocator(E, ConstraintLocator::KeyPathRoot);
36093609
auto locator = CS.getConstraintLocator(E);
3610-
Type root = CS.createTypeVariable(rootLocator, TVO_CanBindToNoEscape |
3611-
TVO_CanBindToHole);
3610+
auto *root = CS.createTypeVariable(rootLocator, TVO_CanBindToNoEscape |
3611+
TVO_CanBindToHole);
36123612

36133613
// If a root type was explicitly given, then resolve it now.
36143614
if (auto rootRepr = E->getRootType()) {
@@ -3747,9 +3747,10 @@ namespace {
37473747

37483748
auto valueLocator =
37493749
CS.getConstraintLocator(E, ConstraintLocator::KeyPathValue);
3750-
auto value = CS.createTypeVariable(valueLocator, TVO_CanBindToNoEscape |
3751-
TVO_CanBindToHole);
3750+
auto *value = CS.createTypeVariable(valueLocator, TVO_CanBindToNoEscape |
3751+
TVO_CanBindToHole);
37523752
CS.addConstraint(ConstraintKind::Equal, base, value, locator);
3753+
CS.recordKeyPath(E, root, value, CurDC);
37533754

37543755
// The result is a KeyPath from the root to the end component.
37553756
// The type of key path depends on the overloads chosen for the key
@@ -3761,6 +3762,7 @@ namespace {
37613762
TVO_CanBindToHole);
37623763

37633764
CS.addKeyPathConstraint(kpTy, root, value, componentTypeVars, locator);
3765+
37643766
return kpTy;
37653767
}
37663768

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14536,6 +14536,12 @@ void ConstraintSystem::recordCallAsFunction(UnresolvedDotExpr *root,
1453614536
getConstraintLocator(root, ConstraintLocator::ApplyArgument), arguments);
1453714537
}
1453814538

14539+
void ConstraintSystem::recordKeyPath(KeyPathExpr *keypath,
14540+
TypeVariableType *root,
14541+
TypeVariableType *value, DeclContext *dc) {
14542+
KeyPaths.insert(std::make_pair(keypath, std::make_tuple(root, value, dc)));
14543+
}
14544+
1453914545
ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1454014546
ConstraintFix *fix, Type type1, Type type2, ConstraintKind matchKind,
1454114547
TypeMatchOptions flags, ConstraintLocatorBuilder locator) {

0 commit comments

Comments
 (0)