You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The tracking issue for std::io::Read::initializer makes it sound like that API is definitely going to be changed a lot, it would be good to remove the similar API here until the std API is closer to its final form.
It seems to me like we're at an awkward point with regards to the desired functionality here.
If it's decided that &mut [u8] to uninitialized memory is UB, then we need to add methods like unsafe fn read_uninit(&mut self, buf: &mut MaybeUninit<[u8]>).
However, if it is decided to NOT be UB, then we don't need those methods, and don't need to suffer the churn.
Whether or not an &mut [u8] pointing to uninitialized memory is UB, there was earlier discussion in the tracking issue about how the ceremony in the current API doesn't provide much utility and it could be replaced with a simpler API. It would be disappointing if AsyncRead ended up with a different, more complicated API than Read.
unsafe fn may_read_buffer(&self) -> bool { true } is incorrect because it is unsafe to implement, not unsafe to call. The only way today to make something unsafe to implement is via a separate unsafe trait, or something which is forced to call an unsafe function, at which point you wind up back at the current initializer API.
The requirement that unsafe fn in traits is only unsafe to call, not unsafe to implement? I'm not aware of an existing UCG proposal for that, but I'd certainly be interested in one, yes.
That seems more like Reference material than UCG. There's no open questions, just things are a bit surprising (rust-lang/rfcs#2585 would improve things IMO by making the role of unsafe fn clearer).
Activity
cramertj commentedon Jul 23, 2019
Yeah, it seems like there's some push towards having
freeze()
instead. cc @seanmonstar @RalfJungRalfJung commentedon Jul 24, 2019
There was a push at rust-lang/rust#58363, but there are two issues with this:
freeze
with the desired semantics basically means that a program can observe uninitialized memory without causing UB. See https://www.reddit.com/r/rust/comments/apreqi/ucgmiri_allhands_2019_recap/egarzl8/ for some links.freeze
cannot actually be a NOP; uninitialized memory can actually be unstable.Note however that the current
initializer
API is incompatible with rust-lang/unsafe-code-guidelines#77, at least if rust-lang/unsafe-code-guidelines#71 ends up deciding that integers must be initialized to be valid.seanmonstar commentedon Jul 24, 2019
It seems to me like we're at an awkward point with regards to the desired functionality here.
&mut [u8]
to uninitialized memory is UB, then we need to add methods likeunsafe fn read_uninit(&mut self, buf: &mut MaybeUninit<[u8]>)
.Nemo157 commentedon Jul 25, 2019
Whether or not an
&mut [u8]
pointing to uninitialized memory is UB, there was earlier discussion in the tracking issue about how the ceremony in the current API doesn't provide much utility and it could be replaced with a simpler API. It would be disappointing ifAsyncRead
ended up with a different, more complicated API thanRead
.taiki-e commentedon Aug 30, 2019
I think we should choose one of the following:
Read::initializer
rust#42788 (comment)AsyncRead::initializer
unstable API - this will be near to what std is doing.cramertj commentedon Aug 30, 2019
+1 for making it unstable. The "simpler API" is unsound, though, so I don't want to do that.
carllerche commentedon Aug 30, 2019
@cramertj what is unsound about it?
cramertj commentedon Aug 30, 2019
unsafe fn may_read_buffer(&self) -> bool { true }
is incorrect because it isunsafe
to implement, not unsafe to call. The only way today to make something unsafe to implement is via a separateunsafe
trait, or something which is forced to call anunsafe
function, at which point you wind up back at the current initializer API.carllerche commentedon Aug 30, 2019
@cramertj makes sense, thanks for the explanation. Is the intent to document the unsafe requirements you describe as part of https://github.com/rust-lang/unsafe-code-guidelines or some other location?
cramertj commentedon Aug 30, 2019
The requirement that
unsafe fn
in traits is only unsafe to call, not unsafe to implement? I'm not aware of an existing UCG proposal for that, but I'd certainly be interested in one, yes.RalfJung commentedon Aug 31, 2019
That seems more like Reference material than UCG. There's no open questions, just things are a bit surprising (rust-lang/rfcs#2585 would improve things IMO by making the role of
unsafe fn
clearer).Merge #255
2 remaining items