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

API Docs: ptr #29371

Closed
10 of 11 tasks
steveklabnik opened this issue Oct 26, 2015 · 15 comments · Fixed by #49767
Closed
10 of 11 tasks

API Docs: ptr #29371

steveklabnik opened this issue Oct 26, 2015 · 15 comments · Fixed by #49767
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority

Comments

@steveklabnik
Copy link
Member

steveklabnik commented Oct 26, 2015

Part of #29329

http://doc.rust-lang.org/std/ptr/

Here's what needs to be done to close out this issue:

  • the module docs act like this is about *const T/*mut T, but it's really about common functions that work with them.
  • copy could link to memmove somewhere.
  • copy_nonoverlapping should link to memcpy. Both of these functions should talk more about what "overlapping" means here.
  • drop_in_place needs links and examples
  • read needs to explain why and where you should use it, as well as linking some stuff.
  • read_volitile needs links
  • replace should link to mem::replace, and justify its unsafety better.
  • swap needs to split out its summary from its description, link to mem::swap, and get an example.
  • write needs to explain when and where to use it, and to link some types
  • write_bytes needs to better justify itself, link memset, and move that out of its summary line.
  • write_volatile needs to link read.
Manishearth added a commit to Manishearth/rust that referenced this issue Apr 17, 2016
…eklabnik

Add examples for std::ptr module functions

Part of rust-lang#29371.

r? @steveklabnik
sophiajt pushed a commit to sophiajt/rust that referenced this issue Sep 2, 2016
…klabnik

add links to interesting items in `std::ptr` documentation

Part of rust-lang#29371.

r? @steveklabnik
sophiajt pushed a commit to sophiajt/rust that referenced this issue Sep 2, 2016
…klabnik

add links to interesting items in `std::ptr` documentation

Part of rust-lang#29371.

r? @steveklabnik
@steveklabnik steveklabnik added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Mar 8, 2017
@steveklabnik
Copy link
Member Author

I am happy to mentor anyone who wants to tackle this issue.

@steveklabnik steveklabnik added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Mar 10, 2017
@steveklabnik steveklabnik added P-medium Medium priority E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. and removed A-docs labels Mar 24, 2017
@bandali0
Copy link

bandali0 commented Mar 25, 2017

@steveklabnik I'd like to help tackle this by taking on some of the items. Any general suggestions before I get started?

I also have one question: any preference as to what website to use for linking to C standard library functions? How does this look for memmove?

@steveklabnik
Copy link
Member Author

I'd like to help tackle this by taking on some of the items. Any general suggestions before I get started?

Wonderful! I left a bunch of related-ish comments on https://www.reddit.com/r/rust/comments/61avqf/want_to_join_the_rust_docs_team/?st=j0s6zfg8&sh=79419433. Of course, this whole exercise has brought up a meta issue, which is that our "how to contribute to docs" docs aren't as awesome as they could be. I'm gonna try to work on that 😄

I also have one question: any preference as to what website to use for linking to C standard library functions?

This is a good question. I am not sure.

How does this look for memmove?

I haven't heard of this website before and I'm slightly skpetical of a wiki. I asked on Twitter, and got a number of responses:

I think I'm leaning towards MSDN here.

@bandali0
Copy link

Awesome. Thanks Steve. I'll get started on this in a few days (my semester's almost over).

@bandali0
Copy link

bandali0 commented Apr 6, 2017

Hey @imiuka, sure! I was thinking of doing at least copy and copy_nonoverlapping, and maybe swap. So feel free to take on any other ones you'd like to.

@Mark-Simulacrum Mark-Simulacrum added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Jul 24, 2017
@chordowl
Copy link
Contributor

chordowl commented Aug 9, 2017

Hey there @hinaria and @aminb! I'm currently going over the remaining API tracking issues and saw your comments here. Are you still interested in helping out with this?

@GuillaumeGomez
Copy link
Member

@lukaramu @hinaria: Want me to assign it to both of you "officially"?

@bandali0
Copy link

Hi all, sorry for my absence.

I still like to do copy and copy_nonoverlapping at the very least, but @lukaramu and @hinaria feel free to split the rest.

@chordowl
Copy link
Contributor

@GuillaumeGomez I'll tackle other modules first since there are people working on this one, thanks for asking though!

@QuietMisdreavus
Copy link
Member

I'm folding #36450 into this issue; basically, make sure that each function also mentions its requirements w.r.t. alignment. (Generally speaking, unless it says _unaligned, it needs the pointer to have the same alignment as the type.)

@QuietMisdreavus
Copy link
Member

No worries! Glad you're feeling better!

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Apr 6, 2018

Newbie here,

If no one's currently working on this, I'd like to pick it up.

I've added the requisite information to copy and copy_nonoverlapping. I'm using the GNU libc docs for links to memcpy and memmove.

A few questions:

  • Does write_bytes require its argument to be properly aligned?
  • Should I discuss undefined behavior under the "Undefined Behavior" heading described in RFC 1574, or keep it under "Safety"? Most documentation for std seems to use "Safety".
  • Is there good documentation for how to submit PRs for the docs somewhere? Do I just add "at steveklabnik" to the PR?

Thanks!

@steveklabnik
Copy link
Member Author

@ecstatic-morse that'd be great!

  1. I'm not actually sure!
  2. The "Undefined Behavior" convention is a newer one, and so not all of std is up to date with it. So yeah, go ahead and use it even though it's not heavily used yet. :)
  3. You don't even need to do that; the bots will assign someone. You can also put "r? @steveklabnik" to force the bot to assign it to me, but I'll probably get assigned anyway

kennytm added a commit to kennytm/rust that referenced this issue May 14, 2018
…bnik

Rewrite docs for `std::ptr`

This PR attempts to resolve rust-lang#29371.

This is a fairly major rewrite of the `std::ptr` docs, and deserves a fair bit of scrutiny. It adds links to the GNU libc docs for various instrinsics, adds internal links to types and functions referenced in the docs, adds new, more complex examples for many functions, and introduces a common template for discussing unsafety of functions in `std::ptr`.

All functions in `std::ptr` (with the exception of `ptr::eq`) are unsafe because they either read from or write to a raw pointer. The "Safety" section now informs that the function is unsafe because it dereferences a raw pointer and requires that any pointer to be read by the function points to "a valid vaue of type `T`".

Additionally, each function imposes some subset of the following conditions on its arguments.

* The pointer points to valid memory.
* The pointer points to initialized memory.
* The pointer is properly aligned.

These requirements are discussed in the "Undefined Behavior" section along with the  consequences of using functions that perform bitwise copies without requiring `T: Copy`. I don't love my new descriptions of the consequences of making such copies. Perhaps the old ones were good enough?

Some issues which still need to be addressed before this is merged:
- [ ] The new docs assert that `drop_in_place` is equivalent to calling `read` and discarding the value. Is this correct?
- [ ] Do `write_bytes` and `swap_nonoverlapping` require properly aligned pointers?
- [ ] The new example for `drop_in_place` is a lackluster.
- [ ] Should these docs rigorously define what `valid` memory is? Or should is that the job of the reference? Should we link to the reference?
- [ ] Is it correct to require that pointers that will be read from refer to "valid values of type `T`"?
- [x] I can't imagine ever using `{read,write}_volatile` with non-`Copy` types.  Should I just link to {read,write} and say that the same issues with non-`Copy` types apply?
- [x] `write_volatile` doesn't link back to `read_volatile`.
- [ ] Update docs for the unstable [`swap_nonoverlapping`](rust-lang#42818)
- [ ] Update docs for the unstable [unsafe pointer methods RFC](rust-lang/rfcs#1966)

Looking forward to your feedback.

r? @steveklabnik
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 15, 2018
…bnik

Rewrite docs for `std::ptr`

This PR attempts to resolve rust-lang#29371.

This is a fairly major rewrite of the `std::ptr` docs, and deserves a fair bit of scrutiny. It adds links to the GNU libc docs for various instrinsics, adds internal links to types and functions referenced in the docs, adds new, more complex examples for many functions, and introduces a common template for discussing unsafety of functions in `std::ptr`.

All functions in `std::ptr` (with the exception of `ptr::eq`) are unsafe because they either read from or write to a raw pointer. The "Safety" section now informs that the function is unsafe because it dereferences a raw pointer and requires that any pointer to be read by the function points to "a valid vaue of type `T`".

Additionally, each function imposes some subset of the following conditions on its arguments.

* The pointer points to valid memory.
* The pointer points to initialized memory.
* The pointer is properly aligned.

These requirements are discussed in the "Undefined Behavior" section along with the  consequences of using functions that perform bitwise copies without requiring `T: Copy`. I don't love my new descriptions of the consequences of making such copies. Perhaps the old ones were good enough?

Some issues which still need to be addressed before this is merged:
- [ ] The new docs assert that `drop_in_place` is equivalent to calling `read` and discarding the value. Is this correct?
- [ ] Do `write_bytes` and `swap_nonoverlapping` require properly aligned pointers?
- [ ] The new example for `drop_in_place` is a lackluster.
- [ ] Should these docs rigorously define what `valid` memory is? Or should is that the job of the reference? Should we link to the reference?
- [ ] Is it correct to require that pointers that will be read from refer to "valid values of type `T`"?
- [x] I can't imagine ever using `{read,write}_volatile` with non-`Copy` types.  Should I just link to {read,write} and say that the same issues with non-`Copy` types apply?
- [x] `write_volatile` doesn't link back to `read_volatile`.
- [ ] Update docs for the unstable [`swap_nonoverlapping`](rust-lang#42818)
- [ ] Update docs for the unstable [unsafe pointer methods RFC](rust-lang/rfcs#1966)

Looking forward to your feedback.

r? @steveklabnik
@GuillaumeGomez
Copy link
Member

I'll reopen this issue because it doesn't feel like it's actually fixed.

@steveklabnik
Copy link
Member Author

Triage: I have looked at all of the individual checkboxes, and 99% of the work here is done. I think these massive tracking issues have served their purpose; if you'd like to see more improvements to the ptr docs, please open one, focused issue for each improvement, and we can tackle them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants