Skip to content

Commit 2f052a9

Browse files
authored
Merge pull request #571 from vks/automatic-i128-support
Replace `i128_support` feature with compile-time detection
2 parents 9b5db4c + b7bead9 commit 2f052a9

File tree

10 files changed

+43
-27
lines changed

10 files changed

+43
-27
lines changed

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ You may also find the [Update Guide](UPDATING.md) useful.
1010

1111
## [0.6.0] - Unreleased
1212

13+
### Crate features and organisation
14+
- The ISAAC and Xorshift RNGs have been moved to their own crates: `rand_isaac`
15+
and `rand_xorshift`. (#551, #557)
16+
- `Uniform` supports inclusive ranges: `Uniform::from(a..=b)`. This is
17+
automatically enabled for Rust >= 1.27. (#566)
18+
- Support for `i128` and `u128` is automatically enabled for Rust >= 1.26. This
19+
renders the `i128_support` feature obsolete. It still exists for backwards
20+
compatibility but does not have any effect. This breaks programs using Rand
21+
with `i128_support` on nightlies older than Rust 1.26. (#571)
22+
23+
### New distributions
24+
- Added sampling from the unit sphere and circle. (#567)
25+
1326
### Sequences module
1427
- Optimised and changed return type of the `sample_indices` function. (#479)
28+
- Added weighted sampling. (#518)
29+
30+
### Platform support
31+
- Added support for wasm-bindgen. (#541)
32+
- Added basic SIMD support. (#523)
1533

1634
## [0.5.4] - 2018-07-11
1735
### Platform support

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ appveyor = { repository = "alexcrichton/rand" }
2020

2121
[features]
2222
default = ["std" ] # without "std" rand uses libcore
23-
nightly = ["i128_support", "simd_support"] # enables all features requiring nightly rust
23+
nightly = ["simd_support"] # enables all features requiring nightly rust
2424
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
2525
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
26-
i128_support = [] # enables i128 and u128 support
26+
i128_support = [] # dummy feature for backwards compatibility
2727
simd_support = ["packed_simd"] # enables SIMD support
2828
serde1 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs
2929

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ Rand is built with only the `std` feature enabled by default. The following
115115
optional features are available:
116116

117117
- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
118-
- `i128_support` enables support for generating `u128` and `i128` values.
119118
- `log` enables some logging via the `log` crate.
120-
- `nightly` enables all unstable features (`i128_support`, `simd_support`).
119+
- `nightly` enables all unstable features (`simd_support`).
121120
- `serde1` enables serialization for some types, via Serde version 1.
122121
- `simd_support` enables uniform sampling of SIMD types (integers and floats).
123122
- `stdweb` enables support for `OsRng` on `wasm32-unknown-unknown` via `stdweb`

build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extern crate rustc_version;
22
use rustc_version::{version, Version};
33

44
fn main() {
5+
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
6+
println!("cargo:rustc-cfg=rust_1_26");
7+
}
58
if version().unwrap() >= Version::parse("1.27.0").unwrap() {
69
println!("cargo:rustc-cfg=rust_1_27");
710
}

src/deprecated.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ impl SeedableRng for ChaChaRng {
151151
}
152152

153153
impl ChaChaRng {
154-
#[cfg(feature = "i128_support")]
154+
#[cfg(rust_1_26)]
155155
pub fn get_word_pos(&self) -> u128 {
156156
self.0.get_word_pos()
157157
}
158158

159-
#[cfg(feature = "i128_support")]
159+
#[cfg(rust_1_26)]
160160
pub fn set_word_pos(&mut self, word_offset: u128) {
161161
self.0.set_word_pos(word_offset)
162162
}

src/distributions/integer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Distribution<u64> for Standard {
4343
}
4444
}
4545

46-
#[cfg(feature = "i128_support")]
46+
#[cfg(rust_1_26)]
4747
impl Distribution<u128> for Standard {
4848
#[inline]
4949
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 {
@@ -83,7 +83,7 @@ impl_int_from_uint! { i8, u8 }
8383
impl_int_from_uint! { i16, u16 }
8484
impl_int_from_uint! { i32, u32 }
8585
impl_int_from_uint! { i64, u64 }
86-
#[cfg(feature = "i128_support")] impl_int_from_uint! { i128, u128 }
86+
#[cfg(rust_1_26)] impl_int_from_uint! { i128, u128 }
8787
impl_int_from_uint! { isize, usize }
8888

8989
#[cfg(feature="simd_support")]
@@ -134,15 +134,15 @@ mod tests {
134134
rng.sample::<i16, _>(Standard);
135135
rng.sample::<i32, _>(Standard);
136136
rng.sample::<i64, _>(Standard);
137-
#[cfg(feature = "i128_support")]
137+
#[cfg(rust_1_26)]
138138
rng.sample::<i128, _>(Standard);
139139

140140
rng.sample::<usize, _>(Standard);
141141
rng.sample::<u8, _>(Standard);
142142
rng.sample::<u16, _>(Standard);
143143
rng.sample::<u32, _>(Standard);
144144
rng.sample::<u64, _>(Standard);
145-
#[cfg(feature = "i128_support")]
145+
#[cfg(rust_1_26)]
146146
rng.sample::<u128, _>(Standard);
147147
}
148148
}

src/distributions/uniform.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ uniform_int_impl! { i8, i8, u8, i32, u32 }
471471
uniform_int_impl! { i16, i16, u16, i32, u32 }
472472
uniform_int_impl! { i32, i32, u32, i32, u32 }
473473
uniform_int_impl! { i64, i64, u64, i64, u64 }
474-
#[cfg(feature = "i128_support")]
474+
#[cfg(rust_1_26)]
475475
uniform_int_impl! { i128, i128, u128, u128, u128 }
476476
uniform_int_impl! { isize, isize, usize, isize, usize }
477477
uniform_int_impl! { u8, i8, u8, i32, u32 }
478478
uniform_int_impl! { u16, i16, u16, i32, u32 }
479479
uniform_int_impl! { u32, i32, u32, i32, u32 }
480480
uniform_int_impl! { u64, i64, u64, i64, u64 }
481481
uniform_int_impl! { usize, isize, usize, isize, usize }
482-
#[cfg(feature = "i128_support")]
482+
#[cfg(rust_1_26)]
483483
uniform_int_impl! { u128, u128, u128, i128, u128 }
484484

485485

@@ -859,7 +859,7 @@ mod tests {
859859
}
860860
t!(i8, i16, i32, i64, isize,
861861
u8, u16, u32, u64, usize);
862-
#[cfg(feature = "i128_support")]
862+
#[cfg(rust_1_26)]
863863
t!(i128, u128)
864864
}
865865

src/distributions/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ macro_rules! wmul_impl {
4040
wmul_impl! { u8, u16, 8 }
4141
wmul_impl! { u16, u32, 16 }
4242
wmul_impl! { u32, u64, 32 }
43-
#[cfg(feature = "i128_support")]
43+
#[cfg(rust_1_26)]
4444
wmul_impl! { u64, u128, 64 }
4545

4646
// This code is a translation of the __mulddi3 function in LLVM's
@@ -75,9 +75,9 @@ macro_rules! wmul_impl_large {
7575
}
7676
}
7777
}
78-
#[cfg(not(feature = "i128_support"))]
78+
#[cfg(not(rust_1_26))]
7979
wmul_impl_large! { u64, 32 }
80-
#[cfg(feature = "i128_support")]
80+
#[cfg(rust_1_26)]
8181
wmul_impl_large! { u128, 64 }
8282

8383
macro_rules! wmul_impl_usize {

src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@
226226

227227
#![cfg_attr(not(feature="std"), no_std)]
228228
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
229-
#![cfg_attr(all(feature="i128_support", feature="nightly"), allow(stable_features))] // stable since 2018-03-27
230-
#![cfg_attr(all(feature="i128_support", feature="nightly"), feature(i128_type, i128))]
231229
#![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))]
232230
#![cfg_attr(feature = "stdweb", recursion_limit="128")]
233231
#![cfg_attr(feature = "wasm-bindgen", feature(use_extern_macros))]
@@ -718,13 +716,13 @@ macro_rules! impl_as_byte_slice {
718716
impl_as_byte_slice!(u16);
719717
impl_as_byte_slice!(u32);
720718
impl_as_byte_slice!(u64);
721-
#[cfg(feature="i128_support")] impl_as_byte_slice!(u128);
719+
#[cfg(rust_1_26)] impl_as_byte_slice!(u128);
722720
impl_as_byte_slice!(usize);
723721
impl_as_byte_slice!(i8);
724722
impl_as_byte_slice!(i16);
725723
impl_as_byte_slice!(i32);
726724
impl_as_byte_slice!(i64);
727-
#[cfg(feature="i128_support")] impl_as_byte_slice!(i128);
725+
#[cfg(rust_1_26)] impl_as_byte_slice!(i128);
728726
impl_as_byte_slice!(isize);
729727

730728
macro_rules! impl_as_byte_slice_arrays {

src/prng/chacha.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ impl ChaChaRng {
114114
/// not supported, hence the result can simply be multiplied by 4 to get a
115115
/// byte-offset.
116116
///
117-
/// Note: this function is currently only available when the `i128_support`
118-
/// feature is enabled. In the future this will be enabled by default.
119-
#[cfg(feature = "i128_support")]
117+
/// Note: this function is currently only available with Rust 1.26 or later.
118+
#[cfg(rust_1_26)]
120119
pub fn get_word_pos(&self) -> u128 {
121120
let mut c = (self.0.core.state[13] as u64) << 32
122121
| (self.0.core.state[12] as u64);
@@ -136,9 +135,8 @@ impl ChaChaRng {
136135
/// simply cycles at the end of its period (1 ZiB), we ignore the upper
137136
/// 60 bits.
138137
///
139-
/// Note: this function is currently only available when the `i128_support`
140-
/// feature is enabled. In the future this will be enabled by default.
141-
#[cfg(feature = "i128_support")]
138+
/// Note: this function is currently only available with Rust 1.26 or later.
139+
#[cfg(rust_1_26)]
142140
pub fn set_word_pos(&mut self, word_offset: u128) {
143141
let index = (word_offset as usize) & 0xF;
144142
let counter = (word_offset >> 4) as u64;
@@ -333,7 +331,7 @@ mod test {
333331
}
334332

335333
#[test]
336-
#[cfg(feature = "i128_support")]
334+
#[cfg(rust_1_26)]
337335
fn test_chacha_true_values_c() {
338336
// Test vector 4 from
339337
// https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04

0 commit comments

Comments
 (0)