Skip to content
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

rename MaybeUninit slice methods #76217

Merged
merged 2 commits into from
Sep 5, 2020
Merged

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 1, 2020

The first methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices.

Also, do the equivalent of #76047 for the slice reference getters, and make them part of #63569 (so far they somehow had no tracking issue).

  • first_ptr -> slice_as_ptr
  • first_ptr_mut -> slice_as_mut_ptr
  • slice_get_ref -> slice_assume_init_ref
  • slice_get_mut -> slice_assume_init_mut

@rust-highfive
Copy link
Collaborator

r? @KodrAus

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 1, 2020
@RalfJung
Copy link
Member Author

RalfJung commented Sep 1, 2020

Cc @Dylan-DPC

@RalfJung RalfJung force-pushed the maybe-uninit-slice branch 2 times, most recently from 899b91b to dddc5ff Compare September 2, 2020 06:53
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 2, 2020
flt2dec: properly handle uninitialized memory

The float-to-str code currently uses uninitialized memory incorrectly (see rust-lang#76092). This PR fixes that.

Specifically, that code used `&mut [T]` as "out references", but it would be incorrect for the caller to actually pass uninitialized memory. So the PR changes this to `&mut [MaybeUninit<T>]`, and then functions return a `&[T]` to the part of the buffer that they initialized (some functions already did that, indirectly via `&Formatted`, others were adjusted to return that buffer instead of just the initialized length).

What I particularly like about this is that it moves `unsafe` to the right place: previously, the outermost caller had to use `unsafe` to assert that things are initialized; now it is the functions that do the actual initializing which have the corresponding `unsafe` block when they call `MaybeUninit::slice_get_ref` (renamed in rust-lang#76217 to `slice_assume_init_ref`).

Reviewers please be aware that I have no idea how any of this code actually works. My changes were purely mechanical and type-driven. The test suite passes so I guess I didn't screw up badly...

Cc @sfackler this is somewhat related to your RFC, and possibly some of this code could benefit from (a generalized version of) the API you describe there. But for now I think what I did is "good enough".

Fixes rust-lang#76092.
Copy link
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

@KodrAus
Copy link
Contributor

KodrAus commented Sep 4, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Sep 4, 2020

📌 Commit 0e0a47d has been approved by KodrAus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 4, 2020
matklad added a commit to matklad/rust that referenced this pull request Sep 4, 2020
rename MaybeUninit slice methods

The `first` methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices.

Also, do the equivalent of rust-lang#76047 for the slice reference getters, and make them part of rust-lang#63569 (so far they somehow had no tracking issue).

* first_ptr -> slice_as_ptr
* first_ptr_mut -> slice_as_mut_ptr
* slice_get_ref -> slice_assume_init_ref
* slice_get_mut -> slice_assume_init_mut
@matklad
Copy link
Member

matklad commented Sep 4, 2020

Failed the build in rollup, looks like this needs a rebase: https://github.com/rust-lang/rust/pull/76316/checks?check_run_id=1070824905#step:23:910

@RalfJung
Copy link
Member Author

RalfJung commented Sep 4, 2020

Ah yes, this conflicted with my own other PR that even prompted me to notice these opportunity for rename.^^ Rebased.

@bors r=KodrAus

@bors
Copy link
Contributor

bors commented Sep 4, 2020

📌 Commit 41a047d has been approved by KodrAus

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 5, 2020
rename MaybeUninit slice methods

The `first` methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices.

Also, do the equivalent of rust-lang#76047 for the slice reference getters, and make them part of rust-lang#63569 (so far they somehow had no tracking issue).

* first_ptr -> slice_as_ptr
* first_ptr_mut -> slice_as_mut_ptr
* slice_get_ref -> slice_assume_init_ref
* slice_get_mut -> slice_assume_init_mut
@Dylan-DPC-zz
Copy link

failed in rollup

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 5, 2020
first_ptr -> slice_as_ptr
first_ptr_mut -> slice_as_mut_ptr
slice_get_ref -> slice_assume_init_ref
slice_get_mut -> slice_assume_init_mut
@RalfJung
Copy link
Member Author

RalfJung commented Sep 5, 2020

Rebased again.

@bors r=KodrAus

@bors
Copy link
Contributor

bors commented Sep 5, 2020

📌 Commit 3506832 has been approved by KodrAus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 5, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 5, 2020
rename MaybeUninit slice methods

The `first` methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices.

Also, do the equivalent of rust-lang#76047 for the slice reference getters, and make them part of rust-lang#63569 (so far they somehow had no tracking issue).

* first_ptr -> slice_as_ptr
* first_ptr_mut -> slice_as_mut_ptr
* slice_get_ref -> slice_assume_init_ref
* slice_get_mut -> slice_assume_init_mut
@bors
Copy link
Contributor

bors commented Sep 5, 2020

⌛ Testing commit 3506832 with merge cdc8f06...

@bors
Copy link
Contributor

bors commented Sep 5, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: KodrAus
Pushing cdc8f06 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants