Add a BitVec model type - #318
Merged
Merged
Conversation
`thrust_models::model::BitVec<WIDTH, SIGNED>` models a value as a bit-vector, leaving the integer backend unchanged. A type opts in by declaring it as its `Model::Ty` and specifying its operations with trusted functions, e.g. a bit set backed by a `u64` or an integer wrapper with wrapping arithmetic. In annotations it supports wrapping `+`, `-`, `*`, unary `-`, the bitwise operators, `<<`, `>>`, and comparisons, with the signedness selecting the meaning of comparisons and `>>`. `BitVec::from_int` and `BitVec::to_int` convert from and to `Int`, encoded with `int_to_bv` and `ubv_to_int`/`sbv_to_int`, which both Z3 and PCSat accept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeM1mapvfoQGY5U2G2YLVP
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The type builder alone reads a `BitVec` model's generic arguments, into `rty::BitVecType`, and the annotation translator inspects the built type instead of re-reading them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeM1mapvfoQGY5U2G2YLVP
`Sort::BitVec` and `Term::IntToBitVec` name their fields instead of describing them in comments. The docs of `BitVec` only state its correspondence to SMT-LIB bit-vectors, and the README section is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeM1mapvfoQGY5U2G2YLVP
coeff-aij
added a commit
to coeff-aij/thrust
that referenced
this pull request
Oct 3, 2026
The fork's UInt sort and upstream's BitVec sort are both kept. BitVec::from_int takes any integer model, so that a usize (UInt) converts. The fork-only term walks (dedup, candidate_atoms, forall defaults) handle IntToBitVec; array repeat builds its element type from the fork's refined type builder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
coeff-aij
added a commit
to coeff-aij/thrust
that referenced
this pull request
Oct 3, 2026
&, |, ^, <<, >> and ! on integers are computed on bit-vectors of the operand type's width with int_to_bv and ubv_to_int / sbv_to_int (coord-e#318's terms); a shift masks its amount to the width. The result is exact for operands in the type's range, which Thrust's integers do not carry as a fact (int_bit_ops: xor_twice needs x <= u32::MAX). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
coeff-aij
added a commit
to coeff-aij/thrust
that referenced
this pull request
Oct 3, 2026
… bit operations through bit-vectors Size::align_to, Size::unsigned_int_max and Align::bytes of rustc_coroutine values.rs verify untrusted; bitset.rs states rustc's word layout with BitVec. The full ui suite fails only the five tests that fail on main d21f075 too (traits fold/fold_fn/map_fn/map_no_closure Unsat, closure_receiver_mut_model_byval timeout). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
thrust_models::model::BitVec<WIDTH, SIGNED>, a model type for SMT-LIB bit-vectors. The integer backend is unchanged: Rust integers are still modeled byInt.A type can declare
BitVecas itsModel::Tyand specify its operations with#[thrust::trusted]functions. Examples are au64-backed bit set (in the spirit ofDenseBitSet) and an integer wrapper.Changes
std.rs: addsmodel::BitVec<WIDTH, SIGNED>. In annotations, its operations translate to SMT-LIB functions:+,-,*bvadd,bvsub,bvmul-bvneg&,|,^,!bvand,bvor,bvxor,bvnot<<bvshl>>bvashr/bvlshr<,<=,>,>=bvslt, ... /bvult, ...BitVec::from_intint_to_bvBitVec::to_intsbv_to_int/ubv_to_intWhere a row lists two functions,
SIGNEDselects the first (signed) or the second (unsigned).chc:
Sort::BitVec { width };Term::IntToBitVec { width, term };rty: adds
Type::BitVec(BitVecType { width, signed }). Only the type builder readsBitVec's generic arguments; the annotation translator inspects the built type.Both Z3 5.0.0 and the pinned PCSat accept
int_to_bv,ubv_to_intandsbv_to_int.Tests
Each test has a pass/fail pair:
bit_vec_set: au64-backed bit set.bit_vec_wrapping: ani32wrapper, checking thati32::MAX + 1compares belowi32::MAX.cargo testpasses in full (390 UI tests), andcargo clippy -- -D warningsandcargo fmt --checkare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01AeM1mapvfoQGY5U2G2YLVP