Skip to content

Commit da5e2d7

Browse files
authored
Merge pull request #4170 from eduardosm/update-rand
Update rand and getrandom dependencies
2 parents b82463f + eab3528 commit da5e2d7

File tree

16 files changed

+134
-36
lines changed

16 files changed

+134
-36
lines changed

src/tools/miri/Cargo.lock

+79-13
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,19 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
351351
dependencies = [
352352
"cfg-if",
353353
"libc",
354-
"wasi",
354+
"wasi 0.11.0+wasi-snapshot-preview1",
355+
]
356+
357+
[[package]]
358+
name = "getrandom"
359+
version = "0.3.1"
360+
source = "registry+https://github.com/rust-lang/crates.io-index"
361+
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
362+
dependencies = [
363+
"cfg-if",
364+
"libc",
365+
"wasi 0.13.3+wasi-0.2.2",
366+
"windows-targets 0.52.6",
355367
]
356368

357369
[[package]]
@@ -529,12 +541,12 @@ dependencies = [
529541
"chrono-tz",
530542
"colored",
531543
"directories",
532-
"getrandom",
544+
"getrandom 0.3.1",
533545
"libc",
534546
"libffi",
535547
"libloading",
536548
"measureme",
537-
"rand",
549+
"rand 0.9.0",
538550
"regex",
539551
"rustc_version",
540552
"smallvec",
@@ -662,7 +674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
662674
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
663675
dependencies = [
664676
"phf_shared",
665-
"rand",
677+
"rand 0.8.5",
666678
]
667679

668680
[[package]]
@@ -692,7 +704,7 @@ version = "0.2.20"
692704
source = "registry+https://github.com/rust-lang/crates.io-index"
693705
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
694706
dependencies = [
695-
"zerocopy",
707+
"zerocopy 0.7.35",
696708
]
697709

698710
[[package]]
@@ -729,28 +741,44 @@ version = "0.8.5"
729741
source = "registry+https://github.com/rust-lang/crates.io-index"
730742
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
731743
dependencies = [
732-
"libc",
744+
"rand_core 0.6.4",
745+
]
746+
747+
[[package]]
748+
name = "rand"
749+
version = "0.9.0"
750+
source = "registry+https://github.com/rust-lang/crates.io-index"
751+
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
752+
dependencies = [
733753
"rand_chacha",
734-
"rand_core",
754+
"rand_core 0.9.0",
755+
"zerocopy 0.8.14",
735756
]
736757

737758
[[package]]
738759
name = "rand_chacha"
739-
version = "0.3.1"
760+
version = "0.9.0"
740761
source = "registry+https://github.com/rust-lang/crates.io-index"
741-
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
762+
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
742763
dependencies = [
743764
"ppv-lite86",
744-
"rand_core",
765+
"rand_core 0.9.0",
745766
]
746767

747768
[[package]]
748769
name = "rand_core"
749770
version = "0.6.4"
750771
source = "registry+https://github.com/rust-lang/crates.io-index"
751772
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
773+
774+
[[package]]
775+
name = "rand_core"
776+
version = "0.9.0"
777+
source = "registry+https://github.com/rust-lang/crates.io-index"
778+
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
752779
dependencies = [
753-
"getrandom",
780+
"getrandom 0.3.1",
781+
"zerocopy 0.8.14",
754782
]
755783

756784
[[package]]
@@ -768,7 +796,7 @@ version = "0.4.5"
768796
source = "registry+https://github.com/rust-lang/crates.io-index"
769797
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
770798
dependencies = [
771-
"getrandom",
799+
"getrandom 0.2.15",
772800
"libredox",
773801
"thiserror",
774802
]
@@ -1105,6 +1133,15 @@ version = "0.11.0+wasi-snapshot-preview1"
11051133
source = "registry+https://github.com/rust-lang/crates.io-index"
11061134
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
11071135

1136+
[[package]]
1137+
name = "wasi"
1138+
version = "0.13.3+wasi-0.2.2"
1139+
source = "registry+https://github.com/rust-lang/crates.io-index"
1140+
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
1141+
dependencies = [
1142+
"wit-bindgen-rt",
1143+
]
1144+
11081145
[[package]]
11091146
name = "windows-sys"
11101147
version = "0.48.0"
@@ -1244,14 +1281,32 @@ version = "0.52.6"
12441281
source = "registry+https://github.com/rust-lang/crates.io-index"
12451282
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
12461283

1284+
[[package]]
1285+
name = "wit-bindgen-rt"
1286+
version = "0.33.0"
1287+
source = "registry+https://github.com/rust-lang/crates.io-index"
1288+
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
1289+
dependencies = [
1290+
"bitflags",
1291+
]
1292+
12471293
[[package]]
12481294
name = "zerocopy"
12491295
version = "0.7.35"
12501296
source = "registry+https://github.com/rust-lang/crates.io-index"
12511297
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
12521298
dependencies = [
12531299
"byteorder",
1254-
"zerocopy-derive",
1300+
"zerocopy-derive 0.7.35",
1301+
]
1302+
1303+
[[package]]
1304+
name = "zerocopy"
1305+
version = "0.8.14"
1306+
source = "registry+https://github.com/rust-lang/crates.io-index"
1307+
checksum = "a367f292d93d4eab890745e75a778da40909cab4d6ff8173693812f79c4a2468"
1308+
dependencies = [
1309+
"zerocopy-derive 0.8.14",
12551310
]
12561311

12571312
[[package]]
@@ -1264,3 +1319,14 @@ dependencies = [
12641319
"quote",
12651320
"syn",
12661321
]
1322+
1323+
[[package]]
1324+
name = "zerocopy-derive"
1325+
version = "0.8.14"
1326+
source = "registry+https://github.com/rust-lang/crates.io-index"
1327+
checksum = "d3931cb58c62c13adec22e38686b559c86a30565e16ad6e8510a337cedc611e1"
1328+
dependencies = [
1329+
"proc-macro2",
1330+
"quote",
1331+
"syn",
1332+
]

src/tools/miri/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test = false # we have no unit tests
1818
doctest = false # and no doc tests
1919

2020
[dependencies]
21-
getrandom = { version = "0.2", features = ["std"] }
22-
rand = "0.8"
21+
getrandom = { version = "0.3", features = ["std"] }
22+
rand = "0.9"
2323
smallvec = { version = "1.7", features = ["drain_filter"] }
2424
aes = { version = "0.8.3", features = ["hazmat"] }
2525
measureme = "11"

src/tools/miri/src/alloc_addresses/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
217217
// We have to pick a fresh address.
218218
// Leave some space to the previous allocation, to give it some chance to be less aligned.
219219
// We ensure that `(global_state.next_base_addr + slack) % 16` is uniformly distributed.
220-
let slack = rng.gen_range(0..16);
220+
let slack = rng.random_range(0..16);
221221
// From next_base_addr + slack, round up to adjust for alignment.
222222
let base_addr = global_state
223223
.next_base_addr

src/tools/miri/src/alloc_addresses/reuse_pool.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl ReusePool {
5858
// We don't remember stack addresses: there's a lot of them (so the perf impact is big),
5959
// and we only want to reuse stack slots within the same thread or else we'll add a lot of
6060
// undesired synchronization.
61-
if kind == MemoryKind::Stack || !rng.gen_bool(self.address_reuse_rate) {
61+
if kind == MemoryKind::Stack || !rng.random_bool(self.address_reuse_rate) {
6262
return;
6363
}
6464
let clock = clock();
@@ -88,10 +88,10 @@ impl ReusePool {
8888
thread: ThreadId,
8989
) -> Option<(u64, Option<VClock>)> {
9090
// Determine whether we'll even attempt a reuse. As above, we don't do reuse for stack addresses.
91-
if kind == MemoryKind::Stack || !rng.gen_bool(self.address_reuse_rate) {
91+
if kind == MemoryKind::Stack || !rng.random_bool(self.address_reuse_rate) {
9292
return None;
9393
}
94-
let cross_thread_reuse = rng.gen_bool(self.address_reuse_cross_thread_rate);
94+
let cross_thread_reuse = rng.random_bool(self.address_reuse_cross_thread_rate);
9595
// Determine the pool to take this from.
9696
let subpool = self.subpool(align);
9797
// Let's see if we can find something of the right size. We want to find the full range of
@@ -118,7 +118,7 @@ impl ReusePool {
118118
return None;
119119
}
120120
// Pick a random element with the desired size.
121-
let idx = rng.gen_range(begin..end);
121+
let idx = rng.random_range(begin..end);
122122
// Remove it from the pool and return.
123123
let (chosen_addr, chosen_size, chosen_thread, clock) = subpool.remove(idx);
124124
debug_assert!(chosen_size >= size && chosen_addr % align.bytes() == 0);

src/tools/miri/src/concurrency/data_race.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> {
830830
let success_rate = 1.0 - this.machine.cmpxchg_weak_failure_rate;
831831
let cmpxchg_success = eq.to_scalar().to_bool()?
832832
&& if can_fail_spuriously {
833-
this.machine.rng.get_mut().gen_bool(success_rate)
833+
this.machine.rng.get_mut().random_bool(success_rate)
834834
} else {
835835
true
836836
};

src/tools/miri/src/concurrency/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11381138
use rand::Rng as _;
11391139

11401140
let this = self.eval_context_mut();
1141-
if this.machine.rng.get_mut().gen_bool(this.machine.preemption_rate) {
1141+
if this.machine.rng.get_mut().random_bool(this.machine.preemption_rate) {
11421142
this.yield_active_thread();
11431143
}
11441144
}

src/tools/miri/src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
421421

422422
if this.machine.communicate() {
423423
// Fill the buffer using the host's rng.
424-
getrandom::getrandom(&mut data)
424+
getrandom::fill(&mut data)
425425
.map_err(|err| err_unsup_format!("host getrandom failed: {}", err))?;
426426
} else {
427427
let rng = this.machine.rng.get_mut();

src/tools/miri/src/intrinsics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
141141
// FIXME: should we check for validity here? It's tricky because we do not have a
142142
// place. Codegen does not seem to set any attributes like `noundef` for intrinsic
143143
// calls, so we don't *have* to do anything.
144-
let branch: bool = this.machine.rng.get_mut().gen();
144+
let branch: bool = this.machine.rng.get_mut().random();
145145
this.write_scalar(Scalar::from_bool(branch), dest)?;
146146
}
147147

@@ -289,7 +289,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
289289
let a = this.read_scalar(a)?.to_f32()?;
290290
let b = this.read_scalar(b)?.to_f32()?;
291291
let c = this.read_scalar(c)?.to_f32()?;
292-
let fuse: bool = this.machine.rng.get_mut().gen();
292+
let fuse: bool = this.machine.rng.get_mut().random();
293293
let res = if fuse {
294294
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
295295
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
@@ -304,7 +304,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
304304
let a = this.read_scalar(a)?.to_f64()?;
305305
let b = this.read_scalar(b)?.to_f64()?;
306306
let c = this.read_scalar(c)?.to_f64()?;
307-
let fuse: bool = this.machine.rng.get_mut().gen();
307+
let fuse: bool = this.machine.rng.get_mut().random();
308308
let res = if fuse {
309309
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
310310
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()

src/tools/miri/src/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
304304
let c = this.read_scalar(&this.project_index(&c, i)?)?;
305305
let dest = this.project_index(&dest, i)?;
306306

307-
let fuse: bool = intrinsic_name == "fma" || this.machine.rng.get_mut().gen();
307+
let fuse: bool = intrinsic_name == "fma" || this.machine.rng.get_mut().random();
308308

309309
// Works for f32 and f64.
310310
// FIXME: using host floats to work around https://github.com/rust-lang/miri/issues/2468.

src/tools/miri/src/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14991499
catch_unwind: None,
15001500
timing,
15011501
is_user_relevant: ecx.machine.is_user_relevant(&frame),
1502-
salt: ecx.machine.rng.borrow_mut().gen::<usize>() % ADDRS_PER_ANON_GLOBAL,
1502+
salt: ecx.machine.rng.borrow_mut().random_range(0..ADDRS_PER_ANON_GLOBAL),
15031503
data_race: ecx.machine.data_race.as_ref().map(|_| data_race::FrameState::default()),
15041504
};
15051505

@@ -1714,7 +1714,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
17141714
if unique {
17151715
CTFE_ALLOC_SALT
17161716
} else {
1717-
ecx.machine.rng.borrow_mut().gen::<usize>() % ADDRS_PER_ANON_GLOBAL
1717+
ecx.machine.rng.borrow_mut().random_range(0..ADDRS_PER_ANON_GLOBAL)
17181718
}
17191719
}
17201720

src/tools/miri/src/math.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rand::Rng as _;
2-
use rand::distributions::Distribution as _;
32
use rustc_apfloat::Float as _;
43
use rustc_apfloat::ieee::IeeeFloat;
54

@@ -18,13 +17,12 @@ pub(crate) fn apply_random_float_error<F: rustc_apfloat::Float>(
1817
// (When read as binary, the position of the first `1` determines the exponent,
1918
// and the remaining bits fill the mantissa. `PREC` is one plus the size of the mantissa,
2019
// so this all works out.)
21-
let dist = rand::distributions::Uniform::new(0, 1 << F::PRECISION);
22-
let r = F::from_u128(dist.sample(rng)).value;
20+
let r = F::from_u128(rng.random_range(0..(1 << F::PRECISION))).value;
2321
// Multiply this with 2^(scale - PREC). The result is between 0 and
2422
// 2^PREC * 2^(scale - PREC) = 2^scale.
2523
let err = r.scalbn(err_scale.strict_sub(F::PRECISION.try_into().unwrap()));
2624
// give it a random sign
27-
let err = if rng.gen::<bool>() { -err } else { err };
25+
let err = if rng.random() { -err } else { err };
2826
// multiple the value with (1+err)
2927
(val * (F::from_u128(1).value + err).value).value
3028
}

src/tools/miri/src/operator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
108108
// Pick one of the NaNs.
109109
let nan = nans.choose(&mut *rand).unwrap();
110110
// Non-deterministically flip the sign.
111-
if rand.gen() {
111+
if rand.random() {
112112
// This will properly flip even for NaN.
113113
-nan
114114
} else {

src/tools/miri/src/shims/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
15501550
}
15511551
}
15521552
fn mkstemp(&mut self, template_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
1553-
use rand::seq::SliceRandom;
1553+
use rand::seq::IndexedRandom;
15541554

15551555
// POSIX defines the template string.
15561556
const TEMPFILE_TEMPLATE_STR: &str = "XXXXXX";

0 commit comments

Comments
 (0)