From e9c7df46cbcff797ae40ef6d0d7e13b5efa50d77 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 19 Mar 2025 00:11:39 +0000 Subject: [PATCH] Migrate all crates except `libm` to edition 2024 Unfortunately this means we lose use of the convenient name `gen`, so this includes a handful of renaming. We can't increase the edition for `libm` yet due to MSRV, but we can enable `unsafe_op_in_unsafe_fn` to help make that change smoother in the future. --- crates/compiler-builtins-smoke-test/src/math.rs | 8 ++++---- crates/libm-macros/Cargo.toml | 2 +- crates/libm-test/Cargo.toml | 2 +- crates/libm-test/benches/icount.rs | 2 +- crates/libm-test/benches/random.rs | 4 ++-- crates/libm-test/examples/plot_domains.rs | 8 ++++---- crates/libm-test/src/{gen.rs => generate.rs} | 0 crates/libm-test/src/{gen => generate}/case_list.rs | 0 crates/libm-test/src/{gen => generate}/edge_cases.rs | 2 +- crates/libm-test/src/{gen => generate}/random.rs | 0 crates/libm-test/src/{gen => generate}/spaced.rs | 0 crates/libm-test/src/lib.rs | 2 +- crates/libm-test/src/run_cfg.rs | 4 ++-- crates/libm-test/tests/compare_built_musl.rs | 2 +- crates/libm-test/tests/multiprecision.rs | 2 +- crates/libm-test/tests/standalone.rs | 2 +- crates/libm-test/tests/u256.rs | 2 +- crates/libm-test/tests/z_extensive/run.rs | 2 +- crates/musl-math-sys/Cargo.toml | 2 +- crates/musl-math-sys/src/lib.rs | 2 +- crates/util/Cargo.toml | 2 +- src/lib.rs | 1 + 22 files changed, 26 insertions(+), 25 deletions(-) rename crates/libm-test/src/{gen.rs => generate.rs} (100%) rename crates/libm-test/src/{gen => generate}/case_list.rs (100%) rename crates/libm-test/src/{gen => generate}/edge_cases.rs (99%) rename crates/libm-test/src/{gen => generate}/random.rs (100%) rename crates/libm-test/src/{gen => generate}/spaced.rs (100%) diff --git a/crates/compiler-builtins-smoke-test/src/math.rs b/crates/compiler-builtins-smoke-test/src/math.rs index 7e0146998..279050902 100644 --- a/crates/compiler-builtins-smoke-test/src/math.rs +++ b/crates/compiler-builtins-smoke-test/src/math.rs @@ -14,7 +14,7 @@ macro_rules! no_mangle { // Handle simple functions with single return types (@inner $name:ident( $($arg:ident: $aty:ty),+ ) -> $ret:ty) => { - #[no_mangle] + #[unsafe(no_mangle)] extern "C" fn $name($($arg: $aty),+) -> $ret { libm::$name($($arg),+) } @@ -26,7 +26,7 @@ macro_rules! no_mangle { ( @inner $name:ident( $($arg:ident: $aty:ty),+ | $($rarg:ident: $rty:ty),+) -> $ret:ty ) => { - #[no_mangle] + #[unsafe(no_mangle)] extern "C" fn $name($($arg: $aty,)+ $($rarg: $rty),+) -> $ret { let ret; (ret, $(*$rarg),+) = libm::$name($($arg),+); @@ -166,12 +166,12 @@ no_mangle! { /* sincos has no direct return type, not worth handling in the macro */ -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn sincos(x: f64, s: &mut f64, c: &mut f64) { (*s, *c) = libm::sincos(x); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) { (*s, *c) = libm::sincosf(x); } diff --git a/crates/libm-macros/Cargo.toml b/crates/libm-macros/Cargo.toml index 314f4ae37..50c869db7 100644 --- a/crates/libm-macros/Cargo.toml +++ b/crates/libm-macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libm-macros" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/crates/libm-test/Cargo.toml b/crates/libm-test/Cargo.toml index 98da73cea..eb9784ef7 100644 --- a/crates/libm-test/Cargo.toml +++ b/crates/libm-test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libm-test" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [features] diff --git a/crates/libm-test/benches/icount.rs b/crates/libm-test/benches/icount.rs index 4a10ec383..da8c6bfd1 100644 --- a/crates/libm-test/benches/icount.rs +++ b/crates/libm-test/benches/icount.rs @@ -4,7 +4,7 @@ use std::hint::black_box; use iai_callgrind::{library_benchmark, library_benchmark_group, main}; use libm::support::{HInt, u256}; -use libm_test::gen::spaced; +use libm_test::generate::spaced; use libm_test::{CheckBasis, CheckCtx, GeneratorKind, MathOp, OpRustArgs, TupleCall, op}; const BENCH_ITER_ITEMS: u64 = 500; diff --git a/crates/libm-test/benches/random.rs b/crates/libm-test/benches/random.rs index 17e4e0d55..63d7e5c6d 100644 --- a/crates/libm-test/benches/random.rs +++ b/crates/libm-test/benches/random.rs @@ -2,8 +2,8 @@ use std::hint::black_box; use std::time::Duration; use criterion::{Criterion, criterion_main}; -use libm_test::gen::random; -use libm_test::gen::random::RandomInput; +use libm_test::generate::random; +use libm_test::generate::random::RandomInput; use libm_test::{CheckBasis, CheckCtx, GeneratorKind, MathOp, TupleCall}; /// Benchmark with this many items to get a variety diff --git a/crates/libm-test/examples/plot_domains.rs b/crates/libm-test/examples/plot_domains.rs index 441889c69..78524761e 100644 --- a/crates/libm-test/examples/plot_domains.rs +++ b/crates/libm-test/examples/plot_domains.rs @@ -12,8 +12,8 @@ use std::path::Path; use std::process::Command; use std::{env, fs}; -use libm_test::gen::spaced::SpacedInput; -use libm_test::gen::{edge_cases, spaced}; +use libm_test::generate::spaced::SpacedInput; +use libm_test::generate::{edge_cases, spaced}; use libm_test::{CheckBasis, CheckCtx, GeneratorKind, MathOp, op}; const JL_PLOT: &str = "examples/plot_file.jl"; @@ -73,7 +73,7 @@ fn plot_one_generator( ctx: &CheckCtx, gen_name: &str, config: &mut String, - gen: impl Iterator, + generator: impl Iterator, ) { let fn_name = ctx.base_name_str; let text_file = out_dir.join(format!("input-{fn_name}-{gen_name}.txt")); @@ -82,7 +82,7 @@ fn plot_one_generator( let mut w = BufWriter::new(f); let mut count = 0u64; - for input in gen { + for input in generator { writeln!(w, "{:e}", input.0).unwrap(); count += 1; } diff --git a/crates/libm-test/src/gen.rs b/crates/libm-test/src/generate.rs similarity index 100% rename from crates/libm-test/src/gen.rs rename to crates/libm-test/src/generate.rs diff --git a/crates/libm-test/src/gen/case_list.rs b/crates/libm-test/src/generate/case_list.rs similarity index 100% rename from crates/libm-test/src/gen/case_list.rs rename to crates/libm-test/src/generate/case_list.rs diff --git a/crates/libm-test/src/gen/edge_cases.rs b/crates/libm-test/src/generate/edge_cases.rs similarity index 99% rename from crates/libm-test/src/gen/edge_cases.rs rename to crates/libm-test/src/generate/edge_cases.rs index 69b59a105..56cc9fa9a 100644 --- a/crates/libm-test/src/gen/edge_cases.rs +++ b/crates/libm-test/src/generate/edge_cases.rs @@ -3,7 +3,7 @@ use libm::support::{CastInto, Float, Int, MinInt}; use crate::domain::get_domain; -use crate::gen::KnownSize; +use crate::generate::KnownSize; use crate::op::OpITy; use crate::run_cfg::{check_near_count, check_point_count}; use crate::{BaseName, CheckCtx, FloatExt, FloatTy, MathOp, test_log}; diff --git a/crates/libm-test/src/gen/random.rs b/crates/libm-test/src/generate/random.rs similarity index 100% rename from crates/libm-test/src/gen/random.rs rename to crates/libm-test/src/generate/random.rs diff --git a/crates/libm-test/src/gen/spaced.rs b/crates/libm-test/src/generate/spaced.rs similarity index 100% rename from crates/libm-test/src/gen/spaced.rs rename to crates/libm-test/src/generate/spaced.rs diff --git a/crates/libm-test/src/lib.rs b/crates/libm-test/src/lib.rs index 824f09a33..485c01a47 100644 --- a/crates/libm-test/src/lib.rs +++ b/crates/libm-test/src/lib.rs @@ -4,7 +4,7 @@ pub mod domain; mod f8_impl; -pub mod gen; +pub mod generate; #[cfg(feature = "build-mpfr")] pub mod mpfloat; mod num; diff --git a/crates/libm-test/src/run_cfg.rs b/crates/libm-test/src/run_cfg.rs index 8e4fff53c..b36164b00 100644 --- a/crates/libm-test/src/run_cfg.rs +++ b/crates/libm-test/src/run_cfg.rs @@ -4,7 +4,7 @@ use std::ops::RangeInclusive; use std::sync::LazyLock; use std::{env, str}; -use crate::gen::random::{SEED, SEED_ENV}; +use crate::generate::random::{SEED, SEED_ENV}; use crate::{BaseName, FloatTy, Identifier, test_log}; /// The environment variable indicating which extensive tests should be run. @@ -241,7 +241,7 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 { // Some tests are significantly slower than others and need to be further reduced. if let Some((_id, _gen, scale)) = EXTEMELY_SLOW_TESTS .iter() - .find(|(id, gen, _scale)| *id == ctx.fn_ident && *gen == ctx.gen_kind) + .find(|(id, generator, _scale)| *id == ctx.fn_ident && *generator == ctx.gen_kind) { // However, do not override if the extensive iteration count has been manually set. if !(ctx.gen_kind == GeneratorKind::Extensive && EXTENSIVE_ITER_OVERRIDE.is_some()) { diff --git a/crates/libm-test/tests/compare_built_musl.rs b/crates/libm-test/tests/compare_built_musl.rs index 897dfc26e..cbb4bd49b 100644 --- a/crates/libm-test/tests/compare_built_musl.rs +++ b/crates/libm-test/tests/compare_built_musl.rs @@ -9,7 +9,7 @@ // There are some targets we can't build musl for #![cfg(feature = "build-musl")] -use libm_test::gen::{case_list, edge_cases, random, spaced}; +use libm_test::generate::{case_list, edge_cases, random, spaced}; use libm_test::{CheckBasis, CheckCtx, CheckOutput, GeneratorKind, MathOp, TupleCall}; const BASIS: CheckBasis = CheckBasis::Musl; diff --git a/crates/libm-test/tests/multiprecision.rs b/crates/libm-test/tests/multiprecision.rs index 0ab4b64da..80b2c7868 100644 --- a/crates/libm-test/tests/multiprecision.rs +++ b/crates/libm-test/tests/multiprecision.rs @@ -2,7 +2,7 @@ #![cfg(feature = "build-mpfr")] -use libm_test::gen::{case_list, edge_cases, random, spaced}; +use libm_test::generate::{case_list, edge_cases, random, spaced}; use libm_test::mpfloat::MpOp; use libm_test::{CheckBasis, CheckCtx, CheckOutput, GeneratorKind, MathOp, TupleCall}; diff --git a/crates/libm-test/tests/standalone.rs b/crates/libm-test/tests/standalone.rs index 7d694843e..7b30a3b48 100644 --- a/crates/libm-test/tests/standalone.rs +++ b/crates/libm-test/tests/standalone.rs @@ -1,6 +1,6 @@ //! Test cases that have both an input and an output, so do not require a basis. -use libm_test::gen::case_list; +use libm_test::generate::case_list; use libm_test::{CheckBasis, CheckCtx, CheckOutput, GeneratorKind, MathOp, TupleCall}; const BASIS: CheckBasis = CheckBasis::None; diff --git a/crates/libm-test/tests/u256.rs b/crates/libm-test/tests/u256.rs index 460353424..4444036d0 100644 --- a/crates/libm-test/tests/u256.rs +++ b/crates/libm-test/tests/u256.rs @@ -9,7 +9,7 @@ use libm::support::{HInt, u256}; type BigInt = rug::Integer; use libm_test::bigint_fuzz_iteration_count; -use libm_test::gen::random::SEED; +use libm_test::generate::random::SEED; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; use rug::Assign; diff --git a/crates/libm-test/tests/z_extensive/run.rs b/crates/libm-test/tests/z_extensive/run.rs index 786546a9d..b10c231d1 100644 --- a/crates/libm-test/tests/z_extensive/run.rs +++ b/crates/libm-test/tests/z_extensive/run.rs @@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; use indicatif::{ProgressBar, ProgressStyle}; -use libm_test::gen::spaced; +use libm_test::generate::spaced; use libm_test::mpfloat::MpOp; use libm_test::{ CheckBasis, CheckCtx, CheckOutput, GeneratorKind, MathOp, TestResult, TupleCall, diff --git a/crates/musl-math-sys/Cargo.toml b/crates/musl-math-sys/Cargo.toml index 34682b74c..91d9ad33c 100644 --- a/crates/musl-math-sys/Cargo.toml +++ b/crates/musl-math-sys/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "musl-math-sys" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/crates/musl-math-sys/src/lib.rs b/crates/musl-math-sys/src/lib.rs index 07277ef3e..6a4bf4859 100644 --- a/crates/musl-math-sys/src/lib.rs +++ b/crates/musl-math-sys/src/lib.rs @@ -10,7 +10,7 @@ macro_rules! functions { $( #[$meta:meta] )* $pfx_name:ident: $name:ident( $($arg:ident: $aty:ty),+ ) -> $rty:ty; )* ) => { - extern "C" { + unsafe extern "C" { $( fn $pfx_name( $($arg: $aty),+ ) -> $rty; )* } diff --git a/crates/util/Cargo.toml b/crates/util/Cargo.toml index 8005459db..bca6b445a 100644 --- a/crates/util/Cargo.toml +++ b/crates/util/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "util" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [features] diff --git a/src/lib.rs b/src/lib.rs index b0e431211..7e56bd079 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ #![allow(clippy::needless_return)] #![allow(clippy::unreadable_literal)] #![allow(clippy::zero_divided_by_zero)] +#![forbid(unsafe_op_in_unsafe_fn)] mod libm_helper; mod math;