Skip to content

SMT2: encode structs and multi-constructor ADTs as SMT-LIB datatypes#9072

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:strata/smt2-adt-struct-datatypes
Open

SMT2: encode structs and multi-constructor ADTs as SMT-LIB datatypes#9072
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:strata/smt2-adt-struct-datatypes

Conversation

@tautschnig

@tautschnig tautschnig commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Declare/parse struct and #adt_constructors (algebraic data) types as SMT-LIB datatypes keyed by tag/#index_type, and handle their construction, member access, and 'with' updates (parse_struct, convert_struct, convert_member, convert_with, find_symbols_rec).

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Jun 18, 2026
Copilot AI review requested due to automatic review settings June 18, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR extends the SMT2 backend to encode CBMC structs and multi-constructor ADTs as SMT-LIB datatypes, including parsing/printing constructors, member access, and with updates.

Changes:

  • Add multi-constructor ADT handling in struct parsing (parse_struct) and printing (convert_struct).
  • Encode member access and with updates for ADT-backed datatypes using (_ is ...) discriminator checks.
  • Extend symbol discovery to traverse additional type metadata (ID_C_index_type) and reuse datatype names by struct tag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/solvers/smt2/smt2_conv.cpp
Comment thread src/solvers/smt2/smt2_conv.cpp Outdated
Comment thread src/solvers/smt2/smt2_conv.cpp Outdated
Comment thread src/solvers/smt2/smt2_conv.cpp Outdated
Comment thread src/solvers/smt2/smt2_conv.cpp
Comment thread src/solvers/smt2/smt2_conv.cpp Outdated
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.27726% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.70%. Comparing base (962c191) to head (80356e0).

Files with missing lines Patch % Lines
src/solvers/smt2/smt2_conv.cpp 86.20% 28 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9072      +/-   ##
===========================================
+ Coverage    80.68%   80.70%   +0.01%     
===========================================
  Files         1714     1714              
  Lines       189522   189797     +275     
  Branches        73       73              
===========================================
+ Hits        152925   153175     +250     
- Misses       36597    36622      +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tautschnig tautschnig force-pushed the strata/smt2-adt-struct-datatypes branch 2 times, most recently from 7cb0c09 to 9d2fb95 Compare June 19, 2026 12:28
Declare/parse struct and #adt_constructors (algebraic data) types as SMT-LIB
datatypes keyed by tag/#index_type, and handle their construction, member
access, and 'with' updates (parse_struct, convert_struct, convert_member,
convert_with, find_symbols_rec).

The constructor tag is always emitted in its own sort (a bit-vector literal
via from_integer), both in the convert_struct ite-chain and in $tag member
access, so the comparisons are well-sorted. A convert_adt_constructor helper
centralises the constructor-application emission.

Because the front end gives no guarantees, the paths that cannot be encoded
soundly are guarded by invariants that fail loudly rather than emit
wrong-but-well-formed SMT: 'with' on $tag (which would change the
constructor) is rejected; constructors sharing a field name (which would
declare a selector twice) are rejected; and a member access on a
multi-constructor ADT must name a field with a declared selector.

Same-tag struct datatype reuse now compares component SMT sorts (array sizes
are irrelevant, element types and bit-widths are not), falling back to a
fresh datatype when they differ, so differently-typed same-tagged structs
are not conflated.

Add unit tests covering the multi-constructor ADT declaration, construction
(constant and non-constant tag), member and 'with' access, the rejection
invariants, and the same-tag reuse (merge vs. reject).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig force-pushed the strata/smt2-adt-struct-datatypes branch from 9d2fb95 to 80356e0 Compare June 23, 2026 13:34
@tautschnig tautschnig assigned kroening and unassigned tautschnig Jun 23, 2026
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.

3 participants