Skip to content

[CSSimplify] Open key path type before assignment to its record requirements #80081

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 5 commits into from
Mar 19, 2025

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Mar 18, 2025

Root and Value generic parameters now have conformance requirements
which we need to account for post-binding inference.

Resolves: rdar://143161190

xedin added 2 commits March 17, 2025 14:06
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.
…rements

`Root` and `Value` generic parameters now have conformance requirements
which we need to account for post-binding inference.
@xedin
Copy link
Contributor Author

xedin commented Mar 18, 2025

@swift-ci please test

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented Mar 18, 2025

@swift-ci please test

@@ -4675,6 +4675,12 @@ ConstraintSystem::matchTypesBindTypeVar(
: getTypeMatchFailure(locator);
}

if (typeVar->getImpl().isKeyPathType()) {
return resolveKeyPath(typeVar, type, flags, locator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this in matchTypesBindTypeVar() seems wrong. Why can't you generate these constraints when the type variable is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is created by inference, it's not possible to generate constraints then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key paths are special in a way that we need to infer capability from the members in the chain before we can form the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To elaborate more, when type variable is created there is no type for it. The type we get here is purely synthetic, formed by inference based on capabilities inferred from members referenced in a key path, which means that the type wasn't previously "opened" like in other places and has to be opened before it's assigned. I agree that this is unfortunate and we'd need a better way to express this but I don't see how we can do that without significant changes to inference.

@xedin
Copy link
Contributor Author

xedin commented Mar 18, 2025

@swift-ci please test

@xedin xedin merged commit 552106d into swiftlang:main Mar 19, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants