Skip to main content

dive_runtime/
run.rs

1//! The run host's `TLCGet("config")` and live counters around the search,
2//! shared by every engine.
3
4use dive_eval::{Counter, RunConfig};
5use dive_stdlib::host::RunHost;
6
7use crate::CheckOptions;
8
9/// `TLCGet("config")` (`AbstractChecker.createConfig`). The worker count is
10/// the logical one, 1, by default and the requested one under
11/// `--compat=tlc`, as TLC reports `-workers`; the install location
12/// is dive's executable.
13#[must_use]
14pub fn run_config(opts: &CheckOptions, deadlock: bool) -> RunConfig {
15    #[allow(clippy::cast_possible_wrap, reason = "Java's long: same bits")]
16    let fingerprint = dive_value::fp64::POLYS
17        .get(opts.fp_index)
18        .copied()
19        .unwrap_or(0) as i64;
20    RunConfig {
21        deadlock,
22        workers: match opts.profile {
23            dive_eval::Profile::Tlc => i64::try_from(opts.workers).unwrap_or(i64::MAX),
24            dive_eval::Profile::Dive => 1,
25        },
26        seed: opts.seed,
27        fingerprint,
28        install: std::env::current_exe()
29            .map(|p| p.display().to_string())
30            .unwrap_or_default(),
31    }
32}
33
34/// The counters while TLC checks assumptions: no state yet, diameter 1
35/// (measured on the pinned TLC, fixture `TgAssume`).
36pub fn startup_counters(host: &RunHost) {
37    for c in [
38        Counter::Generated,
39        Counter::Distinct,
40        Counter::Queue,
41        Counter::Initial,
42    ] {
43        host.set_counter(c, Some(0));
44    }
45    host.set_counter(Counter::Diameter, Some(1));
46}
47
48/// During the search the live counters are not provided: reading one is
49/// refused rather than answered with a count TLC may not report at that
50/// point.
51pub fn search_counters(host: &RunHost) {
52    for c in [
53        Counter::Generated,
54        Counter::Distinct,
55        Counter::Queue,
56        Counter::Initial,
57        Counter::Diameter,
58        Counter::DurationSecs,
59    ] {
60        host.set_counter(c, None);
61    }
62}