Fix decompose_float subnormals, float format grouping/empty type; add HashSecret::from_keys#8232
Fix decompose_float subnormals, float format grouping/empty type; add HashSecret::from_keys#8232youknowone wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR updates subnormal float decomposition, float and integer formatting edge cases, and explicit-key ChangesFloat and formatting correctness fixes
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/common/src/hash.rs (1)
316-316: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueLocked digest correctness depends on runtime verification.
LOCKED_DIGESTis a hardcoded regression value; its correctness can't be confirmed statically and requirescargo test -p rustpython-commonto pass. If the underlyingsiphashercrate version orkeyed_hashderivation ever changes, this constant will need updating — worth a brief comment noting that intent so future changes aren't mistaken for bugs.Also applies to: 334-334
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/common/src/hash.rs` at line 316, Add a brief inline comment near LOCKED_DIGEST (and the related second occurrence) in hash.rs explaining that it is a regression lock value verified by runtime tests, not a statically derivable constant. Make clear that changes to siphasher or keyed_hash derivation may require updating the value, so future maintainers know this is intentional.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/common/src/hash.rs`:
- Line 316: Add a brief inline comment near LOCKED_DIGEST (and the related
second occurrence) in hash.rs explaining that it is a regression lock value
verified by runtime tests, not a statically derivable constant. Make clear that
changes to siphasher or keyed_hash derivation may require updating the value, so
future maintainers know this is intentional.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 6c8d180e-2c74-4afb-9382-a684f7e264c9
📒 Files selected for processing (3)
crates/common/src/float_ops.rscrates/common/src/format.rscrates/common/src/hash.rs
Subnormals carry a biased exponent of 0 and no implicit leading mantissa bit, so the bit-twiddling frexp misread them: hash(5e-324) returned 8404992 instead of CPython's 16777216. Scale subnormals into the normal range by 2**54 (exact) before decomposing and fold the shift back into the returned exponent. Adds a frexp-contract unit test over normals, subnormals, and boundary values. Assisted-by: Claude
HashSecret's fields are private and the only constructor derives k0/k1 from a u32 seed, so an embedder cannot reproduce a fixed keying (e.g. a deterministic PYTHONHASHSEED=0-style run). Add a const constructor taking explicit SipHash keys; the seeded path is unchanged. Assisted-by: Claude
Thousands grouping split the magnitude only on '.', so exponent and percent tails received separators (format(1e20, ',e') gave '1e+,20'-class corruption). Group only the leading integer digits for interval-3 output; hex/octal/binary keep whole-magnitude grouping. Empty presentation type: with a precision, clamp it to at least 1 and restore a trailing '.0' on integer-looking results (Py_DTSF_ADD_DOT_0); without one, alternate form now inserts the forced decimal point before an exponent instead of appending it. Verified byte-identical to CPython 3.14 over a hash/format differential battery; test_format, test_float, test_fstring, test_hash pass. Assisted-by: Claude
- float_ops: use core::f64::consts::PI in the frexp-contract battery (clippy::approx_constant) - hash: rewrite the keyed_hash test via BuildHasher::hash_one (clippy::manual_hash_one) - rustfmt the new float_ops/hash/format test modules Assisted-by: Claude
701b70e to
2e84dee
Compare
Three fixes in
rustpython-common, found while building an external embedder (pyre) against the runtime-independent crates. Each was proven against CPython 3.14 ground truth.1.
float_ops::decompose_floatmishandles subnormalsThe bit-twiddling frexp assumes an implicit leading mantissa bit, which subnormals do not have.
Observable in RustPython before this fix:
Fix: scale subnormals into the normal range by an exact
2**54shift before decomposing, fold the shift into the returned exponent.const fnpreserved. Adds a frexp-contract unit test (mantissa in[0.5, 1),m * 2**e == |value|) over normals, subnormals, and boundary values.2.
hash::HashSecret::from_keysk0/k1are private and the only constructor derives them from au32seed, so an embedder cannot reproduce a fixed keying (deterministicPYTHONHASHSEED=0-style runs). Adds aconstconstructor taking explicit SipHash keys; the seeded path is unchanged. Unit test locks a fixed-key digest.3.
formatfloat presentation fixesTwo defects surfaced by a large format-spec differential battery:
., so exponent/percent tails received separators (format(1e20, ',e')produced1e+,20-class output). Now only the leading integer digits are grouped for decimal/float output; hex/octal/binary keep whole-magnitude grouping..0(Py_DTSF_ADD_DOT_0); without a precision, alternate form inserts the forced.before an exponent (1e+16→1.e+16) instead of appending it.Verification
cargo test -p rustpython-common: 45 pass (includes new tests),e,,.3e,,g,,%,.3,#g,08,): byte-identical-m test test_format test_float test_fstring test_hash: run=192 skipped=4 SUCCESS🤖 Generated with Claude Code
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
f64values to match frexp-like expectations.Tests