Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImpl Index #498
Comments
matklad
added a commit
that referenced
this issue
Jun 28, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Another thing which we could exploit is filtering the set of applicable traits by the method name (this is how rustc does resolve, but I don't think it is applicable for the completion). |
This comment has been minimized.
This comment has been minimized.
|
Thinking about it a bit more, I think a better strategy would be to implement a simpler "inherent impl" rather then jumping directly to the trait impls. |
alexeykudinkin
assigned
matklad and
alexeykudinkin
Jun 30, 2016
This comment has been minimized.
This comment has been minimized.
|
Closed in #566 |
matklad
closed this
Sep 6, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
matklad commentedJun 27, 2016
To do resolve and completion, we need to answer a question "what traits are implemented for a given type?" Moreover, we need to consider only the traits that are currently in scope , so the question reduces to "Is the trait T implemented for the type S?" However, keep in mind the following "advanced" example:
We do not handle generics in any way yet, so I think it's ok to focus on simpler cases for now.
The simplest implementation would be to create an index of all impls. Then in order to answer The Question you would process all entries and check that the trait and the type of the impl resolve to the trait and the type in question. Arguably this is not very efficient, because there are a lot of impls, and majority of them are irrelevant.
The more advanced implementation would index the impls by the name of the trait. You still need to process a number of irrelevant impls though.
It's not easy to index the impl by the type name (
impl<T> X for T where T: A + B {}?). However I suspect that the vast majority of impls have a simpler form ofimpl X for Sorimpl<T> X for S<X>, for which we can index by both the type and the trait. So my suggestion is to create two indexes:The idea is that you first try to find a simple impl for a given trait and type. If you do not succeed, you try to find a sophisticated impl and then try to solve its constraints. Looks like this would work nicely with plain stub indexes, invalidated on file change (we only need to verify impl's trait and type resolve target)
However there are additional properties which we may want to exploit in indexing/caching.
CRATE_MODIFICATION_COUNTand use it for resolve caching. This count would get an update when the crate or any of it's dependencies is modified.impl X for Scan be defined. Namely, they are the crates whereXis defined and whereSis defined. In theory, this should allow us to cut down on the number of impls we investigate, because we'll need to consider only two crates. In practice, I think that all impls would be in these two crates anyway, so this will not cut down on anything.