Skip to content

Commit

Permalink
Add Debug implementations for all public types (egraphs-good#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosekunkel authored Jun 15, 2021
1 parent 5f18284 commit 1750e3b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ assert_eq!(best, "10".parse().unwrap());
```
**/
#[derive(Debug)]
pub struct Extractor<'a, CF: CostFunction<L>, L: Language, N: Analysis<L>> {
cost_function: CF,
costs: HashMap<Id, (CF::Cost, L)>,
Expand Down Expand Up @@ -145,6 +146,7 @@ assert_eq!(AstSize.cost_rec(&e), 4);
```
**/
#[derive(Debug)]
pub struct AstSize;
impl<L: Language> CostFunction<L> for AstSize {
type Cost = usize;
Expand All @@ -165,6 +167,7 @@ assert_eq!(AstDepth.cost_rec(&e), 2);
```
**/
#[derive(Debug)]
pub struct AstDepth;
impl<L: Language> CostFunction<L> for AstDepth {
type Cost = usize;
Expand Down
1 change: 1 addition & 0 deletions src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ where
/// This condition adds its two [`Applier`]s to the egraph and passes
/// if and only if they are equivalent (in the same eclass).
///
#[derive(Debug)]
pub struct ConditionEqual<A1, A2>(pub A1, pub A2);

impl<L: FromOp> ConditionEqual<Pattern<L>, Pattern<L>> {
Expand Down
41 changes: 41 additions & 0 deletions src/run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{self, Debug, Formatter};

use log::*;

use crate::*;
Expand Down Expand Up @@ -168,6 +170,42 @@ where
}
}

impl<L, N, IterData> Debug for Runner<L, N, IterData>
where
L: Language,
N: Analysis<L>,
IterData: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// Use an exhaustive pattern match to ensure the Debug implementation and the struct stay in sync.
let Runner {
egraph,
iterations,
roots,
stop_reason,
hooks,
iter_limit,
node_limit,
time_limit,
start_time,
scheduler: _,
} = self;

f.debug_struct("Runner")
.field("egraph", egraph)
.field("iterations", iterations)
.field("roots", roots)
.field("stop_reason", stop_reason)
.field("hooks", &vec![format_args!("<dyn FnMut ..>"); hooks.len()])
.field("iter_limit", iter_limit)
.field("node_limit", node_limit)
.field("time_limit", time_limit)
.field("start_time", start_time)
.field("scheduler", &format_args!("<dyn RewriteScheduler ..>"))
.finish()
}
}

/// Error returned by [`Runner`] when it stops.
///
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -578,6 +616,7 @@ where
/// [`with_scheduler`](Runner::with_scheduler())
/// method.
///
#[derive(Debug)]
pub struct SimpleScheduler;

impl<L, N> RewriteScheduler<L, N> for SimpleScheduler
Expand All @@ -599,12 +638,14 @@ where
///
/// [`BackoffScheduler`] is configurable in the builder-pattern style.
///
#[derive(Debug)]
pub struct BackoffScheduler {
default_match_limit: usize,
default_ban_length: usize,
stats: IndexMap<String, RuleStats>,
}

#[derive(Debug)]
struct RuleStats {
times_applied: usize,
banned_until: usize,
Expand Down

0 comments on commit 1750e3b

Please sign in to comment.