-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Support miri #51
Comments
I don't have any experience with miri, so I'm not really sure what to do with this bug report. As it is, it isn't actionable, as I don't know what outcome you're hoping for here in terms of this crate in particular. It sounds like this is a bug for miri, not memchr. |
Yeah, as |
I figured as much, but I don't know if I would be or not, because I don't know what it would entail and what the consequences would be. Some brief thoughts:
|
The idea isn't necessarily to test |
Also looks like Miri just got fixed to support bit math on pointers: rust-lang/rust#63839 |
If there's a simple patch that someone wants to submit that would improve quality of life for miri users, then I think I'd be happy to accept it. |
Hello, I got pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
cfg_if::cfg_if! {
if #[cfg(miri)] {
let imp = naive::memchr;
} else if #[cfg(all(target_arch = "x86_64", memchr_runtime_simd))] {
let imp = x86::memchr;
} else if #[cfg(memchr_libc)] {
let imp = c::memchr;
} else {
let imp = fallback::memchr;
}
};
...
} vs pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
#[cfg(miri)]
#[inline(always)]
fn imp(n1: u8, haystack: &[u8]) -> Option<usize> {
naive::memchr(n1, haystack)
}
#[cfg(all(not(miri), target_arch = "x86_64", memchr_runtime_simd))]
#[inline(always)]
fn imp(n1: u8, haystack: &[u8]) -> Option<usize> {
x86::memchr(n1, haystack)
}
#[cfg(all(
not(miri),
not(target_arch = "x86_64"),
not(memchr_runtime_simd),
memchr_libc,
))]
#[inline(always)]
fn imp(n1: u8, haystack: &[u8]) -> Option<usize> {
c::memchr(n1, haystack)
}
#[cfg(all(
not(miri),
not(memchr_libc),
not(target_arch = "x86_64"),
not(memchr_runtime_simd),
))]
#[inline(always)]
fn imp(n1: u8, haystack: &[u8]) -> Option<usize> {
fallback::memchr(n1, haystack)
}
...
} What would be your preference, @BurntSushi? |
@ldesgoui Thanks! I think submitting a PR as is would be great. I'd really like to try to avoid additional dependencies. ( |
Sounds good to me, coming right up! |
@ldesgoui Yeah, that diff looks fine to me. It doesn't really make the current situation much worse. |
MIRI has problems dealing with SIMD or raw pointers, so we cannot use the fallback or SIMD accelerated versions. Instead, we fall back to the "naive" version using iterators. Ideally, this is a temporary measure to make more things work with MIRI in practice. In the future, this work-around shouldn't be needed. Closes #51
The crate does not seem to work well with miri at the moment for multiple reasons. One reason is that the crate uses the x86 / C implementations over the fallback implementation, which miri doesn't support. But even when cfg'ing out those implementations via cfg(miri), the fallback implementation uses a lot of bit math on pointers, which miri also doesn't like.
The text was updated successfully, but these errors were encountered: