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

Implement GATs #116

Closed
scalexm opened this Issue May 1, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@scalexm
Copy link
Collaborator

scalexm commented May 1, 2018

Step 1

The grammar needs to be extended to support bounds and (quantified) where clauses on associated types like in:

trait Foo {
    type Item<'a, T>: Clone where Self: Sized;
}

The grammar is located parser.lalrpop, and the AST in ast.rs.

When this is done, this item:

WhereClauses: Vec<WhereClause> = {
"where" <Comma<WhereClause>>,
() => vec![],
};

won't be needed anymore because we will be using QuantifiedWhereClauses everywhere.

We would also remove where clauses on associated type values because they are useless:

AssocTyValue: AssocTyValue = {
"type" <n:Id> <a:Angle<ParameterKind>> <wc:WhereClauses> "=" <v:Ty> ";" => AssocTyValue {
name: n,
parameter_kinds: a,
value: v,
where_clauses: wc,
},
};

Step 2

Currently, a where clause of the form where T: Foo<Item = U> translated to a single domain goal ProjectionEq(<T as Foo>::Item = U). We would need this clause to be translated to two distinct domain goals:

  • ProjectionEq(<T as Foo>::Item = U) as before
  • Implemented(T: Foo)

Currently, we cannot translate one AST where clause to multiple IR domain goals. This means that the following trait:

chalk/src/lower/mod.rs

Lines 437 to 439 in eeb2182

trait LowerWhereClause<T> {
fn lower(&self, env: &Env) -> Result<T>;
}

should be changed into something like:

trait LowerWhereClause<T> {
    fn lower(&self, env: &Env) -> Result<Vec<T>>;
}

Step 3

Now we should be in a position where we can implement the various rules written in this comment (niko's comment just below can be ignored, it was basically merged into the main one). This includes:

  • program clauses which should be implemented in lower/mod.rs
  • WF requirements which should be implemented in lower/wf.rs

Note: the organization of these two files will change after #114 is fixed, so the preceding text may become obsolete.

Step 4

At that point, the domain goal WellFormed(ProjectionEq) will be unused. See #115 for the next steps.

cc @rust-lang-nursery/wg-traits

This was referenced May 7, 2018

tmandry added a commit that referenced this issue May 9, 2018

Merge pull request #119 from tmandry/GAT-step2
Refactors LowerWhereClause to permit multiple domain goals from a single AST where clause.

For implementing GATs (#116).

@tmandry tmandry self-assigned this May 12, 2018

@scalexm

This comment has been minimized.

Copy link
Collaborator

scalexm commented May 23, 2018

Follow-up (should be straightforward): support quantified bounds on GATs, both in the grammar and in the rules, e.g.

trait Foo {
    type Item<V>: forall<'a> Fn(&'a V);
}
@scalexm

This comment has been minimized.

Copy link
Collaborator

scalexm commented May 24, 2018

(Reopening because of the follow-up)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment