Skip to content

Commit

Permalink
Merge pull request #3 from Bastacyclop/tracing
Browse files Browse the repository at this point in the history
Tracing
  • Loading branch information
memoryleak47 authored Oct 29, 2024
2 parents 8ad27c6 + 80f3b5f commit 50b5848
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ repository = "https://github.com/memoryleak47/slotted-egraphs/"
[features]
explanations = []
checks = []
tracing = ["tracing/max_level_trace", "tracing/release_max_level_trace"]
# ??? no_tracing = ["tracing/max_level_debug", "tracing/release_max_level_off"]

[package.metadata.docs.rs]
features = ["explanations"]

[dependencies]
fnv = "1.0.7"
tracing = { version = "0.1", features = ["attributes"] }

[dev-dependencies]
symbol_table = { version = "0.3", features = ["global"]}
rand = "0.8.5"

[profile.release]
debug = true
debug = true
1 change: 1 addition & 0 deletions src/egraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
self.proven_get_group_compatible_variants(enode).into_iter().map(|pnode| pnode.elem).collect()
}

#[instrument(level = "trace", skip_all)]
pub(crate) fn get_group_compatible_weak_variants(&self, enode: &L) -> HashSet<L> {
let set = self.get_group_compatible_variants(enode);
let mut shapes = HashSet::default();
Expand Down
1 change: 1 addition & 0 deletions src/egraph/rebuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
self.touched_class(from.id);
}

#[instrument(level = "trace", skip_all)]
pub(crate) fn rebuild(&mut self) {
if CHECKS { self.check(); }
while let Some(sh) = self.pending.iter().cloned().next() {
Expand Down
1 change: 1 addition & 0 deletions src/explain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use mock::*;

#[cfg(feature = "explanations")]
impl<L: Language, N: Analysis<L>> EGraph<L, N> {
#[instrument(level = "trace", skip_all)]
pub fn explain_equivalence(&mut self, t1: RecExpr<L>, t2: RecExpr<L>) -> ProvenEq {
let i1 = self.add_syn_expr(t1);
let i2 = self.add_syn_expr(t2);
Expand Down
2 changes: 2 additions & 0 deletions src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Extractor<L: Language, CF: CostFunction<L>> {
}

impl<L: Language, CF: CostFunction<L>> Extractor<L, CF> {
#[instrument(level = "trace", skip_all)]
pub fn new<N: Analysis<L>>(eg: &EGraph<L, N>, cost_fn: CF) -> Self {
if CHECKS {
eg.check();
Expand Down Expand Up @@ -62,6 +63,7 @@ impl<L: Language, CF: CostFunction<L>> Extractor<L, CF> {
Self { map }
}

#[instrument(level = "trace", skip_all)]
pub fn extract<N: Analysis<L>>(&self, i: &AppliedId, eg: &EGraph<L, N>) -> RecExpr<L> {
let i = eg.find_applied_id(i);

Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ mod group;
use group::*;

mod run;
pub use run::*;
pub use run::*;

pub(crate) use tracing::instrument;
5 changes: 5 additions & 0 deletions src/rewrite/ematch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct State {
partial_slotmap: SlotMap,
}

#[instrument(level = "trace", skip_all)]
pub fn ematch_all<L: Language, N: Analysis<L>>(eg: &EGraph<L, N>, pattern: &Pattern<L>) -> Vec<Subst> {
let mut out = Vec::new();
for i in eg.ids() {
Expand Down Expand Up @@ -39,6 +40,10 @@ fn ematch_impl<L: Language, N: Analysis<L>>(pattern: &Pattern<L>, st: State, i:
Pattern::ENode(n, children) => {
let mut out = Vec::new();
for nn in eg.enodes_applied(&i) {
let d = std::mem::discriminant(n);
let dd = std::mem::discriminant(&nn);
if d != dd { continue };

'nodeloop: for n2 in eg.get_group_compatible_weak_variants(&nn) {
if CHECKS {
assert_eq!(&nullify_app_ids(n), n);
Expand Down
6 changes: 4 additions & 2 deletions src/rewrite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ fn any_to_t<T: Any>(t: Box<dyn Any>) -> T {

/// Applies each given rewrite rule to the E-Graph once.
/// Returns an indicator for whether the e-graph changed as a result.
#[instrument(level = "trace", skip_all)]
pub fn apply_rewrites<L: Language, N: Analysis<L>>(eg: &mut EGraph<L, N>, rewrites: &[Rewrite<L, N>]) -> bool {
use tracing::trace;
let prog = eg.progress();

let ts: Vec<Box<dyn Any>> = rewrites.iter().map(|rw| (*rw.searcher)(eg)).collect();
for (rw, t) in rewrites.iter().zip(ts.into_iter()) {
(*rw.applier)(t, eg);
}

prog != eg.progress()
}

Expand Down

0 comments on commit 50b5848

Please sign in to comment.