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 upDisjointness based on associated types. #1672
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Yeah, I've definitely needed this in Diesel. I don't recall the specific place that I'm working around it, but it was likely of the form impl<T> Something for T where T: Expression<SqlType=VarChar> {
// ...
}
impl<T> Something for T where T: Expression<SqlType=Text> {
// ...
}Honestly, I had figured that this was a bug and not an explicit decision. |
comex
reviewed
Jul 11, 2016
| 1. If they are both concrete types, and they are not the same type (this rule | ||
| already exists). | ||
| 2. If they are both bound by the same trait, and both specify the same | ||
| associated type for that trait, and the types they specify are disjoint. |
This comment has been minimized.
This comment has been minimized.
comex
Jul 11, 2016
Perhaps add a rule that instantiations of generic types with disjoint parameters are disjoint. i.e.
impl<T: Trait1<Item=X>> Trait2 for Foo<T> { ... }
impl<T: Trait1<Item=Y>> Trait2 for Foo<T> { ... }
or even
impl<T: Trait1<Item=X>, U: Trait2<Item=Foo<T>>> Trait3 for U { ... }
impl<T: Trait1<Item=Y>, U: Trait2<Item=Foo<T>>> Trait3 for U { ... }
This comment has been minimized.
This comment has been minimized.
withoutboats
Jul 11, 2016
•
Author
Contributor
Yeah. We don't have good, consistent language about this, but when I wrote "two type variables" I meant any type variables (really I meant any type, whether an abstract variable or a concrete type, since the first rule only applies to concrete types), whether they be the receiver of the trait or not (I realize the summary is less broad than this, oops).
This is exactly what I had in mind when I said this rule was recursive.
This comment has been minimized.
This comment has been minimized.
sgrif
Jul 11, 2016
Contributor
Is there any case where T is disjoint but Foo<T> is not disjoint today? If not it seems redundant to re-specify it here.
This comment has been minimized.
This comment has been minimized.
withoutboats
Jul 11, 2016
•
Author
Contributor
@comex was talking about the transitivity of the disjunction rule, but perhaps we should note that if T is disjoint with U and X is a type constructor of the kind type -> type, X<T> is disjoint with X<U>. No reason this couldn't be a roundup to establish and document some of the basic disjunction rules.
EDIT: Actually, this may impact how that rule is implemented. Currently I think all disjunction is based on inequality of concrete types (e.g. we can just see that Foo<Bar<Baz<i32>> is not Foo<Bar<Baz<bool>>), but now that rule also needs to take into account type variables that are bound exclusively.
This comment has been minimized.
This comment has been minimized.
I think the best word for this is 'omission' - the current rules are correct so its not really a bug, but no one ever decided this rule shouldn't be added as well. This kind of disjointness just hasn't been evaluated for inclusion yet. |
This comment has been minimized.
This comment has been minimized.
|
Perhaps the motivation section should be updated to not be in first person, per #61? |
This comment has been minimized.
This comment has been minimized.
|
What about an impl where you don't specify the associated type at all, but use it in the implementation? trait Tr { type A; }
impl<T: Iterator> Tr for T {
type A = T::Item;
} |
This comment has been minimized.
This comment has been minimized.
|
@durka What type do you think |
This comment has been minimized.
This comment has been minimized.
|
None, I guess. |
This comment has been minimized.
This comment has been minimized.
|
I agree, none of the disjointness rules seem to make |
nrc
added
the
T-lang
label
Jul 12, 2016
This comment has been minimized.
This comment has been minimized.
cristicbz
commented
Jul 12, 2016
•
|
There are a bunch of issues about this, including one I filed early last year: rust-lang/rust#23341, rust-lang/rust#20400, rust-lang/rust#30191 (thought it would be useful to link to them) |
This comment has been minimized.
This comment has been minimized.
|
Looking at each of those:
|
aturon
self-assigned this
Jul 14, 2016
nagisa
referenced this pull request
Sep 12, 2016
Closed
Impls discriminating on associated types do not cause rustc consider them separate #36432
This comment has been minimized.
This comment has been minimized.
james-darkfox
commented
Oct 25, 2016
|
Any progress on this issue? |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Oct 25, 2016
|
I've run into this with a toy branch where I wanted to replace some macros that ran over numeric types with type constraints. I believe the type constraint based version made more sense, but it failed and I never thought deeply enough to say anything. If this happens, then great. If this is not a good idea, then maybe comment could be added to the documentation? |
This comment has been minimized.
This comment has been minimized.
|
@Mark-Simulacrum hit this in rust-lang/rust#37270 where they needed two impls for different iterator element types, but had to proxy to a trait dispatched on |
withoutboats
added
the
I-nominated
label
Nov 2, 2016
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge |
withoutboats
removed
the
I-nominated
label
Nov 3, 2016
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 3, 2016
•
|
Team member @withoutboats has proposed to merge this. The next step is review by the rest of the tagged teams: Concerns:
Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
Hmm. I would like to see something like this proposal go forward, but I'm a bit wary here. @rfcbot concern negative reasoning This seems to be strongly connected to negative reasoning. Basically the argument here is that we can prove that two where clauses are mutually incompatible, which isn't how our coherence check works now. I do think it makes sense to go in this direction, but I want to approach it with a somewhat more formal approach. Along those lines, I've been working on converting our trait system into a lambda-prolog-based logic in this repository. I'm not all that far along yet, but I hope that it can give us a basis for reasoning better about negative reasoning and its impact. That said, I think that these changes likely fit fairly well with our trait system logic (modulo my "underspecified" concern below). Basically I think what we should be shooting for is something that relies only on minimal logic. Essentially, in prolog terms, somewhere we can define an "inconsistent" predicate. I think we would translate this RFC as follows:
@rfcbot concern underspecified Today we only have Presumably the answer is that all variables would be considered potentially equal, and the only way to prove two types are disjoint is if they are unified with distinct nominal types (i.e., In any case, more examples are certainly needed. But I do think we'll be able to specify this nicely. |
This comment has been minimized.
This comment has been minimized.
|
About under-specification: The reference case is interesting because it introduces subtyping, presumable
I wrote this RFC very quickly (as I write every RFC I actually publish |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern underspecified Today we only have X = Y constraints in our system. This would introduce X != Y -- even if only limited to cherence -- and the RFC doesn't specify very clearly what this means. It gives some simple examples (u32 and i32 are unequal) but (for example) what about &'a u32 and &'b u32, or T and U? Presumably the answer is that all variables would be considered potentially equal, and the only way to prove two types are disjoint is if they are unified with distinct nominal types (i.e., u32 vs i32, or Rc vs Arc), right? In any case, more examples are certainly needed. But I do think we'll be able to specify this nicely. |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats I'd be happy to work with you on it |
This comment has been minimized.
This comment has been minimized.
|
I've realized this can express mutually exclusive traits and that it therefore carries all of the baggage associated with that feature. // Two disjoint types
struct Left;
struct Right;
trait Exclusive {
type Distinguisher;
}
// Foo and Bar are mutually exclusive because their associated types are
// disjoint.
trait Foo: Exclusive<Distinguisher = Left> { }
trait Bar: Exclusive<Distinguisher = Right> { }
trait Baz { }
// These impls are recognized as non-overlapping because the type parameters
// implement two exclusive forms of the same trait
impl<T: Foo> Baz for T { }
impl<T: Bar> Baz for T { }If this RFC were accepted, it would resolve the most pressing use for general explicit mutual exclusion in my code, because the traits I want to make exclusive already have a supertrait parameterized by a dummy type that ought to be an associated type, but for lack of this feature. |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Nov 22, 2016
|
Just ran into this again when trying to be generic over built in numeric types. I could work around the first times I ran into this if all the core numeric types functionality, like |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Nov 22, 2016
•
|
Appears there are some situations where you can circumvent needing this using a parameterized helper trait to make the associated type behave exactly like a type parameter.
I'd expect logic to tends towards landing in |
burdges
referenced this pull request
Dec 3, 2016
Open
Allow a trait to implement its parent trait #1024
sgrif
added a commit
to diesel-rs/diesel
that referenced
this pull request
Dec 5, 2016
sgrif
added a commit
to diesel-rs/diesel
that referenced
this pull request
Dec 5, 2016
sgrif
referenced this pull request
Dec 5, 2016
Merged
Support batch insert on SQLite, fix inserting empty slices #519
burdges
referenced this pull request
Dec 13, 2016
Open
Crates should allow private impl of external traits for external structs #493
eddyb
referenced this pull request
Dec 26, 2016
Merged
Implement `iter::Sum` and `iter::Product` for `Result` #38580
This comment has been minimized.
This comment has been minimized.
|
ping @nikomatsakis @withoutboats any progress here? |
This comment has been minimized.
This comment has been minimized.
|
Nope, @withoutboats and I haven't really talked. I remain concerned in the same way as before. =) I have been hoping to catch up with @withoutboats online and chat about this at some point though. |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats can you cancel the FCP request until you've had a chance to revise? |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp cancel |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jan 7, 2017
|
@withoutboats proposal cancelled. |
cramertj
referenced this pull request
Jan 27, 2017
Open
Parse and accept type equality constraints in where clauses #20041
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp postpone I'm proposing we postpone this and #1658 for a later date, when chalk is up and running, and we can put forward a unified proposal for how to expand the negative reasoning performed by our coherence system. I still want something like this RFC someday, but keeping this RFC open is not tracking progress toward that goal at all, and I think these two RFCs will want to be majorly revised into a single proposal. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 23, 2017
•
|
Team member @withoutboats has proposed to postpone this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
withoutboats
referenced this pull request
Feb 23, 2017
Closed
Revisiting specialization: Complementary traits #1658
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 15, 2017
|
|
rfcbot
added
the
final-comment-period
label
Mar 15, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 25, 2017
|
The final comment period is now complete. |
This comment has been minimized.
This comment has been minimized.
|
Closing as postponed. |
withoutboats commentedJul 11, 2016
•
edited
Rendered