Bug 1411250 - Revendor deps; r?xidorn
MozReview-Commit-ID: 5Wbf8VKNnDU
--- a/third_party/rust/rand/.cargo-checksum.json
+++ b/third_party/rust/rand/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{".travis.yml":"c5edd03cb5679918a6d85f64c0a634ed83022ff85ea78f440f39fd281bd29c02","Cargo.toml":"e7efa66cdfb551389cc7485818a776cb289f248079df2247eece7f57b30c3abe","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"51831128477b9c9db0ec632ed6b6164f4e70e2d5f21eb5b3a391ecb9ab35e727","appveyor.yml":"6bf2f0c8f17d2dc4957dd39aba9a88ced3130200cf847a76d47b6c8fdcc2cbd8","benches/bench.rs":"2d3481c524841c532b9b9705073b223fd4b308c86ed7c9188b7fcd8e595ad459","benches/distributions/exponential.rs":"99cb59c013a0b6bb390d34c5649b341fc3b88ea7df0caf2470bdda8798f9fe3d","benches/distributions/gamma.rs":"3533f311e4b55d743c5b01a7eb6529c94fd97726ef6702a6372f914f5f33666b","benches/distributions/mod.rs":"0028f1cb96f61152ed5b49a4fe91227d809ef6d19035592c36032a538af7f95e","benches/distributions/normal.rs":"4e10c18cb583ccb96301ea953c8e0aa9ee3b6662060271d1b8d19ca23364dc6b","src/chacha.rs":"529c20ca1eff845da4cdca9ac995bcb8e698e48a61fbae91f09e3b4600ac57c3","src/distributions/exponential.rs":"103c8412c8a581b71835f1c00e40f6370e7702adf9d499243933a793d132d4e7","src/distributions/gamma.rs":"8403bce8e78a42eda20578329d4f5e7ccbb86139a39d6efbd2d37b698d36e946","src/distributions/mod.rs":"2c042ad7d0d53f9c54c02d11e1e623bca8906785cf4264ad708fa05420724f52","src/distributions/normal.rs":"1562b43f80e4d5f83a8deb5af18de5a18dfeeeeda11fefc577da26672b14c949","src/distributions/range.rs":"c0ac6858d6a3979de7996feca22d190fde0bfb6f758d43030efa04a1a0fdcc17","src/distributions/ziggurat_tables.rs":"4eacf94fc352c91c455a6623de6a721e53842e1690f13a5662b6a79c7fbb73de","src/isaac.rs":"1725114b2d63c6fe4c0f4f7e0c36fc993a47f0322350d13abc631b0806bb71ed","src/lib.rs":"e3470f49b8ba85b590bd4375ff0d90874916cf0296637a6639a22c2a4301c3bf","src/os.rs":"ea6c5eb1a2ac8f41269d45b55655704a0ec1b8dd49d3a0a6644263c0acbad0fe","src/rand_impls.rs":"cf411028341f67fd196ccde6200eea563c993f59d360a030b3d7d3ee15447a7d","src/read.rs":"bd0eb508a6b659dc578d546fc2f231484aed80c73cfe8c475e0d65c8d699a769","src/reseeding.rs":"73b2539b86b4cb8068e54716c7fd53e0d70b6c0de787a0749431b17019c9d826"},"package":"61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae"}
\ No newline at end of file
+{"files":{".travis.yml":"c5edd03cb5679918a6d85f64c0a634ed83022ff85ea78f440f39fd281bd29c02","Cargo.toml":"3dbce5caad1d0265badcfe385d578ac29d4e9b755f1909b1c2b67dc498d39d71","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"51831128477b9c9db0ec632ed6b6164f4e70e2d5f21eb5b3a391ecb9ab35e727","appveyor.yml":"6bf2f0c8f17d2dc4957dd39aba9a88ced3130200cf847a76d47b6c8fdcc2cbd8","benches/bench.rs":"2d3481c524841c532b9b9705073b223fd4b308c86ed7c9188b7fcd8e595ad459","benches/distributions/exponential.rs":"99cb59c013a0b6bb390d34c5649b341fc3b88ea7df0caf2470bdda8798f9fe3d","benches/distributions/gamma.rs":"3533f311e4b55d743c5b01a7eb6529c94fd97726ef6702a6372f914f5f33666b","benches/distributions/mod.rs":"0028f1cb96f61152ed5b49a4fe91227d809ef6d19035592c36032a538af7f95e","benches/distributions/normal.rs":"4e10c18cb583ccb96301ea953c8e0aa9ee3b6662060271d1b8d19ca23364dc6b","src/chacha.rs":"529c20ca1eff845da4cdca9ac995bcb8e698e48a61fbae91f09e3b4600ac57c3","src/distributions/exponential.rs":"103c8412c8a581b71835f1c00e40f6370e7702adf9d499243933a793d132d4e7","src/distributions/gamma.rs":"7a3f85c8daad4e56e334586ddb9fc9d83df3b0699738ed681a6c41e4ed455be9","src/distributions/mod.rs":"c3188ec234261ceba8b0231450f1bcfa486bdb7ad6a5aa9e1880aca4f4e02c74","src/distributions/normal.rs":"1562b43f80e4d5f83a8deb5af18de5a18dfeeeeda11fefc577da26672b14c949","src/distributions/range.rs":"c0ac6858d6a3979de7996feca22d190fde0bfb6f758d43030efa04a1a0fdcc17","src/distributions/ziggurat_tables.rs":"4eacf94fc352c91c455a6623de6a721e53842e1690f13a5662b6a79c7fbb73de","src/isaac.rs":"1725114b2d63c6fe4c0f4f7e0c36fc993a47f0322350d13abc631b0806bb71ed","src/lib.rs":"60ecdc3088993488df0a1914bd090fe00e4ea13272d1f3d51fd887e29e4cda3e","src/os.rs":"a27abd65bc29296e447961977c0ce5b44469d6231990783751a84dba36fe1044","src/rand_impls.rs":"cf411028341f67fd196ccde6200eea563c993f59d360a030b3d7d3ee15447a7d","src/read.rs":"bd0eb508a6b659dc578d546fc2f231484aed80c73cfe8c475e0d65c8d699a769","src/reseeding.rs":"73b2539b86b4cb8068e54716c7fd53e0d70b6c0de787a0749431b17019c9d826"},"package":"6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd"}
\ No newline at end of file
--- a/third_party/rust/rand/Cargo.toml
+++ b/third_party/rust/rand/Cargo.toml
@@ -7,17 +7,17 @@
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "rand"
-version = "0.3.17"
+version = "0.3.18"
authors = ["The Rust Project Developers"]
description = "Random number generators and other randomness functionality.\n"
homepage = "https://github.com/rust-lang-nursery/rand"
documentation = "https://docs.rs/rand"
readme = "README.md"
keywords = ["random", "rng"]
categories = ["algorithms"]
license = "MIT/Apache-2.0"
--- a/third_party/rust/rand/src/distributions/gamma.rs
+++ b/third_party/rust/rand/src/distributions/gamma.rs
@@ -180,18 +180,18 @@ impl IndependentSample<f64> for GammaLar
}
}
/// The chi-squared distribution `χ²(k)`, where `k` is the degrees of
/// freedom.
///
/// For `k > 0` integral, this distribution is the sum of the squares
/// of `k` independent standard normal random variables. For other
-/// `k`, this uses the equivalent characterisation `χ²(k) = Gamma(k/2,
-/// 2)`.
+/// `k`, this uses the equivalent characterisation
+/// `χ²(k) = Gamma(k/2, 2)`.
///
/// # Example
///
/// ```rust
/// use rand::distributions::{ChiSquared, IndependentSample};
///
/// let chi = ChiSquared::new(11.0);
/// let v = chi.ind_sample(&mut rand::thread_rng());
--- a/third_party/rust/rand/src/distributions/mod.rs
+++ b/third_party/rust/rand/src/distributions/mod.rs
@@ -118,16 +118,17 @@ pub struct WeightedChoice<'a, T:'a> {
items: &'a mut [Weighted<T>],
weight_range: Range<u32>
}
impl<'a, T: Clone> WeightedChoice<'a, T> {
/// Create a new `WeightedChoice`.
///
/// Panics if:
+ ///
/// - `v` is empty
/// - the total weight is 0
/// - the total weight is larger than a `u32` can contain.
pub fn new(items: &'a mut [Weighted<T>]) -> WeightedChoice<'a, T> {
// strictly speaking, this is subsumed by the total weight == 0 case
assert!(!items.is_empty(), "WeightedChoice::new called with no items");
let mut running_total: u32 = 0;
--- a/third_party/rust/rand/src/lib.rs
+++ b/third_party/rust/rand/src/lib.rs
@@ -249,16 +249,17 @@
use std::cell::RefCell;
use std::marker;
use std::mem;
use std::io;
use std::rc::Rc;
use std::num::Wrapping as w;
+use std::time;
pub use os::OsRng;
pub use isaac::{IsaacRng, Isaac64Rng};
pub use chacha::ChaChaRng;
#[cfg(target_pointer_width = "32")]
use IsaacRng as IsaacWordRng;
@@ -349,18 +350,19 @@ pub trait Rng {
/// choice of bits (masking v. shifting) is arbitrary and
/// should be immaterial for high quality generators. For low
/// quality generators (ex. LCG), prefer bitshifting due to
/// correlation between sequential low order bits.
///
/// See:
/// A PRNG specialized in double precision floating point numbers using
/// an affine transition
- /// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/dSFMT.pdf
- /// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-slide-e.pdf
+ ///
+ /// * <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/dSFMT.pdf>
+ /// * <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-slide-e.pdf>
///
/// By default this is implemented in terms of `next_u32`, but a
/// random number generator which can generate numbers satisfying
/// the requirements directly can overload this for performance.
/// It is required that the return value lies in `[0, 1)`.
///
/// See `Closed01` for the closed interval `[0,1]`, and
/// `Open01` for the open interval `(0,1)`.
@@ -885,73 +887,78 @@ impl<'a> SeedableRng<&'a [usize]> for St
/// Create a weak random number generator with a default algorithm and seed.
///
/// It returns the fastest `Rng` algorithm currently available in Rust without
/// consideration for cryptography or security. If you require a specifically
/// seeded `Rng` for consistency over time you should pick one algorithm and
/// create the `Rng` yourself.
///
-/// This will read randomness from the operating system to seed the
-/// generator.
+/// This will seed the generator with randomness from thread_rng.
pub fn weak_rng() -> XorShiftRng {
- match OsRng::new() {
- Ok(mut r) => r.gen(),
- Err(e) => panic!("weak_rng: failed to create seeded RNG: {:?}", e)
- }
+ thread_rng().gen()
}
/// Controls how the thread-local RNG is reseeded.
#[derive(Debug)]
struct ThreadRngReseeder;
impl reseeding::Reseeder<StdRng> for ThreadRngReseeder {
fn reseed(&mut self, rng: &mut StdRng) {
- *rng = match StdRng::new() {
- Ok(r) => r,
- Err(e) => panic!("could not reseed thread_rng: {}", e)
+ match StdRng::new() {
+ Ok(r) => *rng = r,
+ Err(_) => rng.reseed(&weak_seed())
}
}
}
const THREAD_RNG_RESEED_THRESHOLD: u64 = 32_768;
type ThreadRngInner = reseeding::ReseedingRng<StdRng, ThreadRngReseeder>;
/// The thread-local RNG.
#[derive(Clone, Debug)]
pub struct ThreadRng {
rng: Rc<RefCell<ThreadRngInner>>,
}
/// Retrieve the lazily-initialized thread-local random number
/// generator, seeded by the system. Intended to be used in method
/// chaining style, e.g. `thread_rng().gen::<i32>()`.
///
-/// The RNG provided will reseed itself from the operating system
-/// after generating a certain amount of randomness.
+/// After generating a certain amount of randomness, the RNG will reseed itself
+/// from the operating system or, if the operating system RNG returns an error,
+/// a seed based on the current system time.
///
/// The internal RNG used is platform and architecture dependent, even
/// if the operating system random number generator is rigged to give
/// the same sequence always. If absolute consistency is required,
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
pub fn thread_rng() -> ThreadRng {
// used to make space in TLS for a random number generator
thread_local!(static THREAD_RNG_KEY: Rc<RefCell<ThreadRngInner>> = {
let r = match StdRng::new() {
Ok(r) => r,
- Err(e) => panic!("could not initialize thread_rng: {}", e)
+ Err(_) => StdRng::from_seed(&weak_seed())
};
let rng = reseeding::ReseedingRng::new(r,
THREAD_RNG_RESEED_THRESHOLD,
ThreadRngReseeder);
Rc::new(RefCell::new(rng))
});
ThreadRng { rng: THREAD_RNG_KEY.with(|t| t.clone()) }
}
+fn weak_seed() -> [usize; 2] {
+ let now = time::SystemTime::now();
+ let unix_time = now.duration_since(time::UNIX_EPOCH).unwrap();
+ let seconds = unix_time.as_secs() as usize;
+ let nanoseconds = unix_time.subsec_nanos() as usize;
+ [seconds, nanoseconds]
+}
+
impl Rng for ThreadRng {
fn next_u32(&mut self) -> u32 {
self.rng.borrow_mut().next_u32()
}
fn next_u64(&mut self) -> u64 {
self.rng.borrow_mut().next_u64()
}
@@ -1036,17 +1043,18 @@ pub fn sample<T, I, R>(rng: &mut R, iter
}
}
}
reservoir
}
#[cfg(test)]
mod test {
- use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample};
+ use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample,
+ weak_rng};
use std::iter::repeat;
pub struct MyRng<R> { inner: R }
impl<R: Rng> Rng for MyRng<R> {
fn next_u32(&mut self) -> u32 {
fn next<T: Rng>(t: &mut T) -> u32 {
t.next_u32()
@@ -1280,9 +1288,18 @@ mod test {
let mut r: StdRng = SeedableRng::from_seed(&s[..]);
let string1 = r.gen_ascii_chars().take(100).collect::<String>();
r.reseed(&s);
let string2 = r.gen_ascii_chars().take(100).collect::<String>();
assert_eq!(string1, string2);
}
+
+ #[test]
+ fn test_weak_rng() {
+ let s = weak_rng().gen_iter::<usize>().take(256).collect::<Vec<usize>>();
+ let mut ra: StdRng = SeedableRng::from_seed(&s[..]);
+ let mut rb: StdRng = SeedableRng::from_seed(&s[..]);
+ assert!(iter_eq(ra.gen_ascii_chars().take(100),
+ rb.gen_ascii_chars().take(100)));
+ }
}
--- a/third_party/rust/rand/src/os.rs
+++ b/third_party/rust/rand/src/os.rs
@@ -25,18 +25,18 @@ use Rng;
/// `SystemFunction036`.
/// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed.
/// - PNaCl: calls into the `nacl-irt-random-0.1` IRT interface.
///
/// This usually does not block. On some systems (e.g. FreeBSD, OpenBSD,
/// Max OS X, and modern Linux) this may block very early in the init
/// process, if the CSPRNG has not been seeded yet.[1]
///
-/// [1] See https://www.python.org/dev/peps/pep-0524/ for a more in-depth
-/// discussion.
+/// [1] See <https://www.python.org/dev/peps/pep-0524/> for a more
+/// in-depth discussion.
pub struct OsRng(imp::OsRng);
impl OsRng {
/// Create a new `OsRng`.
pub fn new() -> io::Result<OsRng> {
imp::OsRng::new().map(OsRng)
}
}