Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 8660ace

Browse files
authored
Merge pull request #479 from tgross35/cargo-profile-updates
Rework the available Cargo profiles
2 parents 46a3bce + f5f789a commit 8660ace

File tree

7 files changed

+50
-38
lines changed

7 files changed

+50
-38
lines changed

Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,20 @@ exclude = [
6161
[dev-dependencies]
6262
no-panic = "0.1.33"
6363

64-
[profile.release]
65-
# Options for no-panic to correctly detect the lack of panics
66-
codegen-units = 1
67-
lto = "fat"
64+
# The default release profile is unchanged.
6865

6966
# Release mode with debug assertions
7067
[profile.release-checked]
71-
codegen-units = 1
68+
inherits = "release"
7269
debug-assertions = true
70+
overflow-checks = true
71+
72+
# Release with maximum optimizations, which is very slow to build. This is also
73+
# what is needed to check `no-panic`.
74+
[profile.release-opt]
7375
inherits = "release"
76+
codegen-units = 1
7477
lto = "fat"
75-
overflow-checks = true
7678

7779
[profile.bench]
7880
# Required for iai-callgrind

build.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ fn main() {
88
println!("cargo:rerun-if-changed=build.rs");
99
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
1010

11-
println!("cargo:rustc-check-cfg=cfg(feature, values(\"checked\"))");
12-
13-
#[allow(unexpected_cfgs)]
14-
if !cfg!(feature = "checked") {
15-
let lvl = env::var("OPT_LEVEL").unwrap();
16-
if lvl != "0" && !cfg!(debug_assertions) {
17-
println!("cargo:rustc-cfg=assert_no_panic");
18-
} else if env::var("ENSURE_NO_PANIC").is_ok() {
19-
// Give us a defensive way of ensureing that no-panic is checked when we
20-
// expect it to be.
21-
panic!("`assert_no_panic `was not enabled");
22-
}
11+
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
12+
if env::var("ENSURE_NO_PANIC").is_ok() {
13+
println!("cargo:rustc-cfg=assert_no_panic");
2314
}
2415

2516
configure::emit_libm_config(&cfg);

ci/run.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ $cmd "$profile" release-checked --features unstable-intrinsics
117117
$cmd "$profile" release-checked --features unstable-intrinsics --benches
118118

119119
# Ensure that the routines do not panic.
120-
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
120+
#
121+
# `--tests` must be passed because no-panic is only enabled as a dev
122+
# dependency. The `release-opt` profile must be used to enable LTO and a
123+
# single CGU.
124+
ENSURE_NO_PANIC=1 cargo build \
125+
-p libm \
126+
--target "$target" \
127+
--no-default-features \
128+
--features unstable-float \
129+
--tests \
130+
--profile release-opt

crates/compiler-builtins-smoke-test/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [
2222
"cfg(arch_enabled)",
2323
"cfg(assert_no_panic)",
2424
"cfg(intrinsics_enabled)",
25-
'cfg(feature, values("checked"))',
2625
'cfg(feature, values("force-soft-floats"))',
2726
'cfg(feature, values("unstable"))',
2827
'cfg(feature, values("unstable-intrinsics"))',

src/math/atan2.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ pub fn atan2(y: f64, x: f64) -> f64 {
114114
}
115115
}
116116

117-
#[test]
118-
fn sanity_check() {
119-
assert_eq!(atan2(0.0, 1.0), 0.0);
120-
assert_eq!(atan2(0.0, -1.0), PI);
121-
assert_eq!(atan2(-0.0, -1.0), -PI);
122-
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
123-
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
124-
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
117+
#[cfg(test)]
118+
mod tests {
119+
use super::*;
120+
121+
#[test]
122+
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
123+
fn sanity_check() {
124+
assert_eq!(atan2(0.0, 1.0), 0.0);
125+
assert_eq!(atan2(0.0, -1.0), PI);
126+
assert_eq!(atan2(-0.0, -1.0), -PI);
127+
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
128+
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
129+
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
130+
}
125131
}

src/math/rem_pio2_large.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ pub(crate) fn rem_pio2_large(x: &[f64], y: &mut [f64], e0: i32, prec: usize) ->
226226
let x1p24 = f64::from_bits(0x4170000000000000); // 0x1p24 === 2 ^ 24
227227
let x1p_24 = f64::from_bits(0x3e70000000000000); // 0x1p_24 === 2 ^ (-24)
228228

229-
#[cfg(all(target_pointer_width = "64", feature = "checked"))]
230-
assert!(e0 <= 16360);
229+
if cfg!(target_pointer_width = "64") {
230+
debug_assert!(e0 <= 16360);
231+
}
231232

232233
let nx = x.len();
233234

src/math/sin.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ pub fn sin(x: f64) -> f64 {
8181
}
8282
}
8383

84-
#[test]
85-
fn test_near_pi() {
86-
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
87-
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
88-
let result = sin(x);
89-
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
90-
let result = force_eval!(result);
91-
assert_eq!(result, sx);
84+
#[cfg(test)]
85+
mod tests {
86+
use super::*;
87+
88+
#[test]
89+
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
90+
fn test_near_pi() {
91+
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
92+
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
93+
assert_eq!(sin(x), sx);
94+
}
9295
}

0 commit comments

Comments
 (0)