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

Is the separate nightly version still needed after 1.27.0? #102

Closed
anp opened this issue Jun 21, 2018 · 6 comments
Closed

Is the separate nightly version still needed after 1.27.0? #102

anp opened this issue Jun 21, 2018 · 6 comments

Comments

@anp
Copy link
Contributor

anp commented Jun 21, 2018

A very slightly modified copy of nightly_lazy.rs compiles against 1.27 now that hint::unreachable_unchecked was stabilized. I don't actually know if the nightly version is in some way preferred or what nursery crates' compiler backcompat story is. I'm sure there are other things to consider there too.

Would a PR to make it the default be of interest?

@BurntSushi
Copy link
Member

If this is going to be done, please do it with care so that we don't cause the entire ecosystem to bump their minimum Rust version. lazy-static is as core of a crate as it gets. We should be conservative.

@KodrAus
Copy link
Contributor

KodrAus commented Jun 22, 2018

One option could be to use a build script to determine whether we're compiling against 1.27+ to decide whether we use the lazy.rs or nightly_lazy.rs source instead of (or as well as) the nightly feature since the public API is the same.

@BurntSushi
Copy link
Member

BurntSushi commented Jun 22, 2018

@KodrAus Yup! That's what I did with the regex crate to solve the same problem (but for SIMD).

@KodrAus
Copy link
Contributor

KodrAus commented Jun 22, 2018

@anp If you're interested, would you like to submit a PR that determines whether we're compiling on 1.27+ using a build.rs, similar to how regex does for simd, that enables a build feature like core_unreachable, and uses that core_unreachable feature to pull in nightly_lazy.rs instead of lazy.rs, rather than the current nightly feature? We might also want to rename nightly_lazy...

@anp
Copy link
Contributor Author

anp commented Jun 22, 2018

Sounds great to me. I'll try to do this tonight, but if someone comes along in weeks/months/years and I've abdicated please feel free to pick up!

@eddyb
Copy link
Member

eddyb commented Jun 28, 2018

You don't need language support for unreachable_unchecked if your goal is to tell the compiler that you expect an Option to be in the Some state. You can polyfill it with this:

unsafe fn unreachable_unchecked() -> ! {
    enum Void {}
    match ::std::mem::uninitialized::<Void>() {}
}

And you wouldn't even a version check, this polyfill works great (check LLVM IR/ASM), and I expect you won't need to use the one in core/std. You can just wait to remove the polyfill until you (if ever) bump the minimum needed version past 1.27.

EDIT: You can see that it works even on Rust 1.0: https://godbolt.org/g/sxroUe
EDIT2: Of course someone has made a crate already: https://docs.rs/unreachable.

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

No branches or pull requests

4 participants