Skip to content

Don't flounder on int/float vars #555

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

Merged
merged 3 commits into from
Jul 11, 2020

Conversation

flodiebold
Copy link
Member

If the self type in our goal is e.g. an int var, we don't need to flounder even if the trait is non-enumerable because the search can still be restricted to a few types (rustc can do this already).

This works with the SLG solver, but the recursive solver passes goals to the program clauses code before instantiating them, and from just the BoundVars we can't tell their kind. Maybe we need to change the recursive solver to instantiate first after all? @nikomatsakis any ideas / suggestions?

@nikomatsakis
Copy link
Contributor

I've come to think that the recursive solver's approach, of asking for program clauses before instantiation, is more correct. We could just pass the canonical binders as well, so that it can inspect the variable kinds.

@flodiebold
Copy link
Member Author

We could just pass the canonical binders as well, so that it can inspect the variable kinds.

I think a prerequisite for that would be to convert the SLG solver to also ask for clauses before instantiation, probably? Since it requires changing the interface to take a Canonical.

@flodiebold flodiebold force-pushed the integer-var-floundering branch from fc0ee17 to a3b372c Compare July 10, 2020 14:59
@flodiebold flodiebold marked this pull request as ready for review July 10, 2020 14:59
@flodiebold
Copy link
Member Author

@jackh726 @nikomatsakis here's a variant that works and avoids refactoring the SLG solver for now. It's slightly hacky, but maybe good enough until we can get the two solvers aligned?

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the changes here are simple enough. I would like to think more about long term whether we do want to get program clauses before or after instantiation and why. I don't necessarily have a good opinion either way right now, so I'm curious to here about @nikomatsakis's thoughts.

In any case, I'm okay with merging this now with both a FIXME or comment added (probably in program_clauses_for_goal in clauses) about the use of binders. Also, I would like an issue filed for followup. @flodiebold feel free to merge after that

If the self type in our goal is e.g. an int var, we don't need to flounder even
if the trait is non-enumerable because the search can still be restricted to a
few types (rustc can do this already).
To achieve this, we pass the binders. It's slightly hacky; it would be nicer if
we could just pass the `Canonical`, but that would require the SLG solver to
pass a canonicalized goal, which it doesn't currently. So passing the binders
separately feels slightly less bad.
@flodiebold flodiebold force-pushed the integer-var-floundering branch from a3b372c to 7c91b70 Compare July 10, 2020 20:11
The impl search code needs to be able to tell that it's just looking for
int/float impls.
@flodiebold
Copy link
Member Author

Added the FIXME. I also realized that the impls_for_trait code needs the binders, so I added them as a parameter to the method.

@jackh726
Copy link
Member

Where does impls_for_trait need the binders?

@flodiebold
Copy link
Member Author

flodiebold commented Jul 10, 2020

In rust-analyzer (or rustc, if it used the recursive solver). We need to know that we're actually looking for impls on integer or float types, so that we can search only those and not have to return all impls.

@flodiebold
Copy link
Member Author

I'll merge this now so we can use it in RA. Follow-up issue is #568.

@flodiebold flodiebold merged commit 74ab4c7 into rust-lang:master Jul 11, 2020
@flodiebold flodiebold deleted the integer-var-floundering branch July 11, 2020 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants