semver: drop redundant store and two dead guards in the parser - #34804
Conversation
List::and_range assigned tail.range a second time right after the Box::new struct literal set it. Range is Copy and the parameter is &Range, so the second store is a no-op. In query::parse, the i < input.len() half of the hyphen-lookahead final check is always true: length_of_leading_whitespace_ascii returns at most the slice length, and the preceding i == input.len() check already broke out. In Version::parse, the b'-' | b'+' arm had a leading-space skip loop that can never iterate because input[i] is known to be '-' or '+' at the match dispatch and i is not advanced before the loop.
|
Status: Ready for a maintainer.
|
|
Warning Review limit reached
Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
LGTM — three provably dead statements removed, no behavior change.
What was reviewed:
List::and_range: the droppedtail.range = *rangere-stores the sameCopyvalue just written in the struct literal.- Hyphen lookahead: verified
length_of_leading_whitespace_asciireturns ≤ slice length, so the precedingi == input.len()break makes thei < input.len()guard tautological —input[i]cannot panic. Version::parsetag arm:iis unchanged betweenmatch input[i]and the loop, soinput[i]is-/+, never' '; the loop body is unreachable.
Extended reasoning...
Overview
Three deletions in the semver parser (src/semver/SemverQuery.rs, src/semver/Version.rs): a redundant field re-assignment in List::and_range, an always-true i < input.len() conjunct in the hyphen-range lookahead, and a while-loop whose condition is false on the first iteration in the b'-' | b'+' match arm of Version::parse. Each is a Zig-port leftover.
Verification of each claim
- Redundant store:
range: &Rangeis an immutable borrow andRangeisCopy; theBox::new(Query { range: *range, .. })already wrote the same bits. No interior mutability is involved. - Hyphen guard: read
length_of_leading_whitespace_asciiat src/bun_core/string/immutable.rs:2134 — it returns an index into its slice or the slice length, never more. Afteri += ...(&input[i..])we havei <= input.len(); the immediately precedingif i == input.len() { break }leavesi < input.len()as the only remaining case, so the removed conjunct is always true andinput[i]is in bounds. - Dead space-skip loop: control reaches the loop only when
match input[i]matchedb'-' | b'+'andihas not been mutated since (the early-break arm above exits the outer loop).matches!(input[i], b' ')is therefore false on entry, so the body never runs.part_start_iwas set before the loop and is whatTag::parsereads, so even the intent was preserved.
Security risks
None. Pure Rust, no unsafe touched, no new indexing sites — the one indexing site simplified is proven in-bounds by the line above it.
Level of scrutiny
Low. Each deletion is locally provable as identity from the surrounding lines; there is no input that can distinguish before from after. Existing coverage (test/cli/install/semver.test.ts, 28 tests / 1946 asserts) passes with the change and cargo clippy -p bun_semver is clean.
Other factors
The PR body includes a per-site proof matching what I verified. The "no new test" justification is sound under the repo rule: identity transformations have no distinguishing input, and the existing suite already exercises all three code paths.
|
Closing: this is a no-behavior-change cleanup (three statements that are provably no-ops on every input; see the per-site proof in the PR body and the bot review above), so there is no input that can produce a test which fails without the diff and passes with it. Under the repo's test requirement for The deletions are correct; a maintainer who wants them can reopen and merge directly. Otherwise the larger dead-code sweep in #32000 is the better vehicle for this class of change. |
There was a problem hiding this comment.
LGTM — three provably-dead statements removed with no behavior change.
What was reviewed:
List::and_range: the droppedtail.range = *rangere-stores the sameCopyvalue just written by the struct literal;range: &Rangeis immutable between the two.- Hyphen lookahead: verified
length_of_leading_whitespace_asciireturns at mostslice.len()(src/bun_core/string/immutable.rs:2134), so after the precedingi == input.len()break,i < input.len()is guaranteed and the dropped guard is always true. Version::parsetag arm:iis unchanged between thematch input[i]dispatch and the loop, soinput[i]is-/+and the space-skip loop body never executes;part_start_iwas set before it andTag::parsereads from there.
Extended reasoning...
Overview
Three deletions in the semver parser (src/semver/SemverQuery.rs, src/semver/Version.rs), each a leftover from the Zig port: a redundant field store immediately after construction, an always-true i < input.len() conjunct guarded by a preceding equality check, and a whitespace-skip loop whose condition is false on the first iteration because the match arm was entered on a non-space byte at the same index.
Security risks
None. Pure dead-code removal in a byte parser; no new indexing, no widened input acceptance, no allocation or FFI changes. The one indexing site touched (input[i] in the hyphen lookahead) remains guarded by the immediately preceding if i == input.len() { break }, and I confirmed length_of_leading_whitespace_ascii cannot return more than its slice length, so i cannot exceed input.len() at that point.
Level of scrutiny
Low. Each deletion is an identity transformation provable from local control flow — no cross-function invariants are relied on beyond the bounded return of length_of_leading_whitespace_ascii, which I read directly. There is no input that can distinguish before from after, so the absence of a new test is justified per the repo's own rule (a test that passes both with and without the change is worse than no test). The existing test/cli/install/semver.test.ts (28 tests, 1946 assertions) exercises all three sites and passes.
Other factors
cargo clippy -p bun_semver is clean. The bug-hunting system found nothing. The PR body's per-site proofs are correct on independent verification.
Three no-op statements left over from the Zig port, all provably unreachable or redundant. No behavior change.
List::and_range(SemverQuery.rs)range: &Rangeis an immutable reference andRangeisCopy, so the second store writes the same value it already holds.query::parsehyphen lookahead (SemverQuery.rs)length_of_leading_whitespace_asciireturns at most its slice's length, so after the additioni <= input.len(). The precedingi == input.len()check then leavesi < input.len()as the only remaining case, so the guard in the next condition is always true.Version::parsetag arm (Version.rs)This arm is entered via
match input[i]withiunchanged between dispatch and the loop, soinput[i]is-or+and the loop condition is false on the first iteration.Tag::parsereads frompart_start_i(set before the loop) regardless.Why no new test
These are identity transformations on the compiled function: the dropped store writes the value already present, and the dropped guards evaluate to the branch already taken on every input. There is no input that can distinguish before from after. Regression coverage is the existing
test/cli/install/semver.test.ts, which exercisesList::and_range(multi-comparator ranges), the hyphen-range lookahead, and version tag parsing.Verification