This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 7d097720 [TEST][Rust] Avoid fixed NaN payloads across float casts
(#922)
7d097720 is described below
commit 7d097720891cc06e67f314f57e0688c1e056e9e0
Author: Yaxing Cai <[email protected]>
AuthorDate: Thu Nov 5 02:14:58 2026 +0800
[TEST][Rust] Avoid fixed NaN payloads across float casts (#922)
The crate publishing dry run for v0.1.16-rc0 fails in
`matches_concrete_object_containers_in_source_order` on Linux ARM64,
macOS ARM64, and Windows AMD64. The test expects a negative NaN payload
to survive `f32`/`f64` casts, but Rust allows those casts to change the
NaN sign and payload; the optimized build returns `0x7fc00000` instead
of `0xffc00001`.
Check that a matched `f32` remains NaN, or that an `f64` fallback
retains the original stored bits. Keep the exact checks for signed zero,
infinity, finite narrowing, and an unrepresentable NaN payload. This
changes only the test.
Validation: reproduced the original failure locally on macOS ARM64 with
Rust 1.99.1; `cargo +stable test --release --workspace` passes with the
correction, including doctests. The local native library was built from
source identical to the candidate's `src/` and `include/` trees.
Registry uploads remain disabled, and v0.1.16-rc0 is unchanged.
- Failing candidate run:
https://github.com/apache/tvm-ffi/actions/runs/41882451026
- Rust NaN guarantees:
https://doc.rust-lang.org/std/primitive.f32.html#nan-bit-patterns
---
rust/tvm-ffi/tests/test_match_any.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/rust/tvm-ffi/tests/test_match_any.rs
b/rust/tvm-ffi/tests/test_match_any.rs
index d3906a37..438accee 100644
--- a/rust/tvm-ffi/tests/test_match_any.rs
+++ b/rust/tvm-ffi/tests/test_match_any.rs
@@ -170,7 +170,6 @@ fn matches_concrete_object_containers_in_source_order() {
for (stored, expected) in [
(-0.0, Some(0x8000_0000)),
(f64::INFINITY, Some(f32::INFINITY.to_bits())),
- (f32::from_bits(0xffc0_0001) as f64, Some(0xffc0_0001)),
(f64::from_bits(0x7ff8_0000_0000_0001), None),
(16_777_217.0, None),
(1e40, None),
@@ -184,6 +183,15 @@ fn matches_concrete_object_containers_in_source_order() {
expected
);
}
+ // Rust permits float casts to change a NaN's sign and payload. A matched
+ // f32 must remain NaN; a fallback f64 must retain the original stored
bits.
+ for bits in [0x7ff8_0000_0000_0000, 0xfff8_0000_2000_0000] {
+ match_any!(Any::from(f64::from_bits(bits)) {
+ f32(n) => assert!(n.is_nan()),
+ f64(n) => assert_eq!(n.to_bits(), bits),
+ _ => unreachable!(),
+ });
+ }
assert_eq!(
match_any!(Any::from(257_i64) { Option<u8>(n) => n, _ => None }),
None