Repository navigation
Description
Tests: bit methods coverage (§4)
Summary
Runtime codegen implements the §4.2.4 integer bit methods, but coverage is incomplete. Add behavior tests for rotate, byte swap, population/count-zero methods, bit reverse, return types, width behavior, and signed receiver bit patterns.
Spec
docs/with-specification.md:1031-1145 defines rotate_left, rotate_right, swap_bytes, popcount, clz, ctz, and bitreverse. It specifies width-aware behavior, i32 return type for count methods, zero handling for clz/ctz, 8-bit identity for swap_bytes, and comptime evaluation.
Current state
src/MirLower.w:5852-5894classifies the bit methods as integer intrinsics.src/CodegenDispatch.w:7070-7190lowers runtime operations using LLVM intrinsics or shift/or code.test/behavior/behav_rotate.wandtest/behavior/behav_int_swap_bytes.wprovide partial runtime coverage.- There is no single spec-mapped test file covering all bit methods, return types, zero cases, width wrapping of rotate counts, signed receivers, and bitreverse.
- Comptime evaluation is a separate implementation gap tracked by Comptime evaluation of bit-manipulation methods (§4.2.4) #422.
Implementation plan
- Add/extend runtime behavior tests for every method listed in §4.2.4.
- Keep comptime-specific expectations in Comptime evaluation of bit-manipulation methods (§4.2.4) #422 unless implementing that issue at the same time. This issue can still include runtime tests that will pass before comptime support lands.
- Add type assertions for
popcount,clz, andctzreturningi32. - Include signed integer receivers where the expected result is defined by the fixed-width bit pattern.
- Include edge cases: zero input, all-ones input, 8-bit swap identity, rotate by 0, rotate by width, and rotate by greater than width.
Test plan
test/behavior/behav_int_bit_methods.wor extensions to existing files:u8,u16,u32, andu64examples.popcount(0) == 0,popcount(all_ones) == width.clz(0) == width,ctz(0) == width.swap_bytesidentity onu8, byte reversal onu16/u32.bitreverseon an obvious bit pattern.- rotate count normalization.
- Add compile-time type checks if the test harness has a convention for static assertions; otherwise use assignments to
i32for count method results. - Run
with build,with build :fixpoint, andwith build :test.
Acceptance criteria
- Every §4.2.4 bit method has runtime behavior coverage.
- Count methods are tested as returning
i32. - Zero behavior for
clzandctzis covered. - Width-sensitive behavior is covered.
- Comptime coverage is either added with Comptime evaluation of bit-manipulation methods (§4.2.4) #422 or explicitly left to Comptime evaluation of bit-manipulation methods (§4.2.4) #422.
Dependencies
Overlaps #422 for comptime evaluation. Do not block runtime coverage on #422 unless the chosen tests use const/comptime.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 4.2.4.17, 4.2.4.19, 4.2.4.20, 4.2.4.21, 4.2.4.22, 4.2.4.24, 4.2.4.25, 4.2.4.26.
Activity
ehartford commentedon Jul 3, 2026
Closing — runtime bit methods pinned by behav_int_bit_methods_runtime (ec03406): popcount/clz/ctz/swap_bytes/bitreverse across u8/u16/u32/u64, signed receiver, i32-return. (Comptime bit methods remain #422's scope.) §4.
test: coverage-sweep batch 2 (#483 #484 #522 #493 #494 #514 #515 #532)