-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ConstraintSystem] (mostly) Finish up solver type cache implementation #13664
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
Conversation
@rudkx There is one thing left which is going to fix 2 crashers related to explicit casts - we still use |
@xedin I didn't do any work on I haven't looked at this for a while, but I believe you also need to clear the type on the Expr when it is cached to ensure that we aren't accidentally reading it in places. That was the real hold up the last time I looked at this. Can you hold off trying to merge this until I get done with the IUO changes? I suspect I've introduced some new |
@rudkx Sure, there is no rush in merging this, just wanted to get it out since tests are fixed. I has planning to take care of |
3cecd97
to
5d10771
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
/cc @rudkx |
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'd like to have a better understanding of some of the changes and why we see behavioral changes here before we merge anything for this.
|
||
auto type = loc.getType(); | ||
if (!type) | ||
type = cs.getType(loc); |
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 directly calling loc.getType()
and then only if getting null
calling cs.getType(loc)
?
var a = 3 | ||
var b = 4 | ||
var c = (3) | ||
var d = (a, b) |
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.
It seems like there is something wrong if this is resulting in this type of diagnostic change.
@@ -119,7 +119,6 @@ func testExplicitConstructors3P() { | |||
// EXPLICIT_CONSTRUCTORS_3P: Begin completions | |||
// EXPLICIT_CONSTRUCTORS_3P-DAG: Decl[Constructor]/CurrNominal: ['(']{#(a): Int#}[')'][#ExplicitConstructors3#]{{; name=.+$}} | |||
// EXPLICIT_CONSTRUCTORS_3P-DAG: Decl[Constructor]/CurrNominal: ['(']{#a: Int#}, {#b: Float#}[')'][#ExplicitConstructors3#]{{; name=.+$}} | |||
// EXPLICIT_CONSTRUCTORS_3P-DAG: Decl[FreeFunction]/CurrModule/NotRecommended/TypeRelation[Invalid]: freeFunc()[#Void#]{{; name=.+$}} |
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.
So I am wondering how the code completion changes (which I haven't looked at closely) are related to the type cache. I would expect no behavioral changes from making the type checker store types in a different place.
@@ -2153,6 +2153,8 @@ static void eraseOpenedExistentials(Expr *&expr, ConstraintSystem &CS) { | |||
return type; | |||
}); | |||
CS.setType(expr, type); | |||
// Set new type to the expression directly. | |||
expr->setType(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.
It's non-obvious why this is the right thing to do. This seems like an indication that something that should be reading from the type cache isn't.
@@ -7481,6 +7481,7 @@ namespace { | |||
} else { | |||
// For other closures, type-check the body once we've finished with | |||
// the expression. | |||
cs.setExprTypes(closure); |
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.
Under what circumstances do we need to do this? We should be type checking these bodies independently. They can refer to captured data, but that data should already have a type, right?
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.
We had a chance to sync up on this and everything looks okay for now. It definitely moves things forward re: fixing some crashers and no longer writing types all over the place. We still need to go back and clear expression types, etc. to finish this up.
… found Resolves: rdar://problem/36744895
This is useful for explicit casts and type expressions, where type loc and expression types might be different, and allows constraint solver to avoid setting opened types to expressions which resolves multiple crashes.
5d10771
to
8c17b92
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@rudkx looks like everything is green, going to merge a bit later today |
@swift-ci please smoke test |
Based on all of the great work @rudkx has done, solver should only apply final types
to the expression tree when the solution is deduced. This patch makes it so and fixes
tests (mostly in IDE code completion) along the way.