-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
[ConstraintSystem] Introduce LValueObject
constraint to replace direct l-value assignments
#76174
Conversation
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.
@swift-ci please test |
@swift-ci please test source compatibility |
return formUnsolved(); | ||
|
||
// TODO: This operation deserves its own locator just like OptionalObject. | ||
addConstraint(ConstraintKind::Equal, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
…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".
168c008
to
dab01bc
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
@swift-ci please test |
@swift-ci please test macOS platform |
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 toOptionalObject
constraint) to set "object" type once l-value getsresolved, 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.