Skip to content

Commit c60b7cd

Browse files
committed
Remove special cases for emscripten
Because emscripten supports 128-bit integers now, we no longer have to add special cases for it. In particular, we can now use ChaCha12 on all platforms.
1 parent 8a07c93 commit c60b7cd

File tree

9 files changed

+10
-45
lines changed

9 files changed

+10
-45
lines changed

Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ getrandom = ["rand_core/getrandom"]
3636
simd_support = ["packed_simd"]
3737

3838
# Option (enabled by default): enable StdRng
39-
std_rng = ["rand_chacha", "rand_hc"]
39+
std_rng = ["rand_chacha"]
4040

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

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

73-
# Emscripten does not support 128-bit integers, which are used by ChaCha code.
74-
# We work around this by using a different RNG.
75-
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
76-
rand_chacha = { path = "rand_chacha", version = "0.3.0", default-features = false, optional = true }
77-
[target.'cfg(target_os = "emscripten")'.dependencies]
78-
rand_hc = { path = "rand_hc", version = "0.3.0", optional = true }
79-
8074
[dev-dependencies]
8175
rand_pcg = { path = "rand_pcg", version = "0.3.0" }
8276
# Only for benches:

rand_distr/src/weighted_alias.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,12 @@ macro_rules! impl_weight_for_int {
353353
impl_weight_for_float!(f64);
354354
impl_weight_for_float!(f32);
355355
impl_weight_for_int!(usize);
356-
#[cfg(not(target_os = "emscripten"))]
357-
#[cfg_attr(doc_cfg, doc(cfg(not(target_os = "emscripten"))))]
358356
impl_weight_for_int!(u128);
359357
impl_weight_for_int!(u64);
360358
impl_weight_for_int!(u32);
361359
impl_weight_for_int!(u16);
362360
impl_weight_for_int!(u8);
363361
impl_weight_for_int!(isize);
364-
#[cfg(not(target_os = "emscripten"))]
365-
#[cfg_attr(doc_cfg, doc(cfg(not(target_os = "emscripten"))))]
366362
impl_weight_for_int!(i128);
367363
impl_weight_for_int!(i64);
368364
impl_weight_for_int!(i32);
@@ -401,14 +397,12 @@ mod test {
401397
);
402398
}
403399

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

411-
#[cfg(not(target_os = "emscripten"))]
412406
#[test]
413407
#[cfg_attr(miri, ignore)] // Miri is too slow
414408
fn test_weighted_index_i128() {

rand_pcg/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
#![deny(missing_debug_implementations)]
3838
#![no_std]
3939

40-
#[cfg(not(target_os = "emscripten"))] mod pcg128;
40+
mod pcg128;
4141
mod pcg64;
4242

43-
#[cfg(not(target_os = "emscripten"))]
4443
pub use self::pcg128::{Lcg128Xsl64, Mcg128Xsl64, Pcg64, Pcg64Mcg};
4544
pub use self::pcg64::{Lcg64Xsh32, Pcg32};

src/distributions/integer.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::Rng;
1414
use core::arch::x86::{__m128i, __m256i};
1515
#[cfg(all(target_arch = "x86_64", feature = "simd_support"))]
1616
use core::arch::x86_64::{__m128i, __m256i};
17-
#[cfg(not(target_os = "emscripten"))] use core::num::NonZeroU128;
18-
use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
17+
use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
18+
NonZeroU128};
1919
#[cfg(feature = "simd_support")] use packed_simd::*;
2020

2121
impl Distribution<u8> for Standard {
@@ -46,7 +46,6 @@ impl Distribution<u64> for Standard {
4646
}
4747
}
4848

49-
#[cfg(not(target_os = "emscripten"))]
5049
impl Distribution<u128> for Standard {
5150
#[inline]
5251
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 {
@@ -86,7 +85,6 @@ impl_int_from_uint! { i8, u8 }
8685
impl_int_from_uint! { i16, u16 }
8786
impl_int_from_uint! { i32, u32 }
8887
impl_int_from_uint! { i64, u64 }
89-
#[cfg(not(target_os = "emscripten"))]
9088
impl_int_from_uint! { i128, u128 }
9189
impl_int_from_uint! { isize, usize }
9290

@@ -108,7 +106,6 @@ impl_nzint!(NonZeroU8, NonZeroU8::new);
108106
impl_nzint!(NonZeroU16, NonZeroU16::new);
109107
impl_nzint!(NonZeroU32, NonZeroU32::new);
110108
impl_nzint!(NonZeroU64, NonZeroU64::new);
111-
#[cfg(not(target_os = "emscripten"))]
112109
impl_nzint!(NonZeroU128, NonZeroU128::new);
113110
impl_nzint!(NonZeroUsize, NonZeroUsize::new);
114111

@@ -173,15 +170,13 @@ mod tests {
173170
rng.sample::<i16, _>(Standard);
174171
rng.sample::<i32, _>(Standard);
175172
rng.sample::<i64, _>(Standard);
176-
#[cfg(not(target_os = "emscripten"))]
177173
rng.sample::<i128, _>(Standard);
178174

179175
rng.sample::<usize, _>(Standard);
180176
rng.sample::<u8, _>(Standard);
181177
rng.sample::<u16, _>(Standard);
182178
rng.sample::<u32, _>(Standard);
183179
rng.sample::<u64, _>(Standard);
184-
#[cfg(not(target_os = "emscripten"))]
185180
rng.sample::<u128, _>(Standard);
186181
}
187182

src/distributions/uniform.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,13 @@ uniform_int_impl! { i8, u8, u32 }
556556
uniform_int_impl! { i16, u16, u32 }
557557
uniform_int_impl! { i32, u32, u32 }
558558
uniform_int_impl! { i64, u64, u64 }
559-
#[cfg(not(target_os = "emscripten"))]
560559
uniform_int_impl! { i128, u128, u128 }
561560
uniform_int_impl! { isize, usize, usize }
562561
uniform_int_impl! { u8, u8, u32 }
563562
uniform_int_impl! { u16, u16, u32 }
564563
uniform_int_impl! { u32, u32, u32 }
565564
uniform_int_impl! { u64, u64, u64 }
566565
uniform_int_impl! { usize, usize, usize }
567-
#[cfg(not(target_os = "emscripten"))]
568566
uniform_int_impl! { u128, u128, u128 }
569567

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

@@ -1292,9 +1290,7 @@ mod tests {
12921290
);)*
12931291
}};
12941292
}
1295-
t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
1296-
#[cfg(not(target_os = "emscripten"))]
1297-
t!(i128, u128);
1293+
t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, i128, u128);
12981294

12991295
#[cfg(feature = "simd_support")]
13001296
{

src/distributions/utils.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ macro_rules! wmul_impl {
5656
wmul_impl! { u8, u16, 8 }
5757
wmul_impl! { u16, u32, 16 }
5858
wmul_impl! { u32, u64, 32 }
59-
#[cfg(not(target_os = "emscripten"))]
6059
wmul_impl! { u64, u128, 64 }
6160

6261
// This code is a translation of the __mulddi3 function in LLVM's
@@ -120,9 +119,6 @@ macro_rules! wmul_impl_large {
120119
)+
121120
};
122121
}
123-
#[cfg(target_os = "emscripten")]
124-
wmul_impl_large! { u64, 32 }
125-
#[cfg(not(target_os = "emscripten"))]
126122
wmul_impl_large! { u128, 64 }
127123

128124
macro_rules! wmul_impl_usize {

src/distributions/weighted.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ pub mod alias_method {
4343
impl_weight!(f64, f32,);
4444
impl_weight!(u8, u16, u32, u64, usize,);
4545
impl_weight!(i8, i16, i32, i64, isize,);
46-
#[cfg(not(target_os = "emscripten"))]
4746
impl_weight!(u128, i128,);
4847
}

src/rng.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,8 @@ macro_rules! impl_fill {
389389
}
390390
}
391391

392-
impl_fill!(u16, u32, u64, usize,);
393-
#[cfg(not(target_os = "emscripten"))]
394-
impl_fill!(u128);
395-
impl_fill!(i8, i16, i32, i64, isize,);
396-
#[cfg(not(target_os = "emscripten"))]
397-
impl_fill!(i128);
392+
impl_fill!(u16, u32, u64, usize, u128,);
393+
impl_fill!(i8, i16, i32, i64, isize, i128,);
398394

399395
#[cfg(feature = "min_const_gen")]
400396
impl<T, const N: usize> Fill for [T; N]

src/rngs/std.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
1111
use crate::{CryptoRng, Error, RngCore, SeedableRng};
1212

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

18-
#[cfg(not(target_os = "emscripten"))] use rand_chacha::ChaCha12Rng as Rng;
19-
#[cfg(target_os = "emscripten")] use rand_hc::Hc128Rng as Rng;
15+
use rand_chacha::ChaCha12Rng as Rng;
2016

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

0 commit comments

Comments
 (0)