Skip to content

Commit bf46117

Browse files
committed
Snapshot
1 parent ffd3543 commit bf46117

File tree

9 files changed

+404
-239
lines changed

9 files changed

+404
-239
lines changed

Diff for: src/main.rs

+24-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use env_logger::{Builder, Env, Target};
1414
use itertools::Itertools;
1515
use walkdir::WalkDir;
1616

17-
use crate::pipeline::{unify, Input};
17+
use crate::pipeline::{unify, Input, Stats};
1818

1919
mod pipeline;
2020

@@ -32,8 +32,8 @@ fn visit<P: AsRef<Path>>(dir: P, mut cb: impl FnMut(usize, &Path)) -> io::Result
3232

3333
#[derive(Debug)]
3434
enum CosetteResult {
35-
Provable,
36-
NotProvable,
35+
Provable(Stats),
36+
NotProvable(Stats),
3737
ParseErr(serde_json::Error),
3838
Panic(Box<dyn Any + Send>),
3939
}
@@ -51,21 +51,21 @@ fn main() -> io::Result<()> {
5151
let mut buf_reader = BufReader::new(file);
5252
let mut contents = String::new();
5353
println!("#{}: {}", i, path.to_string_lossy().as_ref());
54-
let old_time = Instant::now();
54+
let start_time = Instant::now();
5555
buf_reader.read_to_string(&mut contents).unwrap();
5656
let result =
5757
std::panic::catch_unwind(|| match serde_json::from_str::<Input>(&contents) {
5858
Ok(rel) => {
59-
let provable = unify(rel);
59+
let (provable, case_stats) = unify(rel);
6060
println!(
6161
"Equivalence is {}provable for {}",
6262
if provable { "" } else { "not " },
6363
path.file_name().unwrap().to_str().unwrap(),
6464
);
6565
if provable {
66-
Provable
66+
Provable(case_stats)
6767
} else {
68-
NotProvable
68+
NotProvable(case_stats)
6969
}
7070
},
7171
Err(e) => {
@@ -80,20 +80,27 @@ fn main() -> io::Result<()> {
8080
Panic(e)
8181
},
8282
};
83-
let duration = Instant::now() - old_time;
84-
let mut result_file = File::create(path.with_extension("res")).unwrap();
85-
write!(
86-
result_file,
87-
"{}\n{}",
88-
matches!(result, CosetteResult::Provable),
89-
duration.as_secs_f32()
90-
)
91-
.unwrap();
83+
let result_file = File::create(path.with_extension("result")).unwrap();
84+
let case_stats = match &result {
85+
Provable(stats) | NotProvable(stats) => {
86+
let mut stats = stats.clone();
87+
stats.provable = matches!(result, Provable(_));
88+
stats.total_duration = start_time.elapsed();
89+
stats
90+
},
91+
_ => {
92+
let mut stats = Stats::default();
93+
stats.panicked = true;
94+
stats.total_duration = start_time.elapsed();
95+
stats
96+
},
97+
};
98+
serde_json::to_writer(result_file, &case_stats).unwrap();
9299
stats.insert(path.to_string_lossy().to_string(), result);
93100
})?;
94101
}
95102
println!("\n\nSTATISTICS");
96-
let (a, b): (Vec<_>, _) = stats.values().partition(|v| matches!(v, CosetteResult::Provable));
103+
let (a, b): (Vec<_>, _) = stats.values().partition(|v| matches!(v, CosetteResult::Provable(_)));
97104
let (al, bl) = (a.len(), b.len());
98105
for (name, result) in stats {
99106
println!("{}\t{:?}", name, result);

Diff for: src/pipeline.rs

+43-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::cell::RefCell;
2-
use std::collections::HashMap;
31
use std::rc::Rc;
2+
use std::time::{Duration, Instant};
43

54
use imbl::vector;
65
use serde::{Deserialize, Serialize};
@@ -24,60 +23,84 @@ pub mod unify;
2423
#[derive(Serialize, Deserialize)]
2524
pub struct Input {
2625
schemas: Vec<Schema>,
27-
queries: (relation::Relation, relation::Relation),
26+
pub queries: (relation::Relation, relation::Relation),
2827
#[serde(default)]
2928
help: (String, String),
3029
}
3130

32-
pub fn unify(Input { schemas, queries: (rel1, rel2), help }: Input) -> bool {
31+
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
32+
pub struct Stats {
33+
pub provable: bool,
34+
pub panicked: bool,
35+
pub complete_fragment: bool,
36+
pub equiv_class_duration: Duration,
37+
pub equiv_class_timed_out: bool,
38+
pub smt_duration: Duration,
39+
pub smt_timed_out: bool,
40+
pub nontrivial_perms: bool,
41+
pub translate_duration: Duration,
42+
pub normal_duration: Duration,
43+
pub stable_duration: Duration,
44+
pub unify_duration: Duration,
45+
pub total_duration: Duration,
46+
}
47+
48+
pub fn unify(Input { schemas, queries: (rel1, rel2), help }: Input) -> (bool, Stats) {
49+
let mut stats = Stats::default();
3350
let subst = vector![];
3451
let env = relation::Env(&schemas, &subst, 0);
3552
log::info!("Schemas:\n{:?}", schemas);
3653
log::info!("Input:\n{}\n{}", help.0, help.1);
54+
stats.complete_fragment = rel1.complete() && rel2.complete();
3755
if rel1 == rel2 {
3856
println!("Trivially true!");
39-
return true;
57+
return (true, stats);
4058
}
59+
let syn_start = Instant::now();
4160
let rel1 = env.eval(rel1);
4261
let rel2 = env.eval(rel2);
43-
if rel1 == rel2 {
44-
return true;
45-
}
62+
stats.translate_duration = syn_start.elapsed();
4663
log::info!("Syntax left:\n{}", rel1);
4764
log::info!("Syntax right:\n{}", rel2);
65+
if rel1 == rel2 {
66+
return (true, stats);
67+
}
4868
let nom_env = &vector![];
4969
let eval_nom = |rel: syntax::Relation| -> normal::Relation {
5070
let rel = (&partial::Env::default()).eval(rel);
5171
nom_env.eval(rel)
5272
};
73+
let norm_start = Instant::now();
5374
let rel1 = eval_nom(rel1);
5475
let rel2 = eval_nom(rel2);
76+
stats.normal_duration = norm_start.elapsed();
5577
log::info!("Normal left:\n{}", rel1);
5678
log::info!("Normal right:\n{}", rel2);
5779
if rel1 == rel2 {
58-
return true;
80+
return (true, stats);
5981
}
6082
let config = Config::new();
6183
let z3_ctx = &Context::new(&config);
62-
let ctx = Rc::new(Ctx::new(Solver::new(z3_ctx)));
63-
let h_ops = Rc::new(RefCell::new(HashMap::new()));
64-
let agg_ops = Rc::new(RefCell::new(HashMap::new()));
65-
let rel_h_ops = Rc::new(RefCell::new(HashMap::new()));
84+
let ctx = Rc::new(Ctx::new_with_stats(Solver::new(z3_ctx), stats));
85+
let z3_env = Z3Env::empty(ctx.clone());
6686
let eval_stb = |nom: normal::Relation| -> normal::Relation {
67-
let env = &stable::Env(vector![], {
68-
let subst = vector![];
69-
Z3Env(ctx.clone(), subst, h_ops.clone(), agg_ops.clone(), rel_h_ops.clone())
70-
});
87+
let env = &stable::Env(vector![], z3_env.clone());
7188
let stb = env.eval(nom);
7289
nom_env.eval(stb)
7390
};
91+
let stb_start = Instant::now();
7492
let rel1 = eval_stb(rel1);
7593
let rel2 = eval_stb(rel2);
94+
ctx.stats.borrow_mut().stable_duration = stb_start.elapsed();
7695
log::info!("Stable left:\n{}", rel1);
7796
log::info!("Stable right:\n{}", rel2);
7897
if rel1 == rel2 {
79-
return true;
98+
return (true, ctx.stats.borrow().clone());
8099
}
81-
let env = UnifyEnv(ctx, vector![], vector![]);
82-
env.unify(&rel1, &rel2)
100+
let env = UnifyEnv(ctx.clone(), vector![], vector![]);
101+
let unify_start = Instant::now();
102+
let res = env.unify(&rel1, &rel2);
103+
ctx.stats.borrow_mut().unify_duration = unify_start.elapsed();
104+
let stats = ctx.stats.borrow().clone();
105+
(res, stats)
83106
}

0 commit comments

Comments
 (0)