-
Notifications
You must be signed in to change notification settings - Fork 48
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
Note design constraints on hypothetical DynSized
#166
Conversation
One additional note w.r.t.
|
Glad this exists! I think a struct WithLayout<T: ?DynSized> {
layout: Layout,
data: T,
};
impl<T: ?DynSized> DynSized for WithLayout<T> { ... } might also be possible to help odd-ball types use The |
The problem I illustrated with The problem is that the example It is a fundamental assumption of
Note that it's not just sufficient to say "it only writes nonzero bytes," because a data race is UB. Naively you'd want to assume that a data race on byte-sized values would only result in reading some value that's previously been written (as byte sized writes theoretically should not be able to tear), but this is not what the memory model gives us1; a write and another memory use on a different thread, at least one of which is not atomic and which are not externally synchronized is plain UB and your program no longer has any defined semantics, anything can happen, nasal demons eating your laundry, etc. So even if reading in (If there's a way I can better communicate this in not quite so many words for the document itself, I'd appreciate any edits, additions, or guidance.) Footnotes
|
I think if Anyways, what this reveals to me is that Later, if we are happy with |
It seems very subtle to allow Footnotes
|
@CAD97 Yeah I am not supposed we get deep into that now. Rather, other hand if we ignore The stuff is super trickle and subtle, which is why I don't want to make it part of the much simpler Bottom line is politically I feel like there is a tough issues to thread where:
See my choice of metaphors :). Stepping stones are used to cross bodies of water which are (locally) flat. The stepping stones are necessary to cross, but unlike the slippery slope they don't force one to finish crossing once one has begun stepping on them. |
Backlinking this here: rust-lang/rust#97052 proposes to add // std::ptr
struct TypedMetadata<T: ?Sized>(pub <T as Pointee>::Metadata);
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<TypedMetadata<U>> for TypedMetadata<T> {} This allows unsizing pointee metadata without access to an attached pointer. This would place another restriction on custom unsized types: that any unsizing must operate exclusively on the metadata without access to a pointer. I can think of one possible feature that would be eliminated by this: Consider a type |
Crossposting again for visibility: That coercion ( Writing that out: this coercion itself actually does only need the ( |
Just discussed in passing on Zulip, custom pointer metadata will likely run into all the same issues as |
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.
This is a great summary, thank you @CAD97
@CAD97 can you clarify the two above points quickly? r=me in any case, so I'll merge once you do so (or if you don't by next week, I'll merge anyway...) |
@nikomatsakis I agree that section was confusingly written and did my best to rewrite for clarity. |
Co-authored-by: Christopher Durham <cad97@cad97.com>
PR rendered
I've been meaning to write this up for a while (since the 2020-01-06 design meeting, honestly). New information brought to light in my recent irlo thread finally prompted me to collect this into one document.
This represents my best understanding of the implications and design constraints on the hypothetical
DynSized
trait. I've done my best to stay neutral and objective here.cc @Ericson2314 (pushing for
DynSized
as an implementation detail)