Skip to content

Commit e4d7155

Browse files
committed
Merge branch 'master' into skip-eclasses
2 parents 0a24083 + 80958e3 commit e4d7155

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/egraph.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,10 @@ impl<L: Language, M: Metadata<L>> EGraph<L, M> {
447447

448448
/// Does very little since you're in parent-pointers mode.
449449
#[cfg(feature = "parent-pointers")]
450-
pub fn rebuild(&mut self) {
450+
pub fn rebuild(&mut self) -> usize {
451451
info!("Skipping rebuild because we have parent pointers");
452452
self.rebuild_classes();
453+
0
453454
}
454455

455456
/// Restores the egraph invariants of congruence and enode uniqueness.
@@ -483,7 +484,7 @@ impl<L: Language, M: Metadata<L>> EGraph<L, M> {
483484
/// assert_eq!(egraph.find(ax), egraph.find(ay));
484485
/// ```
485486
#[cfg(not(feature = "parent-pointers"))]
486-
pub fn rebuild(&mut self) {
487+
pub fn rebuild(&mut self) -> usize {
487488
self.unions_since_rebuild = 0;
488489

489490
let old_hc_size = self.memo.len();
@@ -496,7 +497,7 @@ impl<L: Language, M: Metadata<L>> EGraph<L, M> {
496497
loop {
497498
let u = self.rebuild_once();
498499
n_unions += u;
499-
n_rebuilds += 1;
500+
n_rebuilds += self.number_of_classes();
500501
if u == 0 {
501502
break;
502503
}
@@ -522,6 +523,8 @@ impl<L: Language, M: Metadata<L>> EGraph<L, M> {
522523
n_unions,
523524
trimmed_nodes,
524525
);
526+
527+
n_rebuilds
525528
}
526529

527530
/// Unions two eclasses given their ids.

src/run.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ pub struct Iteration<IterData> {
246246
pub total_time: f64,
247247
/// The user provided annotation for this iteration
248248
pub data: IterData,
249+
/// The number of rebuild iterations done after this iteration completed.
250+
pub n_rebuilds: usize,
249251
}
250252

251253
type RunnerResult<T> = std::result::Result<T, StopReason>;
@@ -316,6 +318,28 @@ where
316318
self
317319
}
318320

321+
#[rustfmt::skip]
322+
/// Prints some information about a runners run.
323+
pub fn print_report(&self) {
324+
let search_time: f64 = self.iterations.iter().map(|i| i.search_time).sum();
325+
let apply_time: f64 = self.iterations.iter().map(|i| i.apply_time).sum();
326+
let rebuild_time: f64 = self.iterations.iter().map(|i| i.rebuild_time).sum();
327+
let total_time: f64 = self.iterations.iter().map(|i| i.total_time).sum();
328+
329+
let iters = self.iterations.len();
330+
let rebuilds: usize = self.iterations.iter().map(|i| i.n_rebuilds).sum();
331+
332+
println!("Runner report");
333+
println!("=============");
334+
println!(" Stop reason: {:?}", self.stop_reason.as_ref().unwrap());
335+
println!(" Iterations: {}", iters);
336+
println!(" Rebuilds: {}, {:.2} per iter", rebuilds, (rebuilds as f64) / (iters as f64));
337+
println!(" Total time: {}", total_time);
338+
println!(" Search: ({:.2}) {}", search_time / total_time, search_time);
339+
println!(" Apply: ({:.2}) {}", apply_time / total_time, apply_time);
340+
println!(" Rebuild: ({:.2}) {}", rebuild_time / total_time, rebuild_time);
341+
}
342+
319343
fn run_one(&mut self, rules: &[Rewrite<L, M>]) -> RunnerResult<()> {
320344
assert!(self.stop_reason.is_none());
321345

@@ -369,7 +393,7 @@ where
369393
info!("Apply time: {}", apply_time);
370394

371395
let rebuild_time = Instant::now();
372-
self.egraph.rebuild();
396+
let n_rebuilds = self.egraph.rebuild();
373397

374398
let rebuild_time = rebuild_time.elapsed().as_secs_f64();
375399
info!("Rebuild time: {}", rebuild_time);
@@ -388,6 +412,7 @@ where
388412
search_time,
389413
apply_time,
390414
rebuild_time,
415+
n_rebuilds,
391416
data: IterData::make(&self),
392417
total_time: start_time.elapsed().as_secs_f64(),
393418
});

src/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ impl<T> Reporter<T> {
5858
}
5959

6060
#[cfg(not(feature = "reports"))]
61-
pub fn report<R>(self, _to_report: impl FnOnce(&T) -> &R) -> T {
61+
pub fn report<R>(self, to_report: impl FnOnce(&T) -> &R) -> T {
6262
if let Some(dir) = var::<PathBuf>("EGG_BENCH_DIR") {
6363
eprintln!(
6464
"EGG_BENCH_DIR is set to '{:?}', but the 'reports' feature is not enabled",
6565
dir
6666
);
6767
}
68+
to_report(&self.result);
6869
self.result
6970
}
7071

@@ -164,7 +165,6 @@ where
164165
let id = egraph.find(*self.roots.last().unwrap());
165166

166167
let (cost, best) = Extractor::new(egraph, AstSize).find_best(id);
167-
println!("Stop reason: {:?}", self.stop_reason.as_ref().unwrap());
168168
println!("End ({}): {}", cost, best.pretty(80));
169169

170170
for (i, goal) in goals.iter().enumerate() {
@@ -223,8 +223,8 @@ macro_rules! test_fn {
223223

224224
let runner = $crate::test::run(name, || {
225225
$runner.with_expr(&start).run(&rules)
226-
})
227-
.report(|r| &r.iterations);
226+
}).report(|r| &r.iterations);
227+
runner.print_report();
228228

229229
let goals = &[$(
230230
$goal.parse().unwrap()

0 commit comments

Comments
 (0)