Skip to content

Add a BitVec model type - #318

Merged
coord-e merged 3 commits into
mainfrom
claude/integer-backend-bitvector-u6x8xp
Oct 3, 2026
Merged

coord-e merged 3 commits into
mainfrom
claude/integer-backend-bitvector-u6x8xp

Conversation

@coord-e

@coord-e coord-e commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

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 by Int.

A type can declare BitVec as its Model::Ty and specify its operations with #[thrust::trusted] functions. Examples are a u64-backed bit set (in the spirit of DenseBitSet) and an integer wrapper.

impl thrust_models::Model for BitSet64 {
    type Ty = BitVec<64, false>;
}

#[thrust::trusted]
#[thrust_macros::requires(i < 64)]
#[thrust_macros::ensures(!self == *self | (BitVec::from_int(1) << BitVec::from_int(i)))]
fn insert(&mut self, i: usize) { ... }

Changes

  • std.rs: adds model::BitVec<WIDTH, SIGNED>. In annotations, its operations translate to SMT-LIB functions:

    Annotation SMT-LIB
    +, -, * bvadd, bvsub, bvmul
    unary - bvneg
    &, |, ^, ! bvand, bvor, bvxor, bvnot
    << bvshl
    >> bvashr / bvlshr
    <, <=, >, >= bvslt, ... / bvult, ...
    BitVec::from_int int_to_bv
    BitVec::to_int sbv_to_int / ubv_to_int

    Where a row lists two functions, SIGNED selects the first (signed) or the second (unsigned).

  • chc:

    • adds Sort::BitVec { width };
    • adds Term::IntToBitVec { width, term };
    • adds the bit-vector functions.
  • rty: adds Type::BitVec(BitVecType { width, signed }). Only the type builder reads BitVec'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_int and sbv_to_int.

Tests

Each test has a pass/fail pair:

  • bit_vec_set: a u64-backed bit set.
  • bit_vec_wrapping: an i32 wrapper, checking that i32::MAX + 1 compares below i32::MAX.

cargo test passes in full (390 UI tests), and cargo clippy -- -D warnings and cargo fmt --check are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AeM1mapvfoQGY5U2G2YLVP

`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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T02:13:21.267209Z 97bd477 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

claude added 2 commits October 3, 2026 02:05
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
@coord-e
coord-e merged commit 67a1cc4 into main Oct 3, 2026
6 checks passed
@coord-e
coord-e deleted the claude/integer-backend-bitvector-u6x8xp branch October 3, 2026 02:13
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants