Skip to content
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 by using naive implementations #67

Merged
merged 2 commits into from
Feb 12, 2020
Merged

Support MIRI by using naive implementations #67

merged 2 commits into from
Feb 12, 2020

Conversation

ldesgoui
Copy link
Contributor

@ldesgoui ldesgoui commented Feb 12, 2020

Closes #51
Some reordering was introduced in cfg attributes to make it consistent

if a {
    ...
} else if all(b, c) {
    ...
} else if d {
    ...
} else {
    ...
}

becomes

#[cfg(a)]
...
#[cfg(all(
    b,
    c,
    not(a),
))]
...
#[cfg(all(
   d,
   not(all(b, c, a)),
))]
...
#[cfg(all(
    not(d),
    not(all(b, c)),
    not(a),
))]
...

It highlights which component of the conditional is important/introduced by putting them first

Closes #51
Some reordering was introduced in `cfg` attributes to make it consistent
@ldesgoui
Copy link
Contributor Author

Woops, looking into breakage

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

src/lib.rs Outdated
target_arch = "x86_64",
memchr_runtime_simd,
memchr_libc
)))]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is your issue. I think you want:

#[cfg(all(
    not(memchr_libc),
    not(all(target_arch = "x86_64", memchr_runtime_simd)),
    not(miri),
))]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, !A && !(B && C) is (!A && !B) || (!A && !C) 🤦‍♂️

src/lib.rs Outdated
#[inline(always)]
fn imp(n1: u8, haystack: &[u8]) -> Option<usize> {
x86::memchr(n1, haystack)
}

#[cfg(all(
memchr_libc,
not(all(target_arch = "x86_64", memchr_runtime_simd))
not(all(miri, target_arch = "x86_64", memchr_runtime_simd))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using similar cfg knobs, could you make sure they are in the same order? e.g., I'd put miri last here, in order to match all(target_arch = "x86_64", memchr_runtime_simd, not(miri)) above.

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I appreciate you persisting without the use of cfg-if. I know it's a pain.

@BurntSushi BurntSushi merged commit 72ad872 into BurntSushi:master Feb 12, 2020
@BurntSushi
Copy link
Owner

This is on crates.io in memchr 2.3.1.

@ldesgoui
Copy link
Contributor Author

Thanks for the crate, the help and the responsiveness! Much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support miri
2 participants