Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCanvas unsafe code in the wild #18
Comments
nikomatsakis
changed the title
Unsafe code in the wild
Canvas unsafe code in the wild
Sep 1, 2016
nikomatsakis
added
the
K-Task
label
Sep 2, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I think they're well enough summarized. (see here) referencing pcb |
This comment has been minimized.
This comment has been minimized.
|
Another use of unsafe code, this one more type-focused than lifetime-focused: https://github.com/Diggsey/query_interface |
This comment has been minimized.
This comment has been minimized.
Ericson2314
commented
Sep 8, 2016
|
https://github.com/nathan7/libfringe is wildly unsafe. |
This comment has been minimized.
This comment has been minimized.
|
This discussion of how coroutines and scoped threads interact seems relevant, probably more as a negative case (i.e., enumerate where the coroutine abstractions goes wrong): https://www.reddit.com/r/rust/comments/508pkb/unleakable_crate_safetysanityrefocus/d72703d |
This comment has been minimized.
This comment has been minimized.
That is more of a soundness issue than a memory model issue. |
This comment has been minimized.
This comment has been minimized.
|
I don't entirely understand what is the criterion for listing pieces of the standard library. Certainly |
This comment has been minimized.
This comment has been minimized.
mystor
commented
Sep 12, 2016
|
The problem with We aren't suggesting removing |
This comment has been minimized.
This comment has been minimized.
|
What I am asking is why |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I see, that makes sense. Notice that the trouble I am having with |
This comment has been minimized.
This comment has been minimized.
What's the trouble again? |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung if you see some other aspect of ref-cell that's not documented, please do open another issue... |
This comment has been minimized.
This comment has been minimized.
|
I think the long version of this needs a blogpost, and I don't know when I will get around to write it -- and I'm still in the process of figuring out the details. I don't necessarily think it's an "issue" in the sense of something that needs to be fixed, it's more of an observation that I will try a short summary, but beware -- I am thinking in terms of "how to prove the code correct" here, not in terms of a static type system or a memory model. fn foo(x: &mut i32) {
*x = 13;
{ let y = &*x;
{ let z = &*y; }
}
}the sharing of the data pointed to by |
This comment has been minimized.
This comment has been minimized.
That is the union of the active lifetimes of the guards. This is also the lifetime of the sharing of an |
This comment has been minimized.
This comment has been minimized.
What exactly do you mean by "active lifetime of the guards"? It's certainly not the lifetime parameter in
I think |
This comment has been minimized.
This comment has been minimized.
|
Active lifetime = intersection of data lifetime and lifetimes of all type parameters. Note that |
This comment has been minimized.
This comment has been minimized.
Manishearth
commented
Oct 4, 2016
|
The Servo-Gecko interface in stylo uses tons of unsafe code (which I'm trying to reduce and refactor). We make some (iffy) assumptions about unsafe code including:
|
This comment has been minimized.
This comment has been minimized.
|
@Manishearth I think, eventually, the fourth will be undefined behavior, but the other three seem like correct assumptions. (although ArcInner is not equivalent to #[repr(C)] { *const usize, *const usize, *const T }) |
This comment has been minimized.
This comment has been minimized.
Manishearth
commented
Oct 4, 2016
|
Oh, we're not casting |
This comment has been minimized.
This comment has been minimized.
mystor
commented
Oct 4, 2016
|
I should clarify that this T @Manishearth is talking about in the casting is the enum FooVoid {}
pub struct Foo(FooVoid); |
This comment has been minimized.
This comment has been minimized.
Manishearth
commented
Oct 4, 2016
|
(I'm thinking of replacing |
This comment has been minimized.
This comment has been minimized.
|
Replace |
This comment has been minimized.
This comment has been minimized.
Manishearth
commented
Oct 4, 2016
|
Right, that's the plan |
This comment has been minimized.
This comment has been minimized.
|
@Manishearth lol, I was just pointing that out :) The |
This comment has been minimized.
This comment has been minimized.
mystor
commented
Oct 5, 2016
|
@ubsan That enum unfortunately is not zero sized, so |
This comment has been minimized.
This comment has been minimized.
|
@mystor ... eww. I'd rather do #[repr(C)]
struct Foo {
__: [i8; 0]
}in order to get rid of the chance of conversion to |
This comment has been minimized.
This comment has been minimized.
mystor
commented
Oct 5, 2016
|
@ubsan Yup, that's actually almost exactly what I'm doing. And yes, I agree that it's a hack to get around |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Oct 5, 2016
|
Just stating the obvious : There are going to be many situations where the only unsafe code consists of calls to |
This comment has been minimized.
This comment has been minimized.
|
The |
This comment has been minimized.
This comment has been minimized.
|
BTW, even if invalid values are ignored, my aliasing memory models could end up with the result of an out-of-range |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jan 21, 2017
|
I implement
|
This comment has been minimized.
This comment has been minimized.
Amanieu
commented
Jan 21, 2017
|
@bluss I think this is a good case for |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jan 22, 2017
|
Another crate:
|
This comment has been minimized.
This comment has been minimized.
llogiq
commented
Mar 16, 2017
|
bytecount (used by ripgrep&xi) has one line of unsafe to transmute aligned byte slices to usize/SIMD slices. This pattern might perhaps be factored out into its own crate, or perhaps even find a place in libstd. |
This comment has been minimized.
This comment has been minimized.
Manishearth
commented
Mar 16, 2017
|
Can't byteorder do that? |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Mar 17, 2017
|
byteorder does not deal with slice conversions. I imagine that's something like split_aligned_for but even that formulation leaves much to be desired, slice iteratorish formulation seems to codegen much better (hence the other experiments there in the same junkyard and in rawslice). |
nikomatsakis commentedSep 1, 2016
•
edited
I think we should organize a kind of "canvas" to find examples of how unsafe code is used in the wild. To start, it'd be great to enumerate a list of interesting places to look.
Here is my start at a list. Further nominations welcome. I'll try to keep the list up to date. Moreover, if you feel you've examined the source, open any relate issues and we can check it off.
rayontake_mutabomonationndarrayintrusive_collectionsby @Amanieu, cited in #19rentalOther thoughts for packages? Is this a fruitful thing to examine?