-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
0.4.0 #14
0.4.0 #14
Conversation
Looks like one of the new tests does a lot, and since Miri is pretty slow that just takes waaaay too long. What we do in other test suites is to either disable that test in Miri, or (better) reduce the number of iterations in Miri. You can use |
Great, thank you a lot for the help @RalfJung! Since Miri was complaining about the fat pointer, and since according to documentation of pub struct Cow<'a, T: Beef + ?Sized + 'a, U: Capacity> {
/// Pointer to data
ptr: NonNull<T::PointerT>,
/// This usize contains length, but it may contain other
/// information pending on impl of `Capacity`, and must therefore
/// always go through `U::len` or `U::unpack`
fat: usize,
/// Capacity field. For `beef::lean::Cow` this is 0-sized!
cap: U::Field,
/// Lifetime marker
marker: PhantomData<&'a T>,
} I've renamed |
That's not my reading. And
What's unsafe is then dereferencing the constructed raw slice pointer, which is UB via all the normal pointer provenance rules. |
Right, the problem is I was dereferencing this invalid pointer, even though all I was doing with it was calling |
That said, these are equivalent apparently: #[no_mangle]
fn len(ptr: *const [u8]) -> usize {
unsafe { std::mem::transmute::<_, (usize, usize)>(ptr).1 }
}
#[no_mangle]
fn len_UB(ptr: *const [u8]) -> usize {
unsafe { (*ptr).len() }
} len:
movq %rsi, %rax
retq
.set len_UB, len |
I think I've mentioned it before, but you actually can get the length from a raw slice pointer on stable today: fn raw_slice_len<T>(slice: ptr::NonNull<[T]>) -> usize {
let slice = slice.as_raw() as *mut [()];
(&*slice).len()
} This works because That said, I think the split design for |
It is meaningless to look at the assembly of a program that has UB. In that case the compiler just outputs something which might or might not be valid assembly, and you can read it like tea leafs. Also see this blog post. |
Yeah. I'm just running some benchmarks against my experimental json-rust branch and there are no performance drops I can measure, so I'm quite happy with this. Just waiting for serde 1.0.105 to be published now so I can add tests for borrows from json and going to merge and publish this (speaking of, those probably should be disabled in Miri). |
Why that? |
I didn't think we need to run |
Miri is slow but not that slow. ;) |
beef::lean::Cow
, found thanks to Miri and @RalfJung (closeslean
leaks #12).impl_serde
feature which provides aSerialize
andDeserialize
trait implementations.Note that it's currently impossible to make it work with#[serde(borrow)]
(relevant PR).is_borrowed
andis_owned
methods.beef::Cow<'a, T>
is now a type alias tobeef::generic::Cow<'a, T, Wide>
whereWide
is private. This doesn't change anything, merely hidesOption<NonZeroUsize>
as implementation detail and makes errors more readable.const_fn
feature now adds two separate functions instead of one:const_str
andconst_slice
for borrowing&'static str
and&'static [T]
respectively. This is the only breaking change, this release.