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

rand is unusable due to crate incompatibilities #531

Closed
orlp opened this issue Aug 30, 2019 · 8 comments
Closed

rand is unusable due to crate incompatibilities #531

orlp opened this issue Aug 30, 2019 · 8 comments
Labels
upstream Caused by a third-party component

Comments

@orlp
Copy link

orlp commented Aug 30, 2019

The current rand crates included in the playground are:

rand = "=0.7.0"
rand_chacha = "=0.2.1"
rand_core = "=0.5.0"
rand_hc = "=0.2.0"
rand_isaac = "=0.1.1"
rand_jitter = "=0.1.4"
rand_os = "=0.1.3"
rand_pcg = "=0.1.2"
rand_xorshift = "=0.1.1"

I haven't checked all of them, but this makes the Pcg and XorShift RNGs unusable because they are outdated, and they are using an older version of rand_core. E.g.:

use rand_core::SeedableRng;
use rand_pcg::Pcg32;
fn main() {
    let _r = Pcg32::seed_from_u64(42);
}

This complains:

error[E0599]: no function or associated item named `seed_from_u64` found for type `rand_pcg::pcg64::Lcg64Xsh32` in the current scope
 --> src/main.rs:4:21
  |
4 |     let _r = Pcg32::seed_from_u64(42);
  |                     ^^^^^^^^^^^^^ function or associated item not found in `rand_pcg::pcg64::Lcg64Xsh32`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
  |
1 | use rand_core::SeedableRng;
  |

warning: unused import: `rand_core::SeedableRng`
 --> src/main.rs:1:5
  |
1 | use rand_core::SeedableRng;
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Due to incompatible crate versions.

@shepmaster
Copy link
Member

You are correct, but I don't know much what to do here.

  1. We get the top downloaded crates and things from the cookbook
  2. We get the newest versions from crates.io
  3. We ask Cargo to resolve the dependencies
  4. We take the latest version of each resolved crate

rand_{pcg,xorshift} is not one of the top-crates or a cookbook item, so it only shows up because it's a dependency. rand 0.7 does not depend on rand_{pcg,xorshift}, only rand 0.6.5 does:

[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

Thus the version of rand_{pcg,xorshift} that is included is the one that's compatible with the crate that needs it.

@shepmaster

This comment has been minimized.

@shepmaster

This comment has been minimized.

@orlp
Copy link
Author

orlp commented Aug 30, 2019

I don't think that'd be the right solution. Reading the code, hand-curating of certain crates already happens with crate-modifications.toml. Considering that rand is a cookbook crate as well, I think the best solution would be the hardcode some exception to also get the latest versions of the accompanying crates.

@shepmaster
Copy link
Member

OK, in that case you will need to either

  1. file an issue with the cookbook. We simply include their list of crates, so you will need to add the various rand_* crates to the cookbook and then we can include them here.

  2. file an issue with rand. They can specify metadata for extra features that they think should be enabled on the playground

The playground tries really hard to make no decisions about what crates to include. I simply don't want to get into the game of "why didn't you select my crate".

@orlp
Copy link
Author

orlp commented Aug 30, 2019

@shepmaster Could this be resolved by cargo features on rand? I don't see how.

@shepmaster
Copy link
Member

cargo features on rand? I don't see how.

It already optionally depends on rand_pcg, so follow that pattern and add all of the other generators as optional dependencies, then create a feature that enables them and enable that feature for the playground.

@shepmaster
Copy link
Member

The playground now supports importing all the crates we've compiled (#540) so this modified version works:

use rand_core_0_4_2::SeedableRng;
use rand_pcg::Pcg32;

fn main() {
    let _r = Pcg32::seed_from_u64(42);
}

Everything else appears to require upstream work, so I'm going to close this for now. Thanks!

@shepmaster shepmaster added the upstream Caused by a third-party component label Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Caused by a third-party component
Projects
None yet
Development

No branches or pull requests

2 participants