-
Notifications
You must be signed in to change notification settings - Fork 14
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
Audit/document/remove unsafe code #27
Comments
Hi there, I contributed a bit to |
That would be awesome! Given that I'm attempting to maintain a crate that I didn't write (and with the original author not around to give feedback), I'm particularly concerned about having good documentation about the invariants that we need to preserve. |
Greetings, just checking in. I haven't forgotten about this, I didn't have time to much work on this this past weekend. I have gone through the code and just made sure that I can explain everything when I do write it up. I just have one or two questions. Would you mind if I prepare the documentation in a fork for the repo? Or would you like it in a separate document (Google Docs, etc)? I might do a bit more than just unsafe with the documentation, there are some gotchas in places that I think should be documented as well. |
My ideal location for documentation would be as doc comments in the code (on private items, so they aren't visible in the API docs but you can compile them with |
Assuming I'm right, I think this is something worth documenting. (Edit: I wasn't right) |
Ok, I think I've understood the motivation behind the owning let (f1, mut f2) = vec.focus_mut().split_at(100);
let f1 = f1.unmut(); then you have a A consequence of this is that the signature of |
Yes, that sounds correct. One thing I've realised |
I guess I can think of a couple of possible motivations, although I'm not really sure how compelling they are:
As for what to do about it, I suppose I should grep through some enum Focus<'a, A> {
Single(&'a [A]),
Full(TreeFocus<'a, A>),
Unmuted(FocusMut<'a, A>),
} |
Ah yes, sorry in my experimental repo I have worked around the need for having a lock. When split is called, I do a This makes Focus and FocusMut on a more level playing field. |
For the second bullet point (about moving before having a value to move in), you could use the take_mut crate. |
We have unsafe code in a few places, and the invariants that need to be upheld are not always well-documented.
Vector::swap
we use unsafe because rust doesn't know that pointers to different indices are non-overlapping. I think this is fine, although it could be removed at the cost of aclone()
and an extraswap
.Entry
. I'm not sure what the cost of that is.imbl
(it's only relevant when usingRc
instead ofArc
, and we don't have that yet). This part is therefore a lower priority.Focus
andFocusMut
. This will take some time to figure out. There's some subtlety inFocusMut::split_at
andFocusMut::unmut
.The text was updated successfully, but these errors were encountered: