-
Notifications
You must be signed in to change notification settings - Fork 13.3k
🔬 implement "always applicable impls" #48538
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
Comments
@nikomatsakis I would like to take this since it's related to specialization, which is the topic I've covered the most. Months ago I wrote a tracking issue (#45982) pointing out the things to do related to "restrictions around lifetime dispatch". |
@giannicic sounds about right, yes. |
@nikomatsakis
Could work? |
@giannicic Sorry for the delay. PS, feel free to reach out on gitter as well.
I don't think that's necessary, but it seems ok to start there. I agree we want both eventually. It might also be better to wait on the "always applicable" side of the equation until we've made more progress around the chalk-ification process etc.
Hmm, I don't know that I agree with that proposed change. I think That logic is presently handled here, when constructing the specialization graph. You can see that in the event of overlap it checks whether either of the two impls specialize one another: rust/src/librustc/traits/specialize/specialization_graph.rs Lines 141 to 154 in 0ff9872
I'm not entirely sure how best to extend this logic to intersection impls though. It seems like we need to start constructing a more complex graph? Maybe I'm overthinking it, but I am imagining something like adding all the impls to a graph, then adding "overlaps" and "specialized by" edges where applicable (note that "specialized by" implies "overlap"). So e.g. the classic "intersection" case might look like:
If we insert a synthetic "bottom" -- basically, an empty impl that hence specializes all others -- then we can say that impls A and B are allowed to overlap if their immediate, mutual postdominator in the graph is not the "bottom impl". Moreover, that postdominator is the specializing impl (in this case, C). Note that we have a postdominator computation in Thinking about this a bit more, I guess we just need to compute the "specialized by" edges -- we may not need to "materialize" the overlaps edges, though we probably want to keep a list for later reference of things that overlapped but did not specialize (so we can check that they have a mutual postdominator). Does that make some sense? |
@nikomatsakis |
Status update.
Inserting multiple parent implies that each possible impl must be visited in order to find the parents of a given impl. So the insert method should return a Then the overlap error can no more be triggered at insertion time but should be checked once the graph is fully build. I'll use the overlap edges in order to check for overlapping errors. @nikomatsakis |
@giannicic this looks roughly right. I suspect we don't need to store the overlap edges in the graph -- after all, I think we only need them during overlap checking. We could keep a set of pairs instead. Regarding whether to store in "both directions", I would instead canonicalize the def-ids so that the "lower" one appears first, since you don't really need to store both directions. |
Is this issue still open/have things significantly changed? I'd like to work on it if so. |
Also left a comment on #31844 but I figured I might as well add this here while I was exploring the possibility of specialising some iterator methods. From Niko's blog post, this example specifically is brought up as being problematic: trait Example {}
impl<T> Example for T where T: Clone { }
impl<T> Example for Vec<T> where T: Clone { } Since, effectively, we can't guarantee that trait Example: Clone {}
impl<T> Example for T where T: Clone { }
impl<T> Example for Vec<T> where T: Clone { } Now, it doesn't really matter if There are definitely cases where I'd still like to rely on the full functionality (for example, assuming |
Part of #31844: In order to eventually stabilize specialization, we need to make it sound. The current plan for doing so is called "always applicable impls", and is explained in this blog post. This issue exists to track the implementation of that proposal.
This does not yet have any mentoring instructions. Ping me if you are interested though and we can talk it over! Or maybe I'll get to it before then.
The text was updated successfully, but these errors were encountered: