-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 infinite recursion on complex traits #106278
Conversation
The code previously only checked for cases like $0: Eq, $1: Eq, etc. Now it also works in cases where the type variables are buried in some data structure, like Union<$0, $1>: Eq.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) soon. Please see the contribution instructions for more information. |
r? types |
The first commit flagged things that weren't infinite recursion as such but after the second commit cases of infinite recursion are missed. I'll try to figure out how to make it just right tomorrow. |
This comment has been minimized.
This comment has been minimized.
Can you add a test for this? It also seems like the code as is introduces a regression for the typenum crate. |
@estebank I would like to add a test but I don't know where to add it. Where are tests generally located? My first commit flagged too many things as infinite recursion while the second one is too strict (which is what causes the typenum regression). It would be an improvement to detect infinite recursion if the old logic or the logic of the second commit detects it but it would affect performance. I'm looking for a more satisfying solution but I guess I should commit that solution to see if it avoids regressions. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
You'll want to add a file somewhere in Update: since I wrote this comment we have moved that directory to |
r? types |
This needs more investigation for the failing tests. Marking this as waiting-on-author, please comment @rustbot author |
@joonazan any updates here? Do you need any help moving investigating the failing tests? |
@jackh726 I tried to make a correct but slow version of the code but it was so slow that it wasn't able to run the tests. It looks like it would require a big rewrite to make a version that is as good as possible but not ridiculously slow. So yeah, the next step would be to go through each of the ICE caused by the new version to figure out if it is incorrect or if some other code that just happened to work with the old code needs to be fixed as well. I lost motivation when I reached that point. I want to finish this but I don't have much free time currently, so I don't know when. |
@joonazan any updates on this? |
☔ The latest upstream changes (presumably #113591) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
Fixes #39959.
As I explained in the issue, evaluate_stack in rustc_trait_selection::traits::select attempts to prevent infinite recursion when inferring types that satisfy traits but fails to do so. I got the details wrong, though.
The code previously only checked for cases like $0: Eq, $1: Eq, etc. Now it also works in cases where the type variables are buried in some
data structure, like Union<$0, $1>: Eq.
This should fix all the errors reported in the issue. It fixes my instance of the problem, at least.
There is another class of problem it does not fix: infinite recursion that never repeats the same pattern. Avoiding that one would require exploring the options in a BFS manner or using bounded DFS. I haven't heard of this happening in practice but it could be that people who would have run into it were too discouraged by this bug.
I should probably add some test for this. Where would I do that?