Skip to content

Fix a bug in ChunkedBitSet::subtract#155381

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
nnethercote:fix-ChunkedBitSet-subtract
Apr 28, 2026
Merged

Fix a bug in ChunkedBitSet::subtract#155381
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
nnethercote:fix-ChunkedBitSet-subtract

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

@nnethercote nnethercote commented Apr 16, 2026

An operator precedence bug means an incorrect mask is used in ChunkedBitSet::subtract. Details in individual commits.

r? @dingxiangfei2009

It results in `b64` having many fewer bits set than it should.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
It does a masking operation but the mask is computed incorrectly due to
operator precedence. The mask is of the form `1 << N - 1` but it
should be `(1 << N) - 1` because `-` binds tighter than `1 << N`.

This commit fixes the problem, not by adjusting the precedence, but by
instead using the existing `clear_excess_bits_in_final_word`, which is
consistent with other similar operations.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2026
@Zalathar
Copy link
Copy Markdown
Member

Precautionary perf run:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 26, 2026
@Zalathar
Copy link
Copy Markdown
Member

Looks good, r=me if perf is unsurprising.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

☀️ Try build successful (CI)
Build commit: 89be914 (89be9143641499c10eebadcfd57b3ecb82e9ae61, parent: 68ffae46b581747074413e4242ab0c6ecc4db4a9)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (89be914): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary 2.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.1% [6.1%, 6.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.9% [-1.9%, -1.9%] 1
All ❌✅ (primary) - - 0

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 488.457s -> 488.608s (0.03%)
Artifact size: 393.89 MiB -> 393.91 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 26, 2026
@Zalathar
Copy link
Copy Markdown
Member

@bors rollup=maybe

@nnethercote
Copy link
Copy Markdown
Contributor Author

@bors r=Zalathar

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 28, 2026

📌 Commit 3f9dbf2 has been approved by Zalathar

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2026
@Zalathar
Copy link
Copy Markdown
Member

r? me

@rustbot rustbot assigned Zalathar and unassigned dingxiangfei2009 Apr 28, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 28, 2026
…ract, r=Zalathar

Fix a bug in `ChunkedBitSet::subtract`

An operator precedence bug means an incorrect mask is used in `ChunkedBitSet::subtract`. Details in individual commits.

r? @dingxiangfei2009
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 28, 2026
…ract, r=Zalathar

Fix a bug in `ChunkedBitSet::subtract`

An operator precedence bug means an incorrect mask is used in `ChunkedBitSet::subtract`. Details in individual commits.

r? @dingxiangfei2009
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
Rollup of 9 pull requests

Successful merges:

 - #155381 (Fix a bug in `ChunkedBitSet::subtract`)
 - #155847 (Don't reload length in String::push)
 - #155858 (`slice::join`: borrow only once during length calc)
 - #155879 (enable pipe tests in Miri)
 - #155905 (Update LLVM to 22.1.4 (again))
 - #155247 ([AIX] update linker default to bcdtors)
 - #155812 ([codex] tests: mark migrated UI tests as check-pass)
 - #155854 (Rename the diagnostic item for `std::sync::mpsc::Receiver`)
 - #155882 (Add regression test for #101363)
@rust-bors rust-bors Bot merged commit 4c59213 into rust-lang:main Apr 28, 2026
12 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 28, 2026
rust-timer added a commit that referenced this pull request Apr 28, 2026
Rollup merge of #155381 - nnethercote:fix-ChunkedBitSet-subtract, r=Zalathar

Fix a bug in `ChunkedBitSet::subtract`

An operator precedence bug means an incorrect mask is used in `ChunkedBitSet::subtract`. Details in individual commits.

r? @dingxiangfei2009
@nnethercote nnethercote deleted the fix-ChunkedBitSet-subtract branch April 28, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants