-
Notifications
You must be signed in to change notification settings - Fork 431
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
Move XorShiftRng
to its own crate
#557
Conversation
Also recommend `StdRng` rather than the deprecated `IsaacRng`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, though CI has a few complaints.
src/prng/mod.rs
Outdated
|
||
pub use self::chacha::ChaChaRng; | ||
pub use self::hc128::Hc128Rng; | ||
pub use self::xorshift::XorShiftRng; | ||
pub use ::rand_xorshift::XorShiftRng; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this should use deprecated::XorShiftRng
. And then SmallRng
will need to change the import path to avoid deprecation warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the deprecation warning itself should suggest the new path
I should mention that I decided against adding a `random` or `xorshift`
keyword, because they are already in the description. This makes them
redundant for search, but they could still be useful for listing crates by
keyword.
It is inconsistent with the keywords for `rand_isaac`.
…On Mon, Jul 16, 2018, 17:03 Diggory Hardy ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/prng/mod.rs
<#557 (comment)>
:
>
pub use self::chacha::ChaChaRng;
pub use self::hc128::Hc128Rng;
-pub use self::xorshift::XorShiftRng;
+pub use ::rand_xorshift::XorShiftRng;
Also the deprecation warning itself should suggest the new path
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#557 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACCtNavrSfVO68RZ3mCcHKR2WOGXPnpks5uHKs4gaJpZM4VROGc>
.
|
I didn't pay much attention to keywords... but is there a problem with having too many? |
There is an upper limit of 5, but we are using less than that. Anyway, I made the |
WASM fails as expected, but I can't see other failures. |
There are some broken documentation links; check the bottom: https://travis-ci.org/rust-lang-nursery/rand/jobs/405253376 This is a different issue (can you investigate?): https://travis-ci.org/rust-lang-nursery/rand/jobs/405253378 Also there was a warning about unused Be nice if you can investigate; I have very little time this week. |
|
The WASM failure happens on master as well, so I think it is orthogonal to this PR. |
Yes, sorry, the WASM failure is a known issue at the moment: koute/cargo-web#116 I guess then we should just ignore the warning for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍. Left two small comments.
What should the version number of these crates be? It is pretty much stable, but the depends on rand_core
< 1.0.
rand_xorshift/Cargo.toml
Outdated
appveyor = { repository = "alexcrichton/rand" } | ||
|
||
[features] | ||
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this only needs serde_derive
? And the comment is old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Actually, it seems like newer versions of serde don't need serde_derive
anymore. I'll remove the comments though.
rand_xorshift/src/lib.rs
Outdated
|
||
mod xorshift; | ||
|
||
pub use self::xorshift::XorShiftRng; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason xorshift.rs
can't be moved in with lib.rs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be. I'm just mirroring what was done before. Why would you prefer this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter much, but I've seen more tiny crates like this have everything in just a single file.
Cargo.toml
Outdated
|
||
[dependencies] | ||
rand_core = { path = "rand_core", version = "0.2", default-features = false } | ||
# only for deprecations and benches: | ||
rand_isaac = { path = "rand_isaac", version = "0.1", default-features = false } | ||
rand_xorshift = { path = "rand_xorshift", version = "0.1", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have default features (neither does rand_isaac
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it.
I realized the serde tests were broken in |
rand_isaac/Cargo.toml
Outdated
@@ -18,9 +18,15 @@ travis-ci = { repository = "rust-lang-nursery/rand" } | |||
appveyor = { repository = "alexcrichton/rand" } | |||
|
|||
[features] | |||
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper | |||
serde1 = ["serde", "serde_derive", "rand_core/serde1"] | |||
std = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow why you added an extra std
feature... Or does testing serialization need std?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. The test uses BufWriter
, BufReader
and bincode
, all requiring std
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about only enabling std
when testing, or even only when testing in combination with serde? Than we don't need the otherwise useless feature flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit fragile. What if you want to test Serde without std
? Anyway, this is not possible AFAIK.
src/lib.rs
Outdated
@@ -237,7 +237,7 @@ | |||
#[cfg(feature="std")] extern crate std as core; | |||
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc; | |||
|
|||
#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode; | |||
#[cfg(all(feature="serde1", test))] extern crate bincode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment does not really belong to this PR, but does rand still need bincode as dependency, or do all tests now live in external crates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after this PR rand does not depend directly on serde or bincode anymore. I removed them.
We might want to implement Serde support for StdRng
and SmallRng
. The serialization stability guarantees could be the same as for value stability.
Does the CI run tests for |
Yes, but only on nightly due to the I'll push a commit that enable more tests on more targets. |
Before, there Serde tests where not running.
Thanks to having a I would expect serialization to give stronger reproducibility guarantees than that. That was the reason we didn't implement serialization for those, and it still seems like the right choice to me. |
Why? I would expect that breaking reproducibility also breaks serialization. And why would you want serialization without reproducibility? Anyway, I agree the conservative choice is to only implement serialization for named RNGs for now. I think this PR is ready now? |
We are saying the same thing 😄.
Testing serialization without std does not seem worthwile for us (it is a minor feature). Removing the std feature is possible, would you cherry-pick my commit? https://github.com/pitdicker/rand/commits/xorshift-crate |
Starting fresh with 0.1 makes sense to me. As you point out, it's not reasonable to use 1.0 until after all dependencies are stable, and IMO this should only happen after the library has existed for some time with no significant changes. |
Your branch does not work, the serde tests are never executed. Applying the following patche fixes this: diff --git a/rand_isaac/src/isaac.rs b/rand_isaac/src/isaac.rs
index 6a8121b..a1bd378 100644
--- a/rand_isaac/src/isaac.rs
+++ b/rand_isaac/src/isaac.rs
@@ -453,7 +453,7 @@ mod test {
}
#[test]
- #[cfg(all(feature="serde1", feature="std"))]
+ #[cfg(all(feature="serde1"))]
fn test_isaac_serde() {
use bincode;
use std::io::{BufWriter, BufReader};
diff --git a/rand_isaac/src/isaac64.rs b/rand_isaac/src/isaac64.rs
index b77f3bb..30c494a 100644
--- a/rand_isaac/src/isaac64.rs
+++ b/rand_isaac/src/isaac64.rs
@@ -445,7 +445,7 @@ mod test {
}
#[test]
- #[cfg(all(feature="serde1", feature="std"))]
+ #[cfg(all(feature="serde1"))]
fn test_isaac64_serde() {
use bincode;
use std::io::{BufWriter, BufReader};
diff --git a/rand_xorshift/src/xorshift.rs b/rand_xorshift/src/xorshift.rs
index 8a93e9a..cf12296 100644
--- a/rand_xorshift/src/xorshift.rs
+++ b/rand_xorshift/src/xorshift.rs
@@ -178,7 +178,7 @@ mod tests {
}
}
- #[cfg(all(feature="serde1", feature="std"))]
+ #[cfg(all(feature="serde1"))]
#[test]
fn test_xorshift_serde() {
use bincode; However, this makes Note that you can push to my branch due to your collaborator privileges. |
Thank you! @dhardy You already gave your approval, but there have been changes. Shall I merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed again. With some doc tweaks I'm happy to have this merged, though it would be nice to fix the tests first.
@pitdicker does the Travis changes clash with #563?
benches/distributions.rs
Outdated
@@ -4,14 +4,15 @@ | |||
|
|||
extern crate test; | |||
extern crate rand; | |||
extern crate rand_xorshift; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just use SmallRng
in this benchmark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -18,9 +18,14 @@ travis-ci = { repository = "rust-lang-nursery/rand" } | |||
appveyor = { repository = "alexcrichton/rand" } | |||
|
|||
[features] | |||
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper | |||
serde1 = ["serde", "serde_derive", "rand_core/serde1"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feature serde1
implicitly implies std
— should probably be documented with a comment here and in the README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feature serde1 implicitly implies std
What do you mean? We don't require std
for the serde1
feature, and Serde works without std
. We only need std
for the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry. I mis-understood the double-negative conditional no_std
attribute.
@@ -18,14 +18,17 @@ | |||
#![deny(missing_debug_implementations)] | |||
#![doc(test(attr(allow(unused_variables), deny(warnings))))] | |||
|
|||
#![no_std] | |||
#![cfg_attr(not(all(feature="serde1", test)), no_std)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, but is surprising
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only alternative I can see would be making our tests work with no_std
.
appveyor = { repository = "alexcrichton/rand" } | ||
|
||
[features] | ||
serde1 = ["serde", "serde_derive"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for rand_isaac
Hence "nice", not "required". I didn't really want to look all through those AppVeyor logs. |
AFAIK, #565 fixes it but is blocked on |
Also recommend
StdRng
rather than the deprecatedIsaacRng
.The main motivation for this is that we can remove the generator from Rand and that it is still possible to reproduce the results.