Merge pull request rust-lang/libm#479 from tgross35/cargo-profile-updates

Rework the available Cargo profiles
This commit is contained in:
Trevor Gross 2025-01-27 20:16:39 -06:00 committed by GitHub
commit 98fd72b62a
7 changed files with 51 additions and 39 deletions

View file

@ -61,19 +61,21 @@ exclude = [
[dev-dependencies]
no-panic = "0.1.33"
[profile.release]
# Options for no-panic to correctly detect the lack of panics
codegen-units = 1
lto = "fat"
# The default release profile is unchanged.
# Release mode with debug assertions
[profile.release-checked]
codegen-units = 1
debug-assertions = true
inherits = "release"
lto = "fat"
debug-assertions = true
overflow-checks = true
# Release with maximum optimizations, which is very slow to build. This is also
# what is needed to check `no-panic`.
[profile.release-opt]
inherits = "release"
codegen-units = 1
lto = "fat"
[profile.bench]
# Required for iai-callgrind
debug = true

View file

@ -8,18 +8,9 @@ fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
println!("cargo:rustc-check-cfg=cfg(feature, values(\"checked\"))");
#[allow(unexpected_cfgs)]
if !cfg!(feature = "checked") {
let lvl = env::var("OPT_LEVEL").unwrap();
if lvl != "0" && !cfg!(debug_assertions) {
println!("cargo:rustc-cfg=assert_no_panic");
} else if env::var("ENSURE_NO_PANIC").is_ok() {
// Give us a defensive way of ensureing that no-panic is checked when we
// expect it to be.
panic!("`assert_no_panic `was not enabled");
}
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
if env::var("ENSURE_NO_PANIC").is_ok() {
println!("cargo:rustc-cfg=assert_no_panic");
}
configure::emit_libm_config(&cfg);

View file

@ -117,4 +117,14 @@ $cmd "$profile" release-checked --features unstable-intrinsics
$cmd "$profile" release-checked --features unstable-intrinsics --benches
# Ensure that the routines do not panic.
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
#
# `--tests` must be passed because no-panic is only enabled as a dev
# dependency. The `release-opt` profile must be used to enable LTO and a
# single CGU.
ENSURE_NO_PANIC=1 cargo build \
-p libm \
--target "$target" \
--no-default-features \
--features unstable-float \
--tests \
--profile release-opt

View file

@ -22,7 +22,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(arch_enabled)",
"cfg(assert_no_panic)",
"cfg(intrinsics_enabled)",
'cfg(feature, values("checked"))',
'cfg(feature, values("force-soft-floats"))',
'cfg(feature, values("unstable"))',
'cfg(feature, values("unstable-intrinsics"))',

View file

@ -114,12 +114,18 @@ pub fn atan2(y: f64, x: f64) -> f64 {
}
}
#[test]
fn sanity_check() {
assert_eq!(atan2(0.0, 1.0), 0.0);
assert_eq!(atan2(0.0, -1.0), PI);
assert_eq!(atan2(-0.0, -1.0), -PI);
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
fn sanity_check() {
assert_eq!(atan2(0.0, 1.0), 0.0);
assert_eq!(atan2(0.0, -1.0), PI);
assert_eq!(atan2(-0.0, -1.0), -PI);
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
}
}

View file

@ -226,8 +226,9 @@ pub(crate) fn rem_pio2_large(x: &[f64], y: &mut [f64], e0: i32, prec: usize) ->
let x1p24 = f64::from_bits(0x4170000000000000); // 0x1p24 === 2 ^ 24
let x1p_24 = f64::from_bits(0x3e70000000000000); // 0x1p_24 === 2 ^ (-24)
#[cfg(all(target_pointer_width = "64", feature = "checked"))]
assert!(e0 <= 16360);
if cfg!(target_pointer_width = "64") {
debug_assert!(e0 <= 16360);
}
let nx = x.len();

View file

@ -81,12 +81,15 @@ pub fn sin(x: f64) -> f64 {
}
}
#[test]
fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
let result = sin(x);
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let result = force_eval!(result);
assert_eq!(result, sx);
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
assert_eq!(sin(x), sx);
}
}