-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Sema: Better prepared overloads #84339
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
Sema: Better prepared overloads #84339
Conversation
3a0ab19
to
1ea7382
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
@swift-ci Please test Linux |
… look like FuncDecl case
getTypeOfMemberReference() already opens the accessor's thrown error type for us.
1ea7382
to
98d0ea5
Compare
…t Post() versions
swiftlang/swift-package-manager#9150 |
@swift-ci Please smoke test macOS |
@swift-ci Please test Windows |
@swift-ci Please test source compatibility |
ASSERT(type && "Expected non-null type"); | ||
|
||
if (preparedOverload) { | ||
preparedOverload->recordedNodeType(node, type); |
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.
Why is this necessary?
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.
Because property wrapper application happens as part of getTypeOfMemberReference() and it calls setType(), so we have to record it and play it back.
cs.addConstraint(ConstraintKind::Bind, typeVar, subst(gp), locator); | ||
for (auto [gp, typeVar] : replacements) { | ||
cs.addConstraint(ConstraintKind::Bind, typeVar, subst(gp), locator, | ||
/*isFavored=*/false, preparedOverload); |
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'm not a big fan of the fact that we have to add prepared overloads to all these various APIs, including addConstraint
. I think prepared overloads belong in the solver not in the constraint system.
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.
Once getTypeOf{Member,}Reference() are always called with preparedOverload != nullptr, I'm planning on changing a bunch of APIs that currently take an optional preparedOverload to be methods on the PreparedOverloadBuilder itself, since in those places we'll always be able to call it on a builder that is provided. I agree it is annoying to have to plumb it through to intercept various places that would otherwise record trail changes, but I hope to separate the two code paths completely (edit: well, probably not 100%) at some point.
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.
Alright, let's see how it turns out.
Also, move some methods from ConstraintSystem.h to ConstraintSystem.cpp.
98d0ea5
to
e9070cf
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
@swift-ci Please smoke test macOS |
…verloads Sema: Better prepared overloads
This PR is another intermediate step on my quest to simplify getTypeOfReference()/getTypeOfMemberReference().
These functions are used in exactly two places: when applying a disjunction choice inside the solver, and in protocol witness matching. I cleaned up the latter code path a bit to make it look more like what happens in the solver, and this allowed me to simplify the parameter lists of both functions a fair bit; both take an OverloadChoice now.
The Pre()/Post() split is transitional and I'm going to re-organize this a little bit more, but I'd like to land this separately and test source compatibility first.