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 up🔬 Tracking issue for generic associated types (GAT) #44265
Comments
withoutboats
added
A-associated-items
A-traits
A-typesystem
B-RFC-approved
B-unstable
C-tracking-issue
T-lang
labels
Sep 2, 2017
nikomatsakis
added
WG-compiler-traits
E-needs-mentor
T-compiler
labels
Sep 15, 2017
This comment has been minimized.
This comment has been minimized.
|
Here is a kind of implementation plan I will endeavor to keep updated.
|
nikomatsakis
added
E-mentor
and removed
E-needs-mentor
labels
Sep 20, 2017
nikomatsakis
changed the title
Tracking issue for generic associated types
Tracking issue for generic associated types (GAT)
Sep 21, 2017
This comment has been minimized.
This comment has been minimized.
|
Let me start by writing about the AST in more detail. First let's discuss how it works today: A A Methods are an interesting case because they can already be made generic. Those generic parameters are declared in the field My take is that the best thing to do would be to "lift" Perhaps a decent first PR would be to just do that change, keeping all other existing functionality the same. That is, we would more |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Cool! Thank you so much! I started experimenting with this last night and I'm proud to say that I found the same places you pointed to in your comment about the AST. I didn't think to lift generics into Here's the change I would have made: pub enum TraitItemKind {
// Generics aren't supported here yet
Const(P<Ty>, Option<P<Expr>>),
// `Generics` is already a field in `MethodSig`
Method(MethodSig, Option<P<Block>>),
// Added `Generics` here:
Type(Generics, TyParamBounds, Option<P<Ty>>),
Macro(Mac),
}Edit: Answer by nikomatsakis on Gitter
|
This was referenced Sep 22, 2017
This comment has been minimized.
This comment has been minimized.
|
All right! Next step is to extend the parser. Here are a few tips. Let's start with trait items. This routine parses trait items. We want to extend the case that handles associated types to also parse things like Currently it is using Once we've done that, we should be able to add some parsing tests. I would do that by making a directory like Something else -- we need to feature gate this work at this point, to avoid people using this stuff in stable builds. There are some instructions for adding a feature-gate here on forge (see the final section). We should add a |
bors
added a commit
that referenced
this issue
Sep 27, 2017
carols10cents
added
the
hacktoberfest
label
Sep 29, 2017
bors
added a commit
that referenced
this issue
Oct 23, 2017
bors
added a commit
that referenced
this issue
Oct 24, 2017
sunjay
referenced this issue
Nov 10, 2017
Merged
Generic Associated Types Parsing & Name Resolution #45904
This comment has been minimized.
This comment has been minimized.
|
To setup name resolution, I think all we have to do is to get the proper "ribs" in place (the name resolution stuff organizes the sets of names that are in scope into ribs; each rib represents one binding level). e.g. for an impl: impl<A,B> Foo<B> for Vec<A> {
fn bar<T,U>(x: ...) {
for y in ... {
}
}
}we would have the following ribs:
In general, modeling things on how methods work is not a bad idea. We might also do a bit of "future proofing" here, I suppose. Here is the code that brings a method's type parameters into scope (this is for a method defined in a trait): rust/src/librustc_resolve/lib.rs Lines 1890 to 1892 in a35a3ab Whereas for a rust/src/librustc_resolve/lib.rs Lines 1897 to 1901 in a35a3ab Now that generics are in place on every trait/impl item, I think we probably want to remove the handling for Other points of interest: You get the idea. @petrochenkov -- sound about right? |
dtolnay
referenced this issue
Nov 15, 2017
Closed
Special lifetime for downcasting ownership to reference. #1802
This comment has been minimized.
This comment has been minimized.
Everything looks correct. |
sunjay
referenced this issue
Nov 21, 2017
Closed
[WIP] Generic Associated Types Name Resolution #46146
bors
added a commit
that referenced
this issue
Dec 2, 2017
bors
added a commit
that referenced
this issue
Apr 23, 2018
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
May 10, 2018
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
May 10, 2018
This comment has been minimized.
This comment has been minimized.
quadrupleslap
commented
May 21, 2018
•
|
Sorry if I'm being stupid, but is this kind of thing going to be legal with GATs? trait Sequencer {
type Wrap<A>;
fn chain<A, B, F>(Self::Wrap<A>, F) -> Self::Wrap<B>
where F: FnOnce(A) -> Self::Wrap<B>;
fn wrap<A>(A) -> Self::Wrap<A>;
} |
This comment has been minimized.
This comment has been minimized.
|
What's the status of this? I know that chalk recently gained gat support. Is that intended to land in rust soon? |
This comment has been minimized.
This comment has been minimized.
baloo
commented
May 29, 2018
|
@mark-i-m I gave it a shot last week. From my understanding, the syntax parser is there (although missing tests). But the "implementation" is not written yet. (see #44265 (comment) for more details) |
This comment has been minimized.
This comment has been minimized.
Boscop
commented
Jun 2, 2018
|
@quadrupleslap AIUI, that will be possible later, but at first, GATs will only support lifetime parameters.. |
This comment has been minimized.
This comment has been minimized.
|
@Boscop the RFC specifies that type parameters will also be supported. |
This comment has been minimized.
This comment has been minimized.
|
Does someone know the exact status of the implementation of the syntax in rustc? It seems mostly there, but higher ranked bounds generate ICEs: I’d at least need the whole syntax to be implemented in order to advance on the chalkification work. If anybody is still working on the syntax, please let me know, or else I might go and fix it myself :) |
This comment has been minimized.
This comment has been minimized.
|
To me it looks like communication is the major problem slowing down the implementation of GATs. There seem to be at least a few people interested in working on this, but no one really knows the exact implementation status and who is working on this already. What do you think about an Discord (or IRC?) channel just to talk about implementing GATs? I think that would certainly help. Also, I could certainly contribute a few work days in the following weeks to work on this (but I don't really know anything about this part of the compiler yet). |
This comment has been minimized.
This comment has been minimized.
|
So I asked for a dedicated channel on Discord. But instead of getting a channel, I learned a few things. I also searched for everything related to GATs. So I'll try to summarize all information regarding this feature; maybe it's useful to some people. But I don't know anything, so take this with a grain of salt! Also: please tell me if some information is incorrect so that I can fix it. Summary of implementation efforts regarding GATs
Since then there weren't any UI tests added. And I can't find any other PRs directly related to GATs. However, the point (c) from above (the trait system) is being worked on "in secret". As far as I understand it, the plan is to migrate to the new chalk-based trait solver soon and not make GATs work on the old system. Integration of the new trait solver is tracking by the "Chalkification" tracking issue. There have been quite a few PRs related to chalk and chalkification. Notably, there is a chalk PR called "Finish implementing GATs" (merged 2018-05-24). So it seems like the core system for GATs is already in place. That said, the "GATs" in chalk are a prototype implementation and using it in rustc is not just a For more information and to help out, it's probably useful to take a look into the |
This comment has been minimized.
This comment has been minimized.
|
So @nikomatsakis just created the |
LukasKalbertodt
referenced this issue
Jun 16, 2018
Closed
WIP: Fix unexpected E0110 when using GATs #51589
Mark-Simulacrum
removed
the
hacktoberfest
label
Jul 6, 2018
This comment has been minimized.
This comment has been minimized.
|
Is there any update on this recently? Are we waiting for Chalk integration into the compiler? (Perhaps there's a separate issue for that.) |
This comment has been minimized.
This comment has been minimized.
|
withoutboats commentedSep 2, 2017
•
edited by nikomatsakis
This is a tracking issue for generic associated types (rust-lang/rfcs#1598)
TODO: