-
Notifications
You must be signed in to change notification settings - Fork 182
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
Include more guidance in ambiguous results #433
Conversation
Made some changes that seem to work for the slg solver, but I still need to clean it up into something presentable. |
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.
The recursive solver part LGTM, for the SLG part @jackh726 or @nikomatsakis would need to take a look. You wrote you still wanted to clean it up, is that still the case or is this ready for review?
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.
Nice :)
Some comments, but overall I think I like the approach
I'm also curious if this has any effect on the issue here: #331 |
Okay, so after looking around a bit, I think I'm convinced that this isn't quite correct on the SLG side. Particularly, I think that adding answers when there are still floundered subgoals is not possible to do correctly yet. This seems to work if you don't push an ambiguous trivial substitution. But I think that's because we don't have any test cases that have a non-ambiguous non-trivial substitution for a strand with all floundered subgoals and will eventually get solved later. |
I'm not quite sure the best way to approach this though. Part of me wonders if, instead of adding incomplete (meaning there are still floundered subgoals) answers always, we instead only do this if we can no longer make progress anywhere. I think we can do this by essentially doing two passes for subgoals: once where subgoals can't create ambiguous or incomplete answers, then a second where they can. (I wonder if it's even worth splitting this into three: one "complete and umabiguous", one "complete and ambiguous", and one "incomplete and ambiguous"). I guess I have to think if we have to do this globally or if per-Strand is enough. (i.e. if another Strand is followed, will subgoals of the current Strand ever become non-ambiguous. I think the answer is no, but have to look.) Edit: right, we only reconsider floundered subgoals if there are new answers to the current Strand |
I have a partial fix for this locally. It fixed |
Okay I completed the fix. (You can see them here: master...jackh726:add-more-guidance) I essentially split answer generation into "complete" and "ambiguous" phases. Basically, we always be sure to process non-ambiguous answers first. For the purposes of answers, any answer we get from strands with all floundered subgoals is ambiguous (which like in this PR we actually use). In general, it needs a bit more cleaning up before it can be used/merged. A couple things to start:
It might be worth splitting my changes out into a separate PR before this since it's kind of a lot on it's own, but also technically an independent fix. |
Cool, thanks! Either way sounds good to me. I could start working on some of the cleanup of your branch? |
@adamrk I think I can finish the cleanup pretty soon. Did you enable the option for me to be able to push to your branch? Also, these changes fix the tests in #331. Which is fantastic because this highlights that the changes here are a little bit more fundamental to how we handle ambiguous answers than just including more guidance :) |
Sounds good! Yeah I turned on edits by maintainers. |
Okay, done with cleanups. @nikomatsakis care to take a look at this? A quick summary/tldr of this thread and PR: This was basically done to fix this case: chalk/chalk-engine/src/table.rs Line 138 in 80c17b8
This also has the side-effect of fixing some other tests as well, including those from #331 and #429, so these changes definitely are a bit more fundamental to how we handle ambiguous answers than just giving some extra guidance. |
…bstitution, since this is the best we can ever do
There are situations where chalk a query is ambiguous and chalk returns
Ambig(Guidance::Unknown)
even though it has deduced some non-trivial substitutions. For example, with this program:the query
exists<T,U> { A<T>: Trait<U> }
flounders because we can't determine if there is a solution toT: Constraint
and the result isAmbig(Guidance::Unknown)
. But even with an ambiguous result we should still be able to return the guidance thatT = U
.The ambiguous guidance in situations like this will be useful in rust-analyzer where some queries flounder because all traits are treated as
non_enumerable
(see e.g. rust-lang/rust-analyzer#4072).The changes here check if any substitutions have been deduced when a goal flounders and returning an ambiguous guidance if the substitutions deduced so far are non-trivial.
Closes #331
Closes #429