1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
use anyhow::anyhow;
use itertools::Itertools;
use move_command_line_common::env::{read_bool_env_var, read_env_var};
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::process::Command;
const DEFAULT_BOOGIE_FLAGS: &[&str] = &[
"-doModSetAnalysis",
"-printVerifiedProceduresCount:0",
"-printModel:1",
"-enhancedErrorMessages:1",
"-monomorphize",
];
const MIN_BOOGIE_VERSION: &str = "2.9.0";
const MIN_Z3_VERSION: &str = "4.8.9";
const EXPECTED_CVC4_VERSION: &str = "aac53f51";
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum VectorTheory {
BoogieArray,
BoogieArrayIntern,
SmtArray,
SmtArrayExt,
SmtSeq,
}
impl VectorTheory {
pub fn is_extensional(&self) -> bool {
matches!(
self,
VectorTheory::BoogieArrayIntern | VectorTheory::SmtArrayExt | VectorTheory::SmtSeq
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct BoogieOptions {
pub boogie_exe: String,
pub use_exp_boogie: bool,
pub z3_exe: String,
pub use_cvc4: bool,
pub cvc4_exe: String,
pub debug_trace: bool,
pub boogie_flags: Vec<String>,
pub use_array_theory: bool,
pub generate_smt: bool,
pub native_equality: bool,
pub type_requires: String,
pub stratification_depth: usize,
pub aggressive_func_inline: String,
pub func_inline: String,
pub serialize_bound: usize,
pub bench_repeat: usize,
pub vector_using_sequences: bool,
pub random_seed: usize,
pub proc_cores: usize,
pub vc_timeout: usize,
pub keep_artifacts: bool,
pub eager_threshold: usize,
pub lazy_threshold: usize,
pub stable_test_output: bool,
pub num_instances: usize,
pub sequential_task: bool,
pub hard_timeout_secs: u64,
pub vector_theory: VectorTheory,
pub z3_trace_file: Option<String>,
}
impl Default for BoogieOptions {
fn default() -> Self {
Self {
bench_repeat: 1,
boogie_exe: read_env_var("BOOGIE_EXE"),
use_exp_boogie: false,
z3_exe: read_env_var("Z3_EXE"),
use_cvc4: false,
cvc4_exe: read_env_var("CVC4_EXE"),
boogie_flags: vec![],
debug_trace: false,
use_array_theory: false,
generate_smt: false,
native_equality: false,
type_requires: "free requires".to_owned(),
stratification_depth: 6,
aggressive_func_inline: "".to_owned(),
func_inline: "{:inline}".to_owned(),
serialize_bound: 0,
vector_using_sequences: false,
random_seed: 1,
proc_cores: 4,
vc_timeout: 40,
keep_artifacts: false,
eager_threshold: 100,
lazy_threshold: 100,
stable_test_output: false,
num_instances: 1,
sequential_task: false,
hard_timeout_secs: 0,
vector_theory: VectorTheory::BoogieArray,
z3_trace_file: None,
}
}
}
impl BoogieOptions {
pub fn derive_options(&mut self) {
use VectorTheory::*;
self.native_equality = self.vector_theory.is_extensional();
if matches!(self.vector_theory, SmtArray | SmtArrayExt) {
self.use_array_theory = true;
}
}
pub fn get_boogie_command(&self, boogie_file: &str) -> anyhow::Result<Vec<String>> {
let mut result = if self.use_exp_boogie {
vec![read_env_var("EXP_BOOGIE_EXE")]
} else {
vec![self.boogie_exe.clone()]
};
if result.iter().all(|path| path.is_empty()) {
anyhow::bail!("No boogie executable set. Please set BOOGIE_EXE");
}
let mut add = |sl: &[&str]| result.extend(sl.iter().map(|s| (*s).to_string()));
add(DEFAULT_BOOGIE_FLAGS);
if self.use_cvc4 {
add(&[
"-proverOpt:SOLVER=cvc4",
&format!("-proverOpt:PROVER_PATH={}", &self.cvc4_exe),
]);
} else {
add(&[&format!("-proverOpt:PROVER_PATH={}", &self.z3_exe)]);
}
if self.use_array_theory {
add(&["-useArrayTheory"]);
if matches!(self.vector_theory, VectorTheory::SmtArray) {
add(&["/proverOpt:O:smt.array.extensional=false"])
}
} else {
add(&[&format!(
"-proverOpt:O:smt.QI.EAGER_THRESHOLD={}",
self.eager_threshold
)]);
add(&[&format!(
"-proverOpt:O:smt.QI.LAZY_THRESHOLD={}",
self.lazy_threshold
)]);
}
add(&[&format!(
"-vcsCores:{}",
if self.stable_test_output {
1
} else {
self.proc_cores
}
)]);
if let Some(file) = &self.z3_trace_file {
add(&[
"-proverOpt:O:trace=true",
&format!("-proverOpt:O:trace_file_name={}", file),
]);
}
if self.generate_smt {
add(&["-proverLog:@PROC@.smt"]);
}
for f in &self.boogie_flags {
add(&[f.as_str()]);
}
add(&[boogie_file]);
Ok(result)
}
pub fn get_boogie_log_file(&self, boogie_file: &str) -> String {
format!("{}.log", boogie_file)
}
pub fn adjust_timeout(&self, time: usize) -> usize {
if read_bool_env_var("MVP_TEST_ON_CI") {
usize::saturating_add(time, time)
} else {
time
}
}
pub fn check_tool_versions(&self) -> anyhow::Result<()> {
if !self.boogie_exe.is_empty() {
let version = Self::get_version(
"boogie",
&self.boogie_exe,
&["-version"],
r"version ([0-9.]*)",
)?;
Self::check_version_is_greater("boogie", &version, MIN_BOOGIE_VERSION)?;
}
if !self.z3_exe.is_empty() && !self.use_cvc4 {
let version =
Self::get_version("z3", &self.z3_exe, &["--version"], r"version ([0-9.]*)")?;
Self::check_version_is_greater("z3", &version, MIN_Z3_VERSION)?;
}
if !self.cvc4_exe.is_empty() && self.use_cvc4 {
let version = Self::get_version(
"cvc4",
&self.cvc4_exe,
&["--version"],
r"git master ([0-9a-f]*)",
)?;
if version != EXPECTED_CVC4_VERSION {
return Err(anyhow!(
"expected git hash {} but found {} for `cvc4`",
EXPECTED_CVC4_VERSION,
version
));
}
}
Ok(())
}
fn get_version(tool: &str, prog: &str, args: &[&str], regex: &str) -> anyhow::Result<String> {
let out = match Command::new(prog).args(args).output() {
Ok(out) => String::from_utf8_lossy(&out.stdout).to_string(),
Err(msg) => {
return Err(anyhow!(
"cannot execute `{}` to obtain version of `{}`: {}",
prog,
tool,
msg.to_string()
))
}
};
if let Some(cap) = Regex::new(regex).unwrap().captures(&out) {
Ok(cap[1].to_string())
} else {
Err(anyhow!("cannot extract version from `{}`", prog))
}
}
fn check_version_is_greater(tool: &str, given: &str, expected: &str) -> anyhow::Result<()> {
let given_parts = given.split('.').collect_vec();
let expected_parts = expected.split('.').collect_vec();
if given_parts.len() < expected_parts.len() {
return Err(anyhow!(
"version strings {} and {} for `{}` cannot be compared",
given,
expected,
tool,
));
}
for (g, e) in given_parts.into_iter().zip(expected_parts.into_iter()) {
let gn = g.parse::<usize>()?;
let en = e.parse::<usize>()?;
if gn < en {
return Err(anyhow!(
"expected at least version {} but found {} for `{}`",
expected,
given,
tool
));
}
}
Ok(())
}
}