-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rewrite associated types to use projection rather than dummy type parameters #20307
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
Rewrite associated types to use projection rather than dummy type parameters #20307
Conversation
Oh, and this incorporates PR #20159 so I will close that. |
Awesome, I'm excited to see this land! |
ProjectionTyCandidate::Impl(data)); | ||
} | ||
super::VtableParam(..) => { | ||
// This case tell us nothing about the value of an |
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 makes me happy, it seems like a really clean way to handle this extra constraints.
pub fn normalize_associated_type<'a>(&mut self, | ||
infcx: &InferCtxt<'a,'tcx>, | ||
trait_ref: Rc<ty::TraitRef<'tcx>>, | ||
item_name: ast::Name, |
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.
item_name should have a more precise name or a comment (which item is it - the associated item, the trait, the concrete item?) It would be good to have a comment on the fn too stating what normalisation actually is
6bdf21e
to
3e0b041
Compare
NoCandidate, | ||
TooManyCandidates, | ||
|
||
/// |
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.
missing comment?
The following example still fails to compile with this branch merged.
I get the following error:
|
enum CreateTypeParametersForAssociatedTypesFlag { | ||
DontCreateTypeParametersForAssociatedTypes, | ||
CreateTypeParametersForAssociatedTypes, | ||
} |
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.
\o/ I'm so glad this is gone
r=me with the changes (all minor) |
@kinghajj the reason is that the method dispatch is not yet integrated with assoc types; should open an issue on that. If you convert to UFCS form, your test passes: #![feature(associated_types)]
trait Foo {
fn foo(&self) -> ();
}
trait Bar {
type F: Foo;
}
struct Wat<B: Bar> {
fs: Vec<B::F>,
}
impl<B: Bar> Wat<B> {
fn wat(&mut self) -> () {
Foo::foo(&self.fs.pop().unwrap()); // <-- changed to UFCS here
}
}
fn main() {
} |
81f8feb
to
3fed71b
Compare
types are always known and hence the ParameterEnvironment is not necessary. For other `Sized` queries, use the trait infrastructure just like `Copy`.
…r several reasons: 1. Produced more unique types than is necessary. This increases memory consumption. 2. Linking the type parameter to its definition *seems* like a good idea, but it encourages reliance on the bounds listing. 3. It made pretty-printing harder and in particular was causing bad error messages when errors occurred before the `TypeParameterDef` entries were fully stored.
…e instantiate them. Also fix some assertions and handling of builtin bounds.
…ow. Seems better to err on the side of being more correct rather than less. Fix a bug in typing index expressions that was exposed as a result, and add one type annotation that is not required. Delete some random tests that were relying on old behavior and don't seem to add anything anymore.
…k to their respective commits but oh dear what a pain.
for lack of impl-trait-for-trait just a bit more targeted (don't substitute err, just drop the troublesome bound for now) -- otherwise substituting false types leads us into trouble when we normalize etc.
5938adc
to
6f6944e
Compare
6f6944e
to
e186acc
Compare
…tend-bound, r=nrc Rewrite associated types to use projection rather than dummy type parameters. This closes almost every (major) open issue, but I'm holding off on that until the code has landed and baked a bit. Probably it should have more tests, as well, but I wanted to get this landed as fast as possible so that we can collaborate on improving it. The commit history is a little messy, particularly the merge commit at the end. If I get some time, I might just "reset" to the beginning and try to carve up the final state into logical pieces. Let me know if it seems hard to follow. By far the most crucial commit is "Implement associated type projection and normalization." r? @nick29581
Rewrite associated types to use projection rather than dummy type parameters. This closes almost every (major) open issue, but I'm holding off on that until the code has landed and baked a bit. Probably it should have more tests, as well, but I wanted to get this landed as fast as possible so that we can collaborate on improving it.
The commit history is a little messy, particularly the merge commit at the end. If I get some time, I might just "reset" to the beginning and try to carve up the final state into logical pieces. Let me know if it seems hard to follow. By far the most crucial commit is "Implement associated type projection and normalization."
r? @nick29581