-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Revert "Auto merge of #43690 - scalexm:issue-28229, r=nikomatsakis" #44045
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
@Fcpbot close |
@rfcbot fcp close OK, so as I wrote on #43690, I kind of screwed up the process here. In particular, I accepted the PR, but @eddyb had some lingering objections. In particular, the PR has the compiler "auto-generate" clone impls. Some of these clone impls are sort of required -- in particular, those for However, the PR also extends support for a few other things. Notably, I personally think this is all very desirable. I also do not think the changes are major enough to require a full RFC. But I do think we should use the consensus process to ensure we are all in agreement on this point. Therefore, @arielb1 prepared this PR to revert the change. Since I support the change, I am moving to close this RFC (and hence accept the change). |
Team member @nikomatsakis has proposed to close 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. |
@rfcbot concern derive-consistency Currently we have one primary mechanism (the builtin set of A more annoying consequence of syntactic deriving is it can't generate the right bounds (see #26925 - although it might not the best issue to explain the problem, let me know if there's another):
So far in the compiler, But after #43690, we have two ways to derive a But deriving |
BTW, I think I missed something. Under #43690, if I'm not mistaken, one can now clone tuples of arbitrary arity (e.g., this compiled in nightly but not stable). Obviously I would want this to work, but it does introduce a kind of "incongruity" -- and, unlike |
This is an interesting comment -- I don't think of In any case, if I can resummarize, you raised two points: "Perfect deriving" -- in particular, the fact that when you have (I do have this sort of instinctual feeling that there is way to permit more co-inductive reasoning in the trait system, but I don't yet understand well enough how to think about it.) "Two ways to have deriving." After #43690, for "user-defined" types (structs and enums), the Put another way, it feels like you are sort of making the case that the change didn't go far enough -- i.e., it converted some clone impls, but not all, to a new system. I don't see why this is a problem. Unless we achieve the specialization goal, we will always have to contend with a mix of user-supplied and builtin clone impls. Whether the user-supplied impls are generated by |
Generating MIR for user-defined types makes me concerned about edge-cases that would be detected in other parts of the compiler (e.g. The derived Clone impl isn't actually more complicated than drop glue, so I'm not much worried about that.
I'm actually not sure whether there's a good solution to the "correct bounds" issue, other than making
The generated MIR is already type-checked, but there's no free-region checking so dubious Borrow-checking it in a "non-fake" sound way would require doing region inference on MIR, aka "NLL". |
I pretty much agree with everything @arielb1 said, which is why I think this requires an RFC. |
So about generating a A side-effect of that change is that indeed tuples of But I think this is a "good" side-effect because it indeed fixes an annoying limitation of the Rust language (not being able to write a trait impl for all array and tuple types). However, the fact that it was not the primary goal of PR #43690 makes me think that we should maybe not do the same for e.g. So the way I see PR #43690 is that it is just a necessary (because of the ICE) workaround until we have a way to express trait impls for arrays and tuples in the language. The fact that is was necessary makes me believe that maybe we don't need an RFC for that change. Also, I agree with @nikomatsakis and @arielb1 that the bounds problem in auto-derived impls seems orthogonal to PR #43690. |
For |
@eddyb I mean that the trait selection algorithm still needs to express something like: // This impl can be seen as a "variadic" impl generated by the compiler
impl<T> Clone for (T1, ...) where T1: Clone, ... if you replace the impl<T> Clone for (T1, ...) where T1: Copy, ... then this would conflict with the macro-generated impls that we have on stable: impl<A, B> Clone for (A, B) where A: Clone, B: Clone { ... }
impl<A, B, C> Clone for (A, B, C) where A: Clone, B: Clone, C: Clone { ... }
// ... and so on up to tuples of 8 elements because the compiler would not know which impl to select for e.g. |
Ahhh this is the first time I ever see this said out loud by anyone. I doubt @nikomatsakis was even aware. The solution is obvious: treat the compiler implementation as a specialization or do not consider it if there are any library impls matching it. |
@eddyb For some reason I thought that specialization would not work in that case, but you're right it seems like it does, just changing to |
Let me be clear on what is being proposed: Limit the built-in impls to the Copy case, and use specialization to ease the overlap between the existing impls (which cover I'd be fine with it. I considered suggesting it at some point (after all, I've been hoping to use specialization uniformly to cover this case...), except that I think it's not exactly a feature that you can't clone things. But I do think it'd be nice for things of arbitrary arity to work uniformly for all traits, not just |
We don't even need specialization. If we're ok with hacks, we can just not have the "complier-generated" impls on tuples with less than 8 elements and arrays with less than 32 elements. However, I think that getting rid of the |
Indeed, true.
This was roughly what I was thinking. But I don't have a very strong opinion here -- I'd be ok with either path. |
No. Only the "function pointer with a binder" case. |
☔ The latest upstream changes (presumably #43076) made this pull request unmergeable. Please resolve the merge conflicts. |
OK, so @eddyb and I were taking, and he said that he would be happy if we restricted the cases covered to precisely the ones needed to fix the ICE (and tried not to go further). I personally think this is OK. I just want the ICE fixed. We can argue about the rest later. I think we had agreed on a viable strategy for how to do that above. @scalexm, would you be able to make such a patch? It may have to be backported to beta too. |
I can do that. |
OK, let's close this PR in favor of #44196 (right?) |
I (and @nikomatsakis) think we needed an FCP for the original PR (#43690). Because it was already merged, let's have the FCP on the revert.