-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add DynSized trait (rebase of #44469) #46108
Conversation
Letting @nikomatsakis Any chance that bounds on |
A couple of interesting points that weren't mentioned in the conversation on #44469:
Because of the potential for future breakage, it may make sense to special-case auto traits, so that they don't have any implicit supertraits. As long as auto traits can't have items, it hopefully should be possible to add or remove implicit supertraits without breaking. Or alternatively, if auto traits could be allowed to have supertraits, we could allow that, as @Zoxc has just mentioned |
cc @bluss |
@Zoxc I saw your comment just before I posted mine, just didn't want to rewrite everything. You basically said everything that I was saying, but in way fewer words :) |
ugh... |
The DynSized trait is implemented by all types which have a size and alignment known at runtime. This includes every type other than extern types, introduced in RFC 1861 and implemented in rust-lang#44295, which are completely opaque. The main motivation for this trait is to prevent the use of !DynSized types as struct tails. Consider for example the following types : ```rust extern { type foo; } struct A<T: ?Sized> { a_x: u8 a_y: T } struct B<T: ?Sized> { b_x: u8 b_y: T } ``` Before this change, the type `A<B<foo>>` is considered well-formed. However, the alignment of `B<foo>` and thus the offset of the `a_y` field depends on the alignment of `foo`, which is unknown. By introducing this new trait, struct tails are now required to implement `DynSized`, such that their alignment is known. The trait is an implicit bound, making `A<B<foo>>` ill-formed. Just like the `Sized` trait, the default bound can be opted-out by using `?DynSized`.
auto traits cannot have bounds, so they must remove the implicit DynSized bound with `Self: ?DynSized`
This fixes a bunch of ui tests. It now either prints out `T`, `T: ?Sized`, or `T: ?DynSized`.
There are other types that can be in a DST struct’s tail: other DST structs, DST tuples, and possibly more. The only one we don’t want to allow is extern types, so I added a check for that
had to add the dynsized lang item, and add ?DynSized bound to auto traits
Had to add ?DynSized to auto-traits
Add a `?DynSized` unbound to the auto trait in the example, and explain why it is necessary
extern types do not implement DynSized, so to implement a trait for one you need to explicitly remove the DynSized bound for that trait
27133cc
to
b9a69c7
Compare
dynamically (at runtime) sized types are |
@liigo anything that is |
@iigo I'll try to explain that a bit better: |
Ping from triage @pnkfelix — will you be able to review this shortly? |
So @withoutboats and I were talking and we had what I think is an interesting insight. We were thinking about when one might want
I'm not sure yet what this means but I find it to be an interesting correspondence. Are there exceptions? |
|
Yes; not using the Rust allocator, basically. Not sure how important that is. (Sometimes I regret designing our allocators so that they supply the size of the value being freed, but I guess it's awfully late to try and reverse course there.)
Yes, true. |
It seems like the use cases for size_of_val diminish significantly without this requirement. I wonder if we couldn't revisit this? |
OK, I feel bad that this PR is sitting here with no viable means to go forward or backward yet. I remain highly nervous about i.e., do we want to move forward with (It seems clear we have to ensure it is 100% backwards compatible; I've kind of lost track of whether that is the case now.) @mikeyhew if your main motivation is to explore custom DST, I'd rather just explore that directly, while leaving the questions around |
|
agreed, this PR doesn't feel like the right place!
OK, I see, I remember that now. Thanks for the clarification.
Sounds like a plan. |
FYI I've submitted rust-lang/rfcs#2310 as an alternative. |
@rfcbot fcp close We discussed this in the @rust-lang/lang meeting today. As a result of that conversation, I'm going to move to close this PR. The general feeling was that the "jury is still out" on what approach to use for handling Given this uncertainty, I at least am reluctant to land deep changes to the compiler at this time, and in particular not to the trait system (which I think is due for some overhauls). Past experience (e.g., with the Speaking personally: I do intend to leave a comment on rust-lang/rfcs#2255 "real soon now" trying to spell out some of the specific confusion that can arise from |
Team member @nikomatsakis has proposed to close 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. |
Ping for ticky boxes @Zoxc, @arielb1, @jseyfried, @michaelwoerister! |
I tagged @arielb1 (who should be moved to alumni status, really) as well as @michaelwoerister (who is on vacation afaik) and @jseyfried (who probably also should be moved to alumni status). |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@nikomatsakis you can modify the FCP list here: https://github.com/anp/rfcbot-rs/blob/master/teams.toml |
The final comment period is now complete. |
OK, going to close. Thanks @mikeyhew |
@nikomatsakis The language team decision against The problem seems to be |
@Ericson2314 I agree with you, I think that ultimately having a trait or traits like I've been meaning to comment on https://internals.rust-lang.org/t/pre-erfc-lets-fix-dsts/6663 and keep the discussion going, and I still think that is the best way forward – we should get an eRFC merged and start working on things experimentally. |
I managed to rebase @plietar's PR #44469, and get all the tests passing.
This unfortunately conflicts with #44917 (by @Zoxc) in a lot of places, so one of us will have to do a rebase after the other gets merged.
r? @pnkfelix since you were reviewing #44469
cc @arielb1