z3tracer/
lib.rs

1// Copyright (c) Facebook, Inc. and its affiliates
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! This crate provides an experimental parser and analyzer for detailed log files produced by Z3.
5//!
6//! To obtain a file `z3.log`, pass the options `trace=true` and `proof=true` on the
7//! command line of Z3 (for instance, `z3 trace=true proof=true file.smt2`). For large problems, you may
8//! choose to limit the size of the log file by interrupting `z3` with `^C` or by setting
9//! a shorter timeout. Passing only `trace=true` is also possible but it will prevent any
10//! dependency analysis (see below).
11//!
12//! While parsing the logs, a "model" of the logs is constructed to record most operations, as
13//! well as the syntactic terms under each `#NUM` notation:
14//!
15//! ```
16//! # use std::str::FromStr;
17//! # use std::collections::BTreeMap;
18//! use z3tracer::{Model, syntax::{Ident, Term}};
19//! # fn main() -> z3tracer::error::RawResult<()> {
20//! let mut model = Model::default();
21//! let input = br#"
22//! [mk-app] #0 a
23//! [mk-app] #1 + #0 #0
24//! [eof]
25//! "#;
26//! model.process(None, &input[1..])?;
27//! assert_eq!(model.terms().len(), 2);
28//! assert!(matches!(model.term(&Ident::from_str("#1")?)?, Term::App { .. }));
29//! assert_eq!(model.id_to_sexp(&BTreeMap::new(), &Ident::from_str("#1").unwrap()).unwrap(), "(+ a a)");
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! Besides, the library will attempt to reconstruct the following information:
35//!
36//! * Quantifier Instantiations (QIs), that is, which quantified formulas were instantiated by Z3 and why;
37//!
38//! * The successive backtracking levels during SMT solving;
39//!
40//! * SAT/SMT conflicts and their causal dependencies in terms of QIs;
41//! ![Conflicts](https://github.com/facebookincubator/smt2utils/blob/master/z3tracer/img/z3_tracer_1.jpg?raw=true)
42//!
43//! * Causal dependencies between QIs.
44//! ![Causal dependencies between QIs](https://github.com/facebookincubator/smt2utils/blob/master/z3tracer/img/z3_tracer_2.jpg?raw=true)
45//!
46//! A tool `z3tracer` based on the library is provided to process a log file `z3.log` from the
47//! command line and generate charts.
48//!
49//! See also in the
50//! [repository](https://github.com/facebookincubator/smt2utils/tree/master/z3tracer/notebooks)
51//! for additional examples using Jupyter notebooks.
52//!
53//! Currently, this library only supports Z3 v4.8.9.
54//!
55//! More information about Z3 tracing logs can be found in the documentation of the
56//! project [Axiom Profiler](https://github.com/viperproject/axiom-profiler).
57
58#![forbid(unsafe_code)]
59
60/// Error management.
61pub mod error;
62/// Tokenization of Z3 logs.
63pub mod lexer;
64/// Main analyzer module.
65pub mod model;
66/// Parsing of Z3 logs.
67pub mod parser;
68/// Terms and data structures found in Z3 logs.
69pub mod syntax;
70
71/// *Experimental* helper functions to generate reports.
72#[cfg(feature = "report")]
73pub mod report;
74
75pub use error::{Error, Result};
76pub use model::{Model, ModelConfig};