-
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
Add basic support for dyn and impl Trait #226
Conversation
ea3bcbb
to
9e35bae
Compare
@KiChjang so I didn't actually see your WIP commit until just now. I'm taking a look now at the issue and trying to figure out what the next steps are. Will try to leave you some advice =) |
@nikomatsakis I still need some guidance on how to extend the chalk solver to account for impl Trait and dyn Trait. |
4dce951
to
4c04ed1
Compare
4c04ed1
to
30d8323
Compare
chalk-solve/src/clauses.rs
Outdated
match trait_ref.self_type_parameter() { | ||
Some(Ty::Opaque(qwc)) | Some(Ty::Dyn(qwc)) => { | ||
clauses.push(ProgramClauseImplication { | ||
consequence: trait_ref.clone().cast(), |
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.
This doesn't quite look right. For example, if this function were invoked with a trait_ref
like Implemented(dyn Foo: Bar)
, this would generate something like
implemented(dyn Foo: Bar) :-
dyn Foo: Foo
but what we really want is
Implemented(dyn Foo: Foo).
Moreover, something is a bit funny here -- you're just skipping over the binders in qwc
, which isn't really right. What we want is more like:
let self_ty = trait_ref.self_type_parameter().unwrap(); // this should not really return an Option
let wc = qwc.instantiate(self_ty);
clauses.extend(wc.iter().cloned().casted());
what this will do is to take a self_ty
like dyn Foo
and create clauses like Implemented(dyn Foo: Foo)
.
However, there are some complications.
For one, the instantiated
method I referred to doesn't actually exist yet -- there is subst::apply(&[self_ty], &qwc.value)
, which I think would be equivalent. The idea of instantiate
would be to take a Binders<T>
and create a T
, substituting a value for the variables bound in Binders
.
30d8323
to
454ff2c
Compare
454ff2c
to
e561538
Compare
48b0a36
to
0a53a25
Compare
Ok I took a stab at building this branch locally and I see errors in the following files. Some notes:
These have to do with implied bounds. I would leave these rules as empty but add "FIXME #203" for now.
You basically want rules very analogous to the So you want to add an analogous match arm like this one: chalk/chalk-solve/src/infer/unify.rs Lines 133 to 139 in 9dac49b
and then add chalk/chalk-solve/src/infer/unify.rs Lines 119 to 122 in 9dac49b
chalk/chalk-solve/src/infer/unify.rs Lines 141 to 149 in 9dac49b
For now we could probably handle "de-aggregation" in the same "not that great" way we handle some other cases, like so: chalk/chalk-solve/src/solve/slg/aggregate.rs Lines 183 to 185 in 9dac49b
but we should add a FIXME for this. (Also, this code seems a bit wrong to me, in that I think it should try to ensure that
As the comment says: chalk/chalk-solve/src/solve/slg/resolvent.rs Lines 340 to 341 in 9dac49b
we ought to be able to match up the structure and descend down, so we probably just want something like this chalk/chalk-solve/src/solve/slg/resolvent.rs Line 347 in 9dac49b
but we have to be sure the
I think this should just behave analogously to apply: so push the type into the accumulate and recurse on the patterns, much like this Lines 67 to 70 in 9dac49b
|
0a53a25
to
b8a7470
Compare
cc #218.