-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix type inference related to upvars in closures #21353
Conversation
r? @Aatch (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -1471,6 +1471,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |||
return Ok(ParameterBuiltin); | |||
} | |||
|
|||
// Whether upvars are sized is checked elsewhere |
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.
Do you mind say where they're checked? "Elsewhere" tends to be kind of frustrating when looking at these comments.
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.
They are checked in numerous places... @nikomatsakis, do you have better ideas how to word this?
I'm not sure what to make of this patch. Some thoughts:
@sanxiyn have you traced out just where the error is cropping up that you are preventing? |
As far as I understand, 3 is correct. The error comes from checking IntVar: Sized before i32 fallback. |
OK, so, I started digging into the problem. I think it is a bug in the caching algorithm. I am double-checking, but I think the problem is that when we ask to get the list of upvar types for a closure, in some cases we do not yet know the result. This is because we haven't run all the inference we are going to need to figure everything out. This yields an ambiguous result -- which is generally the correct thing to do, and should not (typically) be harmful. However, in this case, what happens is that the ambiguous result gets cached -- again, not (typically) harmful, because normally the cache key is careful to note what parts needed more inference, so when more inference has been done, that cache entry no longer matches. (Example: |
That said, this patch may still be a good optimization. But I'd prefer to land the full fix first. I'll prepare a PR now. |
taking liberty of re-assigning responsibility for this patch to me |
This is waiting on #21523. |
So the crucial underlying problem should be fixed now. Now the question is whether this patch on its own makes sense as a kind of optimization. |
I have updated a comment as suggested. |
Fix #20558.