Skip to content

Commit

Permalink
Remove make_expr
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscInside committed Dec 13, 2024
1 parent 65a9f6b commit f1b5cc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
13 changes: 11 additions & 2 deletions src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use ordered_float::NotNan;
use std::collections::VecDeque;

use crate::{util::HashMap, ArcSort, EGraph, Function, Symbol, TupleOutput, Value};
use crate::{
extract::Extractor, util::HashMap, ArcSort, EGraph, Function, Symbol, TermDag, TupleOutput,
Value,
};

pub struct SerializeConfig {
// Maximumum number of functions to include in the serialized graph, any after this will be discarded
Expand Down Expand Up @@ -312,7 +315,13 @@ impl EGraph {
let op = if sort.is_container_sort() {
sort.serialized_name(value).to_string()
} else {
sort.make_expr(self, *value).1.to_string()
let mut termdag = TermDag::default();
let extractor = Extractor::new(self, &mut termdag);
let (cost, term) = sort
.extract_term(self, *value, &extractor, &mut termdag)
.expect("Extraction should be successful since extractor has been fully initialized");

termdag.term_to_expr(&term).to_string()
};
egraph.nodes.insert(
node_id.clone(),
Expand Down
12 changes: 0 additions & 12 deletions src/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ pub trait Sort: Any + Send + Sync + Debug {
_extractor: &Extractor,
_termdag: &mut TermDag,
) -> Option<(Cost, Term)>;

/// Extracting an expression (with smallest cost) out of a primitive value.
/// The default implementation uses [`Sort::extract_term`].
fn make_expr(&self, egraph: &EGraph, value: Value) -> (Cost, Expr) {
let mut termdag = TermDag::default();
let extractor = Extractor::new(egraph, &mut termdag);
let (cost, term) = self
.extract_term(egraph, value, &extractor, &mut termdag)
.expect("Extraction should be successful since extractor has been fully initialized");

(cost, termdag.term_to_expr(&term))
}
}

// Note: this trait is currently intended to be implemented on the
Expand Down

0 comments on commit f1b5cc9

Please sign in to comment.