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

Remove special cases for emscripten #1142

Merged
merged 1 commit into from Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions Cargo.toml
Expand Up @@ -36,7 +36,7 @@ getrandom = ["rand_core/getrandom"]
simd_support = ["packed_simd"]

# Option (enabled by default): enable StdRng
std_rng = ["rand_chacha", "rand_hc"]
std_rng = ["rand_chacha"]

# Option: enable SmallRng
small_rng = []
Expand All @@ -58,6 +58,7 @@ members = [
rand_core = { path = "rand_core", version = "0.6.0" }
log = { version = "0.4.4", optional = true }
serde = { version = "1.0.103", features = ["derive"], optional = true }
rand_chacha = { path = "rand_chacha", version = "0.3.0", default-features = false, optional = true }

[dependencies.packed_simd]
# NOTE: so far no version works reliably due to dependence on unstable features
Expand All @@ -70,13 +71,6 @@ features = ["into_bits"]
# Used for fork protection (reseeding.rs)
libc = { version = "0.2.22", optional = true, default-features = false }

# Emscripten does not support 128-bit integers, which are used by ChaCha code.
# We work around this by using a different RNG.
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
rand_chacha = { path = "rand_chacha", version = "0.3.0", default-features = false, optional = true }
[target.'cfg(target_os = "emscripten")'.dependencies]
rand_hc = { path = "rand_hc", version = "0.3.0", optional = true }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "0.3.0" }
# Only for benches:
Expand Down
6 changes: 0 additions & 6 deletions rand_distr/src/weighted_alias.rs
Expand Up @@ -353,16 +353,12 @@ macro_rules! impl_weight_for_int {
impl_weight_for_float!(f64);
impl_weight_for_float!(f32);
impl_weight_for_int!(usize);
#[cfg(not(target_os = "emscripten"))]
#[cfg_attr(doc_cfg, doc(cfg(not(target_os = "emscripten"))))]
impl_weight_for_int!(u128);
impl_weight_for_int!(u64);
impl_weight_for_int!(u32);
impl_weight_for_int!(u16);
impl_weight_for_int!(u8);
impl_weight_for_int!(isize);
#[cfg(not(target_os = "emscripten"))]
#[cfg_attr(doc_cfg, doc(cfg(not(target_os = "emscripten"))))]
impl_weight_for_int!(i128);
impl_weight_for_int!(i64);
impl_weight_for_int!(i32);
Expand Down Expand Up @@ -401,14 +397,12 @@ mod test {
);
}

#[cfg(not(target_os = "emscripten"))]
#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_weighted_index_u128() {
test_weighted_index(|x: u128| x as f64);
}

#[cfg(not(target_os = "emscripten"))]
#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_weighted_index_i128() {
Expand Down
3 changes: 1 addition & 2 deletions rand_pcg/src/lib.rs
Expand Up @@ -37,9 +37,8 @@
#![deny(missing_debug_implementations)]
#![no_std]

#[cfg(not(target_os = "emscripten"))] mod pcg128;
mod pcg128;
mod pcg64;

#[cfg(not(target_os = "emscripten"))]
pub use self::pcg128::{Lcg128Xsl64, Mcg128Xsl64, Pcg64, Pcg64Mcg};
pub use self::pcg64::{Lcg64Xsh32, Pcg32};
9 changes: 2 additions & 7 deletions src/distributions/integer.rs
Expand Up @@ -14,8 +14,8 @@ use crate::Rng;
use core::arch::x86::{__m128i, __m256i};
#[cfg(all(target_arch = "x86_64", feature = "simd_support"))]
use core::arch::x86_64::{__m128i, __m256i};
#[cfg(not(target_os = "emscripten"))] use core::num::NonZeroU128;
use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
NonZeroU128};
#[cfg(feature = "simd_support")] use packed_simd::*;

impl Distribution<u8> for Standard {
Expand Down Expand Up @@ -46,7 +46,6 @@ impl Distribution<u64> for Standard {
}
}

#[cfg(not(target_os = "emscripten"))]
impl Distribution<u128> for Standard {
#[inline]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 {
Expand Down Expand Up @@ -86,7 +85,6 @@ impl_int_from_uint! { i8, u8 }
impl_int_from_uint! { i16, u16 }
impl_int_from_uint! { i32, u32 }
impl_int_from_uint! { i64, u64 }
#[cfg(not(target_os = "emscripten"))]
impl_int_from_uint! { i128, u128 }
impl_int_from_uint! { isize, usize }

Expand All @@ -108,7 +106,6 @@ impl_nzint!(NonZeroU8, NonZeroU8::new);
impl_nzint!(NonZeroU16, NonZeroU16::new);
impl_nzint!(NonZeroU32, NonZeroU32::new);
impl_nzint!(NonZeroU64, NonZeroU64::new);
#[cfg(not(target_os = "emscripten"))]
impl_nzint!(NonZeroU128, NonZeroU128::new);
impl_nzint!(NonZeroUsize, NonZeroUsize::new);

Expand Down Expand Up @@ -173,15 +170,13 @@ mod tests {
rng.sample::<i16, _>(Standard);
rng.sample::<i32, _>(Standard);
rng.sample::<i64, _>(Standard);
#[cfg(not(target_os = "emscripten"))]
rng.sample::<i128, _>(Standard);

rng.sample::<usize, _>(Standard);
rng.sample::<u8, _>(Standard);
rng.sample::<u16, _>(Standard);
rng.sample::<u32, _>(Standard);
rng.sample::<u64, _>(Standard);
#[cfg(not(target_os = "emscripten"))]
rng.sample::<u128, _>(Standard);
}

Expand Down
8 changes: 2 additions & 6 deletions src/distributions/uniform.rs
Expand Up @@ -556,15 +556,13 @@ uniform_int_impl! { i8, u8, u32 }
uniform_int_impl! { i16, u16, u32 }
uniform_int_impl! { i32, u32, u32 }
uniform_int_impl! { i64, u64, u64 }
#[cfg(not(target_os = "emscripten"))]
uniform_int_impl! { i128, u128, u128 }
uniform_int_impl! { isize, usize, usize }
uniform_int_impl! { u8, u8, u32 }
uniform_int_impl! { u16, u16, u32 }
uniform_int_impl! { u32, u32, u32 }
uniform_int_impl! { u64, u64, u64 }
uniform_int_impl! { usize, usize, usize }
#[cfg(not(target_os = "emscripten"))]
uniform_int_impl! { u128, u128, u128 }

#[cfg(feature = "simd_support")]
Expand Down Expand Up @@ -1224,7 +1222,7 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_integers() {
#[cfg(not(target_os = "emscripten"))] use core::{i128, u128};
use core::{i128, u128};
use core::{i16, i32, i64, i8, isize};
use core::{u16, u32, u64, u8, usize};

Expand Down Expand Up @@ -1292,9 +1290,7 @@ mod tests {
);)*
}};
}
t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
#[cfg(not(target_os = "emscripten"))]
t!(i128, u128);
t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, i128, u128);

#[cfg(feature = "simd_support")]
{
Expand Down
4 changes: 0 additions & 4 deletions src/distributions/utils.rs
Expand Up @@ -56,7 +56,6 @@ macro_rules! wmul_impl {
wmul_impl! { u8, u16, 8 }
wmul_impl! { u16, u32, 16 }
wmul_impl! { u32, u64, 32 }
#[cfg(not(target_os = "emscripten"))]
wmul_impl! { u64, u128, 64 }

// This code is a translation of the __mulddi3 function in LLVM's
Expand Down Expand Up @@ -120,9 +119,6 @@ macro_rules! wmul_impl_large {
)+
};
}
#[cfg(target_os = "emscripten")]
wmul_impl_large! { u64, 32 }
#[cfg(not(target_os = "emscripten"))]
wmul_impl_large! { u128, 64 }

macro_rules! wmul_impl_usize {
Expand Down
1 change: 0 additions & 1 deletion src/distributions/weighted.rs
Expand Up @@ -43,6 +43,5 @@ pub mod alias_method {
impl_weight!(f64, f32,);
impl_weight!(u8, u16, u32, u64, usize,);
impl_weight!(i8, i16, i32, i64, isize,);
#[cfg(not(target_os = "emscripten"))]
impl_weight!(u128, i128,);
}
8 changes: 2 additions & 6 deletions src/rng.rs
Expand Up @@ -389,12 +389,8 @@ macro_rules! impl_fill {
}
}

impl_fill!(u16, u32, u64, usize,);
#[cfg(not(target_os = "emscripten"))]
impl_fill!(u128);
impl_fill!(i8, i16, i32, i64, isize,);
#[cfg(not(target_os = "emscripten"))]
impl_fill!(i128);
impl_fill!(u16, u32, u64, usize, u128,);
impl_fill!(i8, i16, i32, i64, isize, i128,);

#[cfg(feature = "min_const_gen")]
impl<T, const N: usize> Fill for [T; N]
Expand Down
6 changes: 1 addition & 5 deletions src/rngs/std.rs
Expand Up @@ -10,13 +10,9 @@

use crate::{CryptoRng, Error, RngCore, SeedableRng};

#[cfg(all(any(test, feature = "std"), not(target_os = "emscripten")))]
pub(crate) use rand_chacha::ChaCha12Core as Core;
#[cfg(all(any(test, feature = "std"), target_os = "emscripten"))]
pub(crate) use rand_hc::Hc128Core as Core;

#[cfg(not(target_os = "emscripten"))] use rand_chacha::ChaCha12Rng as Rng;
#[cfg(target_os = "emscripten")] use rand_hc::Hc128Rng as Rng;
use rand_chacha::ChaCha12Rng as Rng;

/// The standard RNG. The PRNG algorithm in `StdRng` is chosen to be efficient
/// on the current platform, to be statistically strong and unpredictable
Expand Down