bitstrings #447
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq!447
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "string-bits"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Review
Traced both functions by hand against the runtime/codegen for
shr,band, andstring.concat; logic is correct and the documented behavior matches reality.Correctness
int->bits-loop(imath.seq:159) — LSB-first loop, MSB-first accumulator viastring.concat (bit-str ++ acc). Tail call is in tail position, same shape asgcdabove it, so TCO applies.int->bits(imath.seq:172) — handles0specially since the loop's terminator (n == 0) would otherwise return the empty string for0. Good.int->bits-padded-loop(imath.seq:183) — verified theswap / rot / rotshuffle leaves(n>>1) (width-1) resultfor the recursive call. Also tail-recursive.int->bits-padded(imath.seq:196) —width <= 0returns"", which also covers the negative-width case correctly.Logical-shift claim is accurate
The header comment at
imath.seq:33-34saysshris logical/zero-fill. Confirmed againstruntime/src/arithmetic/bitwise.rs:107((v as u64).checked_shr) andcodegen/specialization/codegen_safe_math.rs:190(lshr). So-1 int->bitscorrectly produces 64 ones, andint->bits-paddedtruncating to the low N bits works for negative inputs too.(Aside, not this PR's problem: the builtin doc at
crates/compiler/src/builtins/arith.rs:109still describesshras "arithmetic" — that line is stale relative to actual semantics.)One suggestion
The "negative ints render as full 64-bit two's-complement pattern" behavior is documented but not exercised by any test. It's the most regression-prone bit because it depends on
shrstaying logical. Worth pinning down with e.g.-1 4 int->bits-padded "1111" test.assert-eq-strand/or a-1 int->bitslength check.