Skip to content

Fix numeric lowering and standard-library boundary handling - #707

Merged
LunaStev merged 12 commits into
wavefnd:masterfrom
LunaStev:fix/numeric-and-stdlib-boundaries
Sep 24, 2026
Merged

LunaStev merged 12 commits into
wavefnd:masterfrom
LunaStev:fix/numeric-and-stdlib-boundaries

Conversation

@LunaStev

Copy link
Copy Markdown
Member

Summary

Fix twelve compiler and standard-library correctness issues, with one DCO-signed commit per issue and regression coverage alongside each change.

  • Resolve integer-literal arithmetic at the contextual integer width before lowering, reject out-of-range operands, use unordered floating-point inequality, and preserve signed zero during unary negation.
  • Correct buffer source-range detection, file-read capacity growth, and path capacity, classification, and component boundaries.
  • Normalize duration carry/borrow before overflow checks, correct the FNV-1a offset basis, and return ordered trim ranges for whitespace-only input.

For example, comparing a u64 value against 4294967296 - 32 now uses the bound 4294967264, instead of truncating the expression to i32 and extending -32.

Motivation

Issue Result
Fixes #702 Contextual integer width and signedness survive nested arithmetic; oversized operands produce source diagnostics.
Fixes #682 Float != returns true for unordered NaN comparisons in all numeric paths.
Fixes #683 Float unary minus uses fneg, preserving signed-zero and NaN payload behavior.
Fixes #676 An adjacent allocation is accepted as an external append source; self-append handling remains intact.
Fixes #597 read_to_end reports capacity-doubling overflow and restores the original buffer length.
Fixes #521 Dirname's . fallback reserves space for both the dot and its terminator before writing.
Fixes #529 Absolute-path classification follows the compilation target's Windows or POSIX policy.
Fixes #677 Windows dirname extraction preserves drive roots such as C:\.
Fixes #592 Basename extraction ignores trailing separators while retaining the empty-basename convention for roots.
Fixes #522 Duration carry/borrow can recover representable boundary results before seconds overflow is checked.
Fixes #547 FNV-1a uses the standard 64-bit offset basis and unsigned-byte wrapping arithmetic.
Fixes #548 Empty and whitespace-only strings yield bounded, ordered trim ranges.

The saved pre-change compiler and standard library reproduced failures in eleven focused programs covering all twelve issues, including the original #702 reproducer. The Windows path issues share one regression program.

Target and compatibility impact

  • Integer-only arithmetic borrows an integer destination or typed peer's width and signedness. Unconstrained expressions retain the i32 fallback; out-of-range operands are diagnosed before truncation. Integer division still occurs before conversion to a floating-point destination.
  • Windows absolute paths must be fully qualified drive paths or UNC paths with a server and share. Drive-relative and root-relative paths are not absolute. Other targets retain POSIX leading-slash semantics. Existing dirname trailing-separator behavior is preserved.
  • Correcting FNV-1a changes hashes emitted by older versions. Its public i64 return type still exposes the 64-bit hash bit pattern. API comments document this change and the path/trim conventions.
  • No public function signatures, ABIs, CLI options, or compiler/std compatibility revision change. No libc FFI is added.

Validation

Cargo commands used LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 and --jobs 2 for builds and tests.

  • cargo fmt --all --check, git diff --check, and whitespace checks for every commit.
  • ./tools/check_std_policy.sh.
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --no-deps --jobs 2.
  • cargo clippy --locked --workspace --all-targets --jobs 2 -- -D warnings.
  • Python syntax checks for the files listed in CONTRIBUTING.md; python3 -m unittest tools.test_case_manifest tools.test_test_contracts tools.test_process_tree: 38 tests, one skip.
  • cargo build --locked --release --jobs 2; python3 tools/check_wave_corpus.py --wavec target/release/wavec --run-std-examples: 288 corpus checks and 26 std examples passed.
  • cargo test --locked --workspace --all-targets --jobs 2: completed suites passed except one existing async TCP regression blocked by the sandbox's local-socket restrictions. That exact regression passed when rerun with socket access; the remaining frontend, runtime, and std-I/O suites also passed with that access. Parser tests and all 13 new boundary regression tests passed; executable boundary cases run at both -O0 and -O2.
  • Focused AArch64, RISC-V, and LoongArch64 QEMU cases: 36 O0/O2 executions passed using freestanding static Linux test runtimes.
  • Focused wasm32/wasm64 numeric and controlled-allocator cases: 20 O0/O2 executions passed.
  • Windows path cases compile for x64 and ARM64. Existing/new x64 path cases passed 10 O0/O2 executions under Wine; this is not a native Windows runtime result.

Checklist

  • Commits include a DCO Signed-off-by line.
  • Tests cover new behavior or the PR explains why no test is needed.
  • User-facing changes include documentation or diagnostics updates.
  • The change preserves the license boundary between the compiler and std/.

Resolve literal arithmetic from its integer destination or typed peer before lowering. Diagnose operands that exceed that type and retain integer division semantics at float conversion sites.

Fixes wavefnd#702

Signed-off-by: LunaStev <[email protected]>
Make NaN unequal in all float comparison paths. Cover both operand orders, mixed numeric operands, and finite values at O0 and O2.

Fixes wavefnd#682

Signed-off-by: LunaStev <[email protected]>
Preserve signed zero and NaN payloads by using LLVM floating-point negation. Check exact f32 and f64 bit patterns at O0 and O2.

Fixes wavefnd#683

Signed-off-by: LunaStev <[email protected]>
Use a half-open allocation range when detecting self-appends. Exercise adjacent allocations, moving growth, interior sources, and failure-state preservation with a controlled allocator.

Fixes wavefnd#676

Signed-off-by: LunaStev <[email protected]>
Return the buffer overflow error and restore the original length when capacity cannot be doubled. Cover overflow, guard bytes, and normal empty and growing file reads.

Fixes wavefnd#597

Signed-off-by: LunaStev <[email protected]>
Account for both the fallback dot and its terminator before writing. Cover empty and filename-only inputs with zero, one, and two-byte capacities and guard bytes.

Fixes wavefnd#521

Signed-off-by: LunaStev <[email protected]>
Require fully qualified drive or UNC paths on Windows and a leading slash on POSIX targets. Cover drive-relative and root-relative inputs and compile path regressions for Windows x64 and ARM64.

Fixes wavefnd#529

Signed-off-by: LunaStev <[email protected]>
Clamp dirname trimming at the target-recognized drive root while preserving POSIX and existing trailing-separator behavior. Check exact output and destination guards.

Fixes wavefnd#677

Signed-off-by: LunaStev <[email protected]>
Find the final non-root component before trailing separators and bound extension scanning to it. Preserve root-only empty basenames and existing dirname behavior.

Fixes wavefnd#592

Signed-off-by: LunaStev <[email protected]>
Fold nanosecond carry or borrow into a safe operand before checking the seconds operation. Cover representable boundary results and checked/saturating agreement with integer-oracle cases.

Fixes wavefnd#522

Signed-off-by: LunaStev <[email protected]>
Hash unsigned bytes with wrapping u64 arithmetic and return the existing i64 bit pattern. Document the corrected output and check empty, ASCII, and UTF-8 vectors.

Fixes wavefnd#547

Signed-off-by: LunaStev <[email protected]>
Clamp the right endpoint to the left endpoint for all-whitespace strings. Check empty, whitespace-only, and content-bearing inputs without changing the individual trim helpers.

Fixes wavefnd#548

Signed-off-by: LunaStev <[email protected]>
@LunaStev
LunaStev merged commit 01955d7 into wavefnd:master Sep 24, 2026
24 of 25 checks passed
@LunaStev LunaStev mentioned this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment