Skip to content

[ConstraintSystem] Initial rework of key path inference #69405

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 13 commits into from
Nov 2, 2023

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Oct 25, 2023

Depends on #69292

  • Setup a fallback type for a key path that is going to be used as a base for capability inference.

  • If key path has no direct contextual bindings attempt to infer its capabilities and form a binding
    based on a previously established fallback type (default capability is ReadOnly).

  • Delay KeyPath constraint simplification until key path type has been bound.

    This means that the inference now drives key path simplification and problems
    with eager key path binding are resolved (because type variables are already
    delayed if they are connected to an ApplicableFunction or Disjunction constraint).

Next steps:

  • Allow transitive inference of key path root type through key path type bindings
  • Delay key path type binding until capability is established (depends on the previous step)
  • Unify contextual bindings (if any) with a type inferred based on key path literal
    capabilities. This means that we would no longer need to:
    • Bind a resolved type to a contextual type at the end of simplification.
    • A hack that allows capability downgrades in certain cases
      (i.e. when contextual type is read-only but key path itself is writable)

@xedin xedin requested a review from Jumhyn October 25, 2023 17:13
@xedin
Copy link
Contributor Author

xedin commented Oct 25, 2023

cc @amritpan

@xedin
Copy link
Contributor Author

xedin commented Oct 25, 2023

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Oct 25, 2023

@swift-ci please test Linux platform

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented Oct 26, 2023

@swift-ci please test Linux platform

xedin added 13 commits November 1, 2023 09:14
This is a very first step in attempt to move some of the logic
from `simplifyKeyPathConstraint` to the inference. This type is
going to be used as an anchor to trigger capability inference.
If there are no contextual types available but capability of
key path could be inferred, let's turn default into a real
binding.
…th type is bound

Let the inference drive key path literal resolution, this fixes
a problem where key path is bound too eagerly.
Detect that diagnose key path literals that do not have any components.
Since key path type is always bound by inference before the
constraint could be simplified, there is no need to search
for a contextual type or try to bind key path type if there
are errors in the path.
Make sure that contextual mismatch uses a correct locator when
the issue is with key path value type instead of the key path
type.
…ed root types

Covariant conversions between explicit and contextual/inferred root
types of a key path are simulated through a subtype constraint which
has to be attached to a `KeyPathRoot` element.
…her key path is invalid

This flag makes it easier to determine what binding to produce
from the default. In cases where some of the member references
are invalid it's better to produce a placeholder for a key
path type instead of letting the solver to attempt to fix more
contextual problems for a broken key path.
Move some of the checks from the constraint simplification into
`inferKeyPathLiteralCapability` and start using it for both
inference and constraint simplification.
@xedin xedin force-pushed the rework-keypath-type-inference branch from 8a460aa to 7363812 Compare November 1, 2023 16:15
@xedin
Copy link
Contributor Author

xedin commented Nov 1, 2023

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Nov 1, 2023

@swift-ci please test source compatibility

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2023

@swift-ci please test source compatibility

@xedin xedin merged commit ca53be7 into swiftlang:main Nov 2, 2023
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.

1 participant