Architecture
Architecture overview¶
z3_mojo uses the same release-pinned generator structure as
cvc5_mojo. Hand-written
edits go into bindgen/ (not the generated .mojo files) so fixes survive
future Z3 upgrades.
Four layers¶
| Layer | Files | Role |
|---|---|---|
| Pythonic API | src/z3_mojo/pythonic.mojo, src/z3_mojo/theories.mojo, src/z3_mojo/callbacks.mojo |
Pythonic free functions, theory builders, operators, and callback helpers re-exported from z3_mojo. |
| Safe Handle & Context API | src/z3_mojo/api.mojo, src/z3_mojo/__init__.mojo, src/z3_mojo/enums.mojo |
Typed handle structs with RAII cleanup, 769 safe C-API bindings, safe callback traits (UserPropagator, ClauseHandler, ModelHandler), apn_mojo number conversions, and generated enums. |
| Low-level C API | src/z3_mojo/c.mojo, src/z3_mojo/_c/ffi.mojo, src/z3_mojo/_c/raw.mojo |
Public 1-to-1 C API (z3_mojo.c) over all 817 Z3_* functions; loads libz3 once per process, resolves every C function into a cached _DLCallable, converts C bool via UInt8, and raises Mojo errors from Z3_get_error_code. |
| Native Z3 | libz3.so / libz3.dylib |
The official MIT-licensed Z3 shared library pinned by SHA-256 in z3-version.toml. |
How generation works¶
bindgen/fetch.pydownloads the pinned Z3 binaries forlinux-64,linux-aarch64, andosx-arm64, plus the matching source archive, and verifies every SHA-256 hash intothird_party/.bindgen/c_headers.pyparses all nine headers included byz3.h, extracts Z3'sdef_API/extra_APIparameter direction and array-length annotations, and checks every parsed prototype againstz3.hby compiling a generated C file withcc -fsyntax-only -Werror.bindgen/c_library.pyinspectslibz3across all three platforms withllvm-nm,llvm-readelf, andllvm-objdump(so Linux can inspect macOS Mach-O binaries without running them) and checks that every declared symbol is exported everywhere.bindgen/enums.pycompiles and runs a small C program againstz3.hthat prints every enumerator's exact value, then writessrc/z3_mojo/enums.mojo.bindgen/snapshot.pywritesapi/z3-api.jsonand enforces the completeness gate (pixi run check-api): every handle needs an ownership rule, every C function must be accounted for (auto,manual,lifecycle, or listed inbindgen/overrides.toml), and stale overrides fail the build.bindgen/gen_raw.pychecks scalar,bool, enum, and pointer sizes and signedness with_Static_assert, then writessrc/z3_mojo/_c/raw.mojo.bindgen/gen_api.pyandbindgen/gen_docs.pygeneratesrc/z3_mojo/api.mojo,src/z3_mojo/__init__.mojo, and the reference pages underdocs/content/reference/.
Direct access to the low-level C API¶
All 817 C functions, 29 raw handle structs, 10 enums, and FFI helpers (including
the 8 raw-only functions such as Z3_mk_context_rc, Z3_inc_ref/Z3_dec_ref,
Z3_set_proof_check_callback, and raw Z3_fixedpoint_* callbacks) are exposed
publicly via from z3_mojo.c import c_api, .... See the
Low-level C API guide and
Low-Level C API Reference.