-
Couldn't load subscription status.
- Fork 13.9k
arbitrary_self_types: Split the Autoderef chain #146095
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
base: master
Are you sure you want to change the base?
arbitrary_self_types: Split the Autoderef chain #146095
Conversation
|
This PR changes a file inside |
This comment has been minimized.
This comment has been minimized.
bef5ba5 to
f3e8785
Compare
This comment has been minimized.
This comment has been minimized.
f3e8785 to
31788b7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@rustbot label +F-arbitrary_self_types |
31788b7 to
1a2dbf8
Compare
|
The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Is this waiting on discussion and a decision from the lang team? |
|
@jackh726 Sorry I was not very clear. Indeed it would need a lang team discussion. To support the discussion, I am writing a report to describe what changes this would bring to the feature. |
|
☔ The latest upstream changes (presumably #145993) made this pull request unmergeable. Please resolve the merge conflicts. |
|
The report is a bit overdue. I would like to just publish a partial text while I need more time to restore some diagnostics. Acceptable receiversLanding #146095 means that types implementing
Library changesThis patch demonstrates that we now explicitly mark types like This is particularly important for ShadowingAfter careful consideration and testing, I believe that splitting the two traits do not change the fundamental reasoning behind method shadowing diagnostics. Before this change, concerns about shadowing items through |
|
I'm going to go ahead and nominate. This is just a vibe check. We're not making a binding decision at this time. The question on the table is only whether we might have such opposition to this direction that we'd block or discourage its exploration. For my part, I want to see this explored so we can fully consider it. |
1a2dbf8 to
32146f8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
32146f8 to
423792b
Compare
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
423792b to
962a737
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
962a737 to
0bd9ecd
Compare
|
We talked about this, for a vibe check, in the lang meeting this past week. People certainly aren't yet sold on this approach -- I'm not yet sold myself. However, I feel that the way to work out whether this approach is viable and desirable is to let @dingxiangfei2009 land this and explore it further -- experimentation will hopefully help to answer the kind of questions this approach raises and support the writing of comprehensive design documents for this -- and that went without objection. Putting on the hat of the lang champion here, then, this PR is OK to land as far as lang is concerned. We'll want to be careful, in how we do this experimentation, that we still support experimentation of and the ability to answer important design questions for the other model, e.g. to support work on evolving trait hierarchies, reborrowing, autoref, projection, etc., where we might want to compare how the complete solution would look either in the |
This comment has been minimized.
This comment has been minimized.
0bd9ecd to
b5815ec
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
Receiver chain has been an extension of Deref chain, but the consequence has been questioned as this would admit method signatures that are deemed dubious. It is also debatable that Receiver trait which determines applicable `Self` type should have anything to do with dereference operation in general. This patch separate the two traits and isolate their use in the language. This means that in method probing, we will chase down a Deref chain for an applicable type for the variable `self`, from which we additionally chase down a Receiver chain for an applicable `Self` type from a list of methods that accepts one of these possible types of `self`.
b5815ec to
32433c2
Compare
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.
Wasn't sure if this was quite ready for review or not. But, here are my thoughts.
| hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types = | ||
| consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
| consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`); |
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.
I'm surprised by this change. I would expect to only change the diagnostic when the feature is not enabled hir_analysis_invalid_receiver_ty_help
| A(A, PhantomData<fn() -> C>), | ||
| B(B, PhantomData<fn() -> C>), |
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.
Why the extra PhantomData<fn() -> C> here? I assume it was to ensure that C is used constrained in the impl below, but it's unnecessary.
| } | ||
| } | ||
| if follow_receiver_chain { | ||
| EitherIter::A(fcx.autoderef(span, ty).follow_receiver_chain(), PhantomData) |
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.
Okay, so if I'm understanding this correctly, for each step in Deref chain, we then try a Receiver chain? That's pretty crazy, and is very likely going to have an effect on perf.
I would really like to evaluate perf before and after this PR (when enabling arbitrary self types).
| // We are in the wf check, so we would like to deref the references in the type head. | ||
| // However, we do not want to walk `Deref` chain. | ||
| autoderef = autoderef.follow_receiver_chain(); |
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.
I'm curious why that is here? But in confirm we do?
| &*self.0 | ||
| } | ||
| } | ||
| impl<T: ?Sized> Receiver for Ptr<T> { |
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.
Are these impls required? I imagine this might be a consequence of my comment in wfcheck?
Receiver chain has been an extension of Deref chain, but the consequence has been questioned as this would admit method signatures that are deemed dubious.
It is also debatable that Receiver trait which determines applicable
Selftype should have anything to do with dereference operation in general.This patch separate the two traits and isolate their use in the language. This means that in method probing, we will chase down a Deref chain for an applicable type for the variable
self, from which we additionally chase down a Receiver chain for an applicableSelftype from a list of methods that accepts one of these possible types ofself.To facilitate discussion, we can use the Zulip thread #t-lang > Consequences of making Deref a subtrait of Receiver.
Pending items
arbitrary_self_typesgate again.