-
Notifications
You must be signed in to change notification settings - Fork 183
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
support "specialized" impls #219
Comments
The basic idea then is to add a few sorts of domain goals:
We never generate program clauses for
impl Iterator for Foo<T> { // impl A
default type Item = u32; // associated-type-value with id V0
}
impl Iterator for Foo<String> { // impl B
type Item = char; // associated-type-value with id V1
} Impl B specializes impl A, so when lowering V0 we would generate a rule like:
Lowering V1 we would generate rules like:
Note that since V1 is not declared |
As @sunjay pointed out on Zulip, an obvious first step is: Extend the parser to support |
Presently we have code to build a specialization forest: chalk/chalk-solve/src/coherence.rs Lines 77 to 78 in 3238c6d
In order to figure out which impls specialize which other ones, I think for now we'd probably build on that, but we have to think about how to do it. This gets to a related topic, I realize, which is that I think we want chalk-solve to integrate more closely with salsa and have some query structure of its own. I'll think about that and try to leave a few notes, but that might be a good next step. |
Given that we now have
These are relatively simple steps but they don't do anything interesting yet. The next step is where things get more exciting. We would want to take the |
The next steps are described in this paper document. Summary of next steps:
Each of these steps leads to finishing off the |
A note to help me remember: I was debating if this lowering could lead to a need to handle "negative cycles". In particular, it seems at first glance plausible that a clause like: forall<T> {
Normalize(<Foo<T> as Iterator>::Item -> u32) :-
Reveal,
not { Overrides[V0](Foo<T>: Iterator) }
} might wind up recursively dependent on itself (i.e., part of proving |
I suppose you could write something sort of self-contradictory like this: impl Iterator for Foo<T> { // impl A
default type Item = u32; // associated-type-value with id V0
}
impl Iterator for Foo<String>
where
Foo<String>: Iterator<Item = u32>,
{ // impl B
type Item = char; // associated-type-value with id V1
} In this case, proving that
Ugh, I wonder if we're going to have to extend chalk-engine to handle such cycles correctly after all. Of course, this program ultimately I think wouldn't be expected to compile, and it's hard to imagine such things arising in practice. And maybe it's some kind of special case of negative cycles. |
What's the current status of this issue? It looks like some specialization-related methods have been added ( |
With respect to my example, I realize now that this setup would probably fail in rustc because we require that there is a DAG between traits with respect to references from specializing impls. |
This is a step towards full support for specialization (#9). This particular step sidesteps some of the trickier bits of specialization (in particular, it sidesteps the parts related to regions and soundness). The goal is this:
I'll try to post more detailed mentoring instructions, but here are some high-level notes:
Specialization does not effect whether or not a trait is implemented. Therefore, the "lowering" for an impl ought to be unaffected -- overlapping impls simply mean more than one way to prove the same set of types, and the solver ought to be able to handle that.
The "normalization rules", however, are effected. If you have an impl with a default item:
then we cannot normalize
<Foo<T> as Iterator>::Item
tou32
unless we know that there is no "more specific" impl that applies.Moreover, at least in rustc at the moment, we sometimes wish to assume that a more specialized impl could be added in the future. In rustc, we currently distinguish between "reveal mode", at which point we are allowed to normalize a
default
type, and "normal mode", when we are not.The text was updated successfully, but these errors were encountered: