Skip to content

[ConstraintSystem] Introduce LValueObject constraint to replace direct l-value assignments #76174

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 30, 2024

Instead having to eagerly bind type variables to l-value types
like it currently happens during constraint generation for assignment
expressions, let's use new LValueObject constraint (similar to
OptionalObject constraint) to set "object" type once l-value gets
resolved, this allows the solver to infer types and/or resolve overloads
during solving and detect failures related to l-value in one spot.

This makes mismatches easier to diagnose during solving and allows
to simplify some of the logic in constraint generator, inference, and
disjunction favoring.

xedin added 3 commits August 29, 2024 10:10
This aims to help with cases like `_ = { x in x = 0 }` or `.test = 42`
which are currently supported because the member is eagerly bound to
an `@lvalue $T` during constraint generation.
@xedin xedin requested a review from hamishknight August 30, 2024 16:38
@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2024

@swift-ci please test source compatibility

return formUnsolved();

// TODO: This operation deserves its own locator just like OptionalObject.
addConstraint(ConstraintKind::Equal,
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, does Bind not work here? I would expect that we shouldn't end up with nested lvalues or anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the Bind would work here the same way, I just prefer Equal in this case since the type could be bound from context as well which really means that it's an equality operation more than a Bind.

xedin added 4 commits August 30, 2024 15:39
…laceholder

Placeholders propagate but we still can allow contextual inference,
to facilitate that the solver should consider `l-value object` constraint
to be solved and allow placeholders on "object" type.
…text

Re-implements swiftlang#76115 in
a simpler fashion now that we don't have to eagerly binding destination
type on l-value.
…mber settability

Increases the default score of the `treat r-value as l-value`
and decrease the impact if the immediate member is settable
because that means that the problem is somewhere in the "base".
@xedin xedin force-pushed the remodel-constraint-generation-for-assignment branch from 168c008 to dab01bc Compare August 30, 2024 22:39
@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2024

@swift-ci please test source compatibility

1 similar comment
@xedin
Copy link
Contributor Author

xedin commented Sep 2, 2024

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Sep 2, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 3, 2024

@swift-ci please test macOS platform

@xedin xedin merged commit f9e08bc into swiftlang:main Sep 4, 2024
7 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