Uh oh!
There was an error while loading. Please reload this page.
implement unsafe pointer methods - #43964
Conversation
rust-highfive
commented
Aug 17, 2017
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
Gankra
commented
Aug 17, 2017
Tracking Issue: #43941 |
Gankra
commented
Aug 17, 2017
strega-nil
left a comment
There was a problem hiding this comment.
I'm mostly 👍 on this, but there are some issues I'd like to see resolved, either through convincing me of the wording, or changing the wording.
There was a problem hiding this comment.
the formatting here - byte should be indented.
There was a problem hiding this comment.
this seems unnecessary to state, imo?
There was a problem hiding this comment.
It's possible to construct an offset which wraps around the address space but ends up in bounds, if pointers are modeled as "just" usizes. This would satisfy both previous rules, but fail this one. LLVM explicitly says it's UB to do this with GEP inbounds.
There was a problem hiding this comment.
Yeah, but that assumes the pointers are just usizes. I dunno, maybe I've been smoking the object model for too long.
There was a problem hiding this comment.
I don't like this paragraph. wrapping_offset is, imo, a kludge that really shouldn't ever be used. Maybe recommend add, and use actual usize pointer arithmetic in add.
There was a problem hiding this comment.
There is no unsigned version of GEP inbounds, it's impossible to ask LLVM to do this without removing the inbounds modifier, which is what wrapping_* does.
There was a problem hiding this comment.
This seems like it should use usize based pointer arithmetic, rather than casting to isize.
There was a problem hiding this comment.
As above, there is no such thing in LLVM.
There was a problem hiding this comment.
can I just say that this is so weird to me. Anyways.
There was a problem hiding this comment.
There is a reason I frequently rant about gep
strega-nil
commented
Aug 19, 2017
Well, you've convinced me. I'm a go. |
There was a problem hiding this comment.
src and dst should be val and self
carols10cents
commented
Aug 28, 2017
friendly ping @gankro to keep this on your radar! |
Gankra
commented
Aug 28, 2017
All comments addressed, and squashed. One thing I noticed myself: I didn't update *mut's offset docs before. That is now fixed. |
aidanhs
commented
Sep 7, 2017
I've pinged @sfackler on IRC for review. |
There was a problem hiding this comment.
Nit: I think we lean towards US english spelling in docs?
sfackler
commented
Sep 7, 2017
LGTM other than the one spelling nit. |
ghost
left a comment
There was a problem hiding this comment.
It is not clear to me from the documentation whether these methods may or may not be used with unaligned pointers: *offset methods, *add and *sub methods, copy* methods, *_volatile methods, drop_in_place, *_bytes methods, replace, swap.
Should I simply assume that they are safe to use with unaligned pointers, unless explicitly stated?
It'd be nice if the Safety section of every method mentioned whether unaligned pointers are allowed anyway.
Other than that, LGTM.
There was a problem hiding this comment.
By 'they may overlap' you mean 'the locations may be equal'?
What happens if you swap the values at, say, two different but overlapping locations (at least one of the pointers will be unaligned)? Is it allowed to call swap with unaligned pointers?
There was a problem hiding this comment.
You don't need alignment issues -- consider x: [u32; 3], where I swap [u32; 2] from x[0] and x[1].
There was a problem hiding this comment.
In this case the final value of x[1] is actually unspecified, but definitely one of the original values of x[0] or x[2].
strega-nil
commented
Sep 10, 2017
@stjepang Unless explicitly stated otherwise, all functions which take pointers assume that they are aligned. (see |
Gankra
commented
Sep 10, 2017
Made changes to appease american pigs ready to merge |
alexcrichton
commented
Sep 14, 2017
@bors: r=sfackler |
bors
commented
Sep 14, 2017
📌 Commit 4f24507 has been approved by |
bors
commented
Sep 15, 2017
⌛ Testing commit 4f24507 with merge bd235a61e5047f090f8a37729145b8e56f290904... |
bors
commented
Sep 15, 2017
💔 Test failed - status-travis |
alexcrichton
commented
Sep 15, 2017
@bors: retry
|
The errors in the documentation I pointed out above are still there. |
implement unsafe pointer methods I also cleaned up some existing documentation a bit here or there since I was doing so much auditing of it. Most notably I significantly rewrote the `offset` docs to clarify safety (`*const` and `*mut`'s offset docs had actually diverged).
bors
commented
Sep 16, 2017
⌛ Testing commit 4f24507 with merge 6ae1aead5260aadf8598783fe98fb9210487ddbb... |
alexcrichton
commented
Sep 16, 2017
@bors: retry
|
bors
commented
Sep 16, 2017
implement unsafe pointer methods I also cleaned up some existing documentation a bit here or there since I was doing so much auditing of it. Most notably I significantly rewrote the `offset` docs to clarify safety (`*const` and `*mut`'s offset docs had actually diverged).
bors
commented
Sep 16, 2017
☀️ Test successful - status-appveyor, status-travis |
Gankra
commented
Sep 17, 2017
Hey @tormol sorry I thought I got everything. Please file an issue for the ones I missed, or a PR to fix it, so we don't forget! |
I also cleaned up some existing documentation a bit here or there since I was doing so much auditing of it. Most notably I significantly rewrote the
offsetdocs to clarify safety (*constand*mut's offset docs had actually diverged).