From 1c7aaf95e1bb77c99437fa260f84124ac30808f0 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 1 Feb 2025 19:35:47 +0000 Subject: [PATCH 1/3] Update rand to 0.9.0 --- Cargo.lock | 14 +++++++------- compiler/rustc_abi/Cargo.toml | 8 ++++---- compiler/rustc_incremental/Cargo.toml | 2 +- compiler/rustc_incremental/src/persist/fs.rs | 4 ++-- src/etc/test-float-parse/Cargo.toml | 4 ++-- src/etc/test-float-parse/src/gen/fuzz.rs | 8 ++++---- src/etc/test-float-parse/src/gen/many_digits.rs | 14 +++++++------- src/etc/test-float-parse/src/lib.rs | 4 ++-- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecd26d6199c90..ea93fbd01f069 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2881,11 +2881,11 @@ dependencies = [ [[package]] name = "rand_xoshiro" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +checksum = "f703f4665700daf5512dcca5f43afa6af89f09db47fb56be587f80636bda2d41" dependencies = [ - "rand_core 0.6.4", + "rand_core 0.9.0", ] [[package]] @@ -3155,7 +3155,7 @@ name = "rustc_abi" version = "0.0.0" dependencies = [ "bitflags", - "rand 0.8.5", + "rand 0.9.0", "rand_xoshiro", "rustc_data_structures", "rustc_hashes", @@ -3789,7 +3789,7 @@ dependencies = [ name = "rustc_incremental" version = "0.0.0" dependencies = [ - "rand 0.8.5", + "rand 0.9.0", "rustc_ast", "rustc_data_structures", "rustc_errors", @@ -5176,8 +5176,8 @@ version = "0.1.0" dependencies = [ "indicatif", "num", - "rand 0.8.5", - "rand_chacha 0.3.1", + "rand 0.9.0", + "rand_chacha 0.9.0", "rayon", ] diff --git a/compiler/rustc_abi/Cargo.toml b/compiler/rustc_abi/Cargo.toml index 4713b3474bdb5..9cb6619adc95b 100644 --- a/compiler/rustc_abi/Cargo.toml +++ b/compiler/rustc_abi/Cargo.toml @@ -6,13 +6,13 @@ edition = "2024" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -rand = { version = "0.8.4", default-features = false, optional = true } -rand_xoshiro = { version = "0.6.0", optional = true } -rustc_data_structures = { path = "../rustc_data_structures", optional = true } +rand = { version = "0.9.0", default-features = false, optional = true } +rand_xoshiro = { version = "0.7.0", optional = true } +rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_hashes = { path = "../rustc_hashes" } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } -rustc_serialize = { path = "../rustc_serialize", optional = true } +rustc_serialize = { path = "../rustc_serialize", optional = true } rustc_span = { path = "../rustc_span", optional = true } tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_incremental/Cargo.toml b/compiler/rustc_incremental/Cargo.toml index 754881309bf5f..4e5061f4f69e7 100644 --- a/compiler/rustc_incremental/Cargo.toml +++ b/compiler/rustc_incremental/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -rand = "0.8.4" +rand = "0.9.0" rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index 19cca48af6127..76a1ff3cf3828 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -108,7 +108,7 @@ use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use rand::{RngCore, thread_rng}; +use rand::{RngCore, rng}; use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN}; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::svh::Svh; @@ -445,7 +445,7 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result PathBuf { let timestamp = timestamp_to_string(SystemTime::now()); debug!("generate_session_dir_path: timestamp = {}", timestamp); - let random_number = thread_rng().next_u32(); + let random_number = rng().next_u32(); debug!("generate_session_dir_path: random_number = {}", random_number); // Chop the first 3 characters off the timestamp. Those 3 bytes will be zero for a while. diff --git a/src/etc/test-float-parse/Cargo.toml b/src/etc/test-float-parse/Cargo.toml index 56cb5cddeea52..bacb9e09f3f6a 100644 --- a/src/etc/test-float-parse/Cargo.toml +++ b/src/etc/test-float-parse/Cargo.toml @@ -7,8 +7,8 @@ publish = false [dependencies] indicatif = { version = "0.17.8", default-features = false } num = "0.4.3" -rand = "0.8.5" -rand_chacha = "0.3" +rand = "0.9.0" +rand_chacha = "0.9.0" rayon = "1" [lib] diff --git a/src/etc/test-float-parse/src/gen/fuzz.rs b/src/etc/test-float-parse/src/gen/fuzz.rs index 7fc999d167113..1d6c5562a14c8 100644 --- a/src/etc/test-float-parse/src/gen/fuzz.rs +++ b/src/etc/test-float-parse/src/gen/fuzz.rs @@ -6,7 +6,7 @@ use std::ops::Range; use std::sync::Mutex; use rand::Rng; -use rand::distributions::{Distribution, Standard}; +use rand::distr::{Distribution, StandardUniform}; use rand_chacha::ChaCha8Rng; use rand_chacha::rand_core::SeedableRng; @@ -47,7 +47,7 @@ impl Fuzz { impl Generator for Fuzz where - Standard: Distribution<::Int>, + StandardUniform: Distribution<::Int>, { const SHORT_NAME: &'static str = "fuzz"; @@ -74,13 +74,13 @@ where impl Iterator for Fuzz where - Standard: Distribution<::Int>, + StandardUniform: Distribution<::Int>, { type Item = >::WriteCtx; fn next(&mut self) -> Option { let _ = self.iter.next()?; - let i: F::Int = self.rng.gen(); + let i: F::Int = self.rng.random(); Some(F::from_bits(i)) } diff --git a/src/etc/test-float-parse/src/gen/many_digits.rs b/src/etc/test-float-parse/src/gen/many_digits.rs index aab8d5d704bec..741e11437fe29 100644 --- a/src/etc/test-float-parse/src/gen/many_digits.rs +++ b/src/etc/test-float-parse/src/gen/many_digits.rs @@ -3,7 +3,7 @@ use std::fmt::Write; use std::marker::PhantomData; use std::ops::{Range, RangeInclusive}; -use rand::distributions::{Distribution, Uniform}; +use rand::distr::{Distribution, Uniform}; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; @@ -40,7 +40,7 @@ impl Generator for RandDigits { fn new() -> Self { let rng = ChaCha8Rng::from_seed(SEED); - let range = Uniform::from(0..10); + let range = Uniform::try_from(0..10).unwrap(); Self { rng, iter: 0..ITERATIONS, uniform: range, marker: PhantomData } } @@ -55,11 +55,11 @@ impl Iterator for RandDigits { fn next(&mut self) -> Option { let _ = self.iter.next()?; - let num_digits = self.rng.gen_range(POSSIBLE_NUM_DIGITS); - let has_decimal = self.rng.gen_bool(0.2); - let has_exp = self.rng.gen_bool(0.2); + let num_digits = self.rng.random_range(POSSIBLE_NUM_DIGITS); + let has_decimal = self.rng.random_bool(0.2); + let has_exp = self.rng.random_bool(0.2); - let dec_pos = if has_decimal { Some(self.rng.gen_range(0..num_digits)) } else { None }; + let dec_pos = if has_decimal { Some(self.rng.random_range(0..num_digits)) } else { None }; let mut s = String::with_capacity(num_digits); @@ -75,7 +75,7 @@ impl Iterator for RandDigits { } if has_exp { - let exp = self.rng.gen_range(EXP_RANGE); + let exp = self.rng.random_range(EXP_RANGE); write!(s, "e{exp}").unwrap(); } diff --git a/src/etc/test-float-parse/src/lib.rs b/src/etc/test-float-parse/src/lib.rs index def66398d9fd1..e2f84b085c6f5 100644 --- a/src/etc/test-float-parse/src/lib.rs +++ b/src/etc/test-float-parse/src/lib.rs @@ -10,7 +10,7 @@ use std::sync::OnceLock; use std::sync::atomic::{AtomicU64, Ordering}; use std::{fmt, time}; -use rand::distributions::{Distribution, Standard}; +use rand::distr::{Distribution, StandardUniform}; use rayon::prelude::*; use time::{Duration, Instant}; use traits::{Float, Generator, Int}; @@ -132,7 +132,7 @@ fn register_float(tests: &mut Vec, cfg: &Config) where RangeInclusive: Iterator, >::Error: std::fmt::Debug, - Standard: Distribution<::Int>, + StandardUniform: Distribution<::Int>, { if F::BITS <= MAX_BITS_FOR_EXHAUUSTIVE { // Only run exhaustive tests if there is a chance of completion. From 9b71e86724923db15636fd8f0acc44f04be986ca Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 1 Feb 2025 19:50:04 +0000 Subject: [PATCH 2/3] Allow wit-bindgen-rt as compiler dependency --- src/tools/tidy/src/deps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 51e58b4e4fcfd..b8d1d8103f23b 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -446,6 +446,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", + "wit-bindgen-rt", // via wasi "writeable", "yoke", "yoke-derive", From aea9ddd745e6184dafeb0d0e3bab491910d0754b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 2 Mar 2025 14:10:32 +0000 Subject: [PATCH 3/3] Support locking versions in permitted rustc deps --- src/tools/tidy/src/deps.rs | 41 +++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index b8d1d8103f23b..5434e708bb715 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -1,11 +1,12 @@ //! Checks the licenses of third-party dependencies. -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::fs::{File, read_dir}; use std::io::Write; use std::path::Path; use build_helper::ci::CiEnv; +use cargo_metadata::semver::Version; use cargo_metadata::{Metadata, Package, PackageId}; #[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"] @@ -446,7 +447,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", - "wit-bindgen-rt", // via wasi + "wit-bindgen-rt@0.33.0", // via wasi "writeable", "yoke", "yoke-derive", @@ -804,7 +805,17 @@ fn check_permitted_dependencies( // Check that the PERMITTED_DEPENDENCIES does not have unused entries. for permitted in permitted_dependencies { - if !deps.iter().any(|dep_id| &pkg_from_id(metadata, dep_id).name == permitted) { + fn compare(pkg: &Package, permitted: &str) -> bool { + if let Some((name, version)) = permitted.split_once("@") { + let Ok(version) = Version::parse(version) else { + return false; + }; + pkg.name == name && pkg.version == version + } else { + pkg.name == permitted + } + } + if !deps.iter().any(|dep_id| compare(pkg_from_id(metadata, dep_id), permitted)) { tidy_error!( bad, "could not find allowed package `{permitted}`\n\ @@ -815,14 +826,30 @@ fn check_permitted_dependencies( } // Get in a convenient form. - let permitted_dependencies: HashSet<_> = permitted_dependencies.iter().cloned().collect(); + let permitted_dependencies: HashMap<_, _> = permitted_dependencies + .iter() + .map(|s| { + if let Some((name, version)) = s.split_once('@') { + (name, Version::parse(version).ok()) + } else { + (*s, None) + } + }) + .collect(); for dep in deps { let dep = pkg_from_id(metadata, dep); // If this path is in-tree, we don't require it to be explicitly permitted. - if dep.source.is_some() && !permitted_dependencies.contains(dep.name.as_str()) { - tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id); - has_permitted_dep_error = true; + if dep.source.is_some() { + let is_eq = if let Some(version) = permitted_dependencies.get(dep.name.as_str()) { + if let Some(version) = version { version == &dep.version } else { true } + } else { + false + }; + if !is_eq { + tidy_error!(bad, "Dependency for {descr} not explicitly permitted: {}", dep.id); + has_permitted_dep_error = true; + } } }