Amanieu / intrusive-rs

Intrusive collections for Rust
Apache License 2.0
412 stars 48 forks source link

Migrate from deprecated `XorShiftRng::seed_from_u64` #56

Closed victorhsieh closed 3 years ago

victorhsieh commented 3 years ago

The crate currently depends on rand_xorshift 0.2.0. But it seems like XorShiftRng::seed_from_u64 has been removed in 0.3.0. Here is what the build error looks like when I try to uprev rand_xorshift:

   Compiling intrusive-collections v0.9.1 (/ssd/aosp/external/rust/crates/intrusive-collections)
error[E0599]: no function or associated item named `seed_from_u64` found for struct `rand_xorshift::XorShiftRng` in the current scope
    --> src/rbtree.rs:2216:36
     |
2216 |         let mut rng = XorShiftRng::seed_from_u64(0);
     |                                    ^^^^^^^^^^^^^ function or associated item not found in `rand_xorshift::XorShiftRng`
     |
     = help: items from traits can only be used if the trait is in scope
     = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
             `use rand_core::SeedableRng;`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `intrusive-collections`.

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

It'd be great to migrate away from the deprecated API.

Amanieu commented 3 years ago

This is only used in tests, so it should be pretty trivial to upgrade. Do you want to make a pull request for this?

victorhsieh commented 3 years ago

The right solution isn't clear to me. There doesn't seem to be a seeding API exposed from XorShiftRng anymore. So I'd have to use rand_core::SeedableRng. But that also breaks both indices.shuffle(&mut rng); and rng.gen_range since those API has changed.

I'm not familiar with rand*. Is rand_xorshift necessary? Or maybe the way to use it has changed?

Amanieu commented 3 years ago

The only thing we care about is that the seed is the same every time the tests are run, to avoid non-determinism. We don't particularly care what RNG is used, as long as it can be seeded to give the same numbers on every run.

victorhsieh commented 3 years ago

Sorry for the slow response. Finally had a chance to look at this again, and figured out the actual problem.