Skip to content

Conversation

@baloo
Copy link
Contributor

@baloo baloo commented Nov 5, 2025

No description provided.

@baloo baloo marked this pull request as draft November 5, 2025 19:41
@baloo
Copy link
Contributor Author

baloo commented Nov 5, 2025

cc @tarcieri

@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch 2 times, most recently from d42c214 to 1accbdb Compare November 5, 2025 19:51
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (8b478bd) to head (54833c8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
+ Coverage   97.44%   97.46%   +0.01%     
==========================================
  Files          14       14              
  Lines        1722     1734      +12     
==========================================
+ Hits         1678     1690      +12     
  Misses         44       44              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cargo.toml Outdated
# need `crypto-bigint` with `alloc` to test `BoxedUint`
crypto-bigint = { version = "0.7.0-pre.5", default-features = false, features = ["alloc"] }
rand_chacha = "0.9"
rand_chacha = "0.10.0-rc.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps switch to chacha20 v0.10.0-rc.4 here? I think the plan is to deprecate rand_chacha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I can drop it altogether and use the one re-exported by rand?
https://docs.rs/rand/0.10.0-rc.1/rand/rngs/struct.ChaCha20Rng.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rand_chacha::Chacha20Rng was Clone-able, chacha20::Chacha20Rng is not anymore. I've made a PR in rand-core to add a fork method in SeedableRng here:
rust-random/rand_core#17

This now depends on it.

@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch from 1accbdb to badc078 Compare November 6, 2025 03:03
@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch from badc078 to 54ba25d Compare November 6, 2025 03:06
src/multicore.rs Outdated
loop {
if let Some(result) = self.sieve.next() {
return Some(result);
return Some((self.rng.fork(), result));
Copy link
Contributor Author

@baloo baloo Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SieveIterator now injects a new forked Rng for each item it streams. This is the only way I've found to pass the rng to each predicate.

I think the weight of the operation is fairly minimal, but ... worth pointing it out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on the RNG, but probably negligible compared to testing a large number for primality. And definitely more correct than cloning the RNG.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on the RNG,

To elaborate on that, cloning is probably cheaper than forking/splitting, but for RNGs that are counter based, splitting is cheap (essentially a clone and generate a nonce). That said, forking is the way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally you would rekey instead of generating a random nonce (ChaCha has 256-bit keys and 64-bit nonces for the variant we're using for RNGs, making collisions under random nonces too likely for comfort).

But the difference there is just extracting a bit more RNG output

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baloo can you just use *Rng::from_rng here for now with a TODO to use fork, so it isn't blocked on another rand_core release?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what the default implementation of fork() does in rust-random/rand_core#17

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baloo can you just use *Rng::from_rng here for now with a TODO to use fork, so it isn't blocked on another rand_core release?

done.

@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch 2 times, most recently from 8c948c7 to 18e8361 Compare November 6, 2025 03:39
@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch from 18e8361 to 7455a05 Compare November 6, 2025 03:45
@baloo baloo marked this pull request as ready for review November 6, 2025 05:04
@fjarri
Copy link
Collaborator

fjarri commented Nov 6, 2025

@tarcieri I assume crypto-bigint 0.7 will release with rand_core 0.10? Otherwise I'd rather stay on 0.9.

Don't worry about the build-docs and semver failures, I'll deal with it in another PR

Edit: actually, the doc-auto-cfg error comes from getrandom. Rust devs really screwed up a lot of builds here.

src/multicore.rs Outdated
loop {
if let Some(result) = self.sieve.next() {
return Some(result);
return Some((self.rng.fork(), result));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on the RNG,

To elaborate on that, cloning is probably cheaper than forking/splitting, but for RNGs that are counter based, splitting is cheap (essentially a clone and generate a nonce). That said, forking is the way to go.

@tarcieri
Copy link
Contributor

tarcieri commented Nov 6, 2025

@fjarri yes, we're in the process of bumping everything to use rand_core v0.10, and can hopefully actually start cutting releases once it's been updated.

I've already cut a crypto-bigint v0.7.0-rc.10 prerelease that includes the upgrade.

@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch from 9a7e805 to b05b17a Compare November 6, 2025 18:47
@baloo baloo force-pushed the baloo/rand_core/0.10.0-rc.2 branch from b05b17a to 9030605 Compare November 6, 2025 18:48
@tarcieri
Copy link
Contributor

tarcieri commented Nov 6, 2025

The other failures look unrelated. Would it be possible to get this landed and get another prerelease out? Unfortunately this rand_core upgrade is pretty painful and I'm trying to get to baseline crate releases with initial support for everything

}))
Ok(iter
.par_bridge()
.find_map_any(|(mut rng, c)| if predicate(&mut rng, &c) { Some(c) } else { None }))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wait, how does that work? Why don't we need to clone the RNG anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone on an RNG is not a really good idea as either forks of the clone will have a similar internal state and will yield the same bits.

Hence the idea to use SeedableRng::fork instead (which needs to take a &mut to mutate the internal state of the source RNG).

rand_chacha used to carry Clone: https://docs.rs/rand_chacha/latest/rand_chacha/struct.ChaCha20Core.html#impl-Clone-for-ChaCha20Core (rand_chacha is getting deprecated)
chacha20:rngs does not anymore: https://docs.rs/chacha20/0.10.0-rc.5/chacha20/struct.ChaCha20Rng.html

Here instead, the rng is injected by the iterator in each of the items (using fork).
It's a couple of lines down from this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fork comes in the next rc of rand_core, I will send a followup to migrate)

tarcieri and others added 2 commits November 6, 2025 14:50
`--html-in-header` apparently only works with the `--no-deps` option
when `cargo doc` is invoked, which `cargo semver-checks` isn't doing

This removes the rustdocflags overrides in `.cargo/config.toml` by
deleting the file first.
@tarcieri
Copy link
Contributor

tarcieri commented Nov 6, 2025

@baloo this hack should fix the semver checks, but right now the build is breaking because of rand_core: #97

@fjarri fjarri merged commit d0f86f4 into entropyxyz:master Nov 6, 2025
12 checks passed
@fjarri
Copy link
Collaborator

fjarri commented Nov 6, 2025

That's weird, I'm getting a lot of compilation errors locally after this. Going to publish a new release after I figure it out.

@fjarri
Copy link
Collaborator

fjarri commented Nov 7, 2025

crypto-bigint in the main deps was still set to rc.5, that was the reason. Fixed by setting it to rc.10 as well.

@tarcieri
Copy link
Contributor

tarcieri commented Nov 7, 2025

@fjarri thanks for the release! Got everything updated

@baloo baloo deleted the baloo/rand_core/0.10.0-rc.2 branch November 7, 2025 01:24
@baloo baloo restored the baloo/rand_core/0.10.0-rc.2 branch November 7, 2025 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants