Skip to content

Commit

Permalink
Merge pull request #630 from egraphs-good/oflatt-egglog-latest
Browse files Browse the repository at this point in the history
Upgrade eggcc to deterministic egglog
  • Loading branch information
oflatt authored Oct 9, 2024
2 parents 1483581 + 065c10d commit 047ef3b
Show file tree
Hide file tree
Showing 31 changed files with 409 additions and 291 deletions.
66 changes: 60 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ name = "files"


[dependencies]
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "325814fd90767b5e43c72bc2eb65e14ff0b8746c" }
egraph-serialize = "0.1.0"
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "12ecb21e8aeb25297a36be2a04d846222daf5297" }
egraph-serialize = "0.2.0"
log = "0.4.19"
thiserror = "1"
lalrpop-util = { version = "0.20.2", features = ["lexer"] }
Expand Down
66 changes: 60 additions & 6 deletions dag_in_context/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dag_in_context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "325814fd90767b5e43c72bc2eb65e14ff0b8746c" }
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "12ecb21e8aeb25297a36be2a04d846222daf5297" }
strum = "0.25"
strum_macros = "0.25"
main_error = "0.1.2"
thiserror = "1.0"
egraph-serialize = "0.1.0"
egraph-serialize = "0.2.0"
bril-rs = { git = "https://github.com/uwplse/bril", rev = "e2be3f5" }
indexmap = "2.0.0"
rustc-hash = "1.1.0"
Expand Down
20 changes: 10 additions & 10 deletions dag_in_context/src/add_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Mantains the sharing invariant (see restore_sharing_invariant) by using a cache.

use egglog::Term;
use std::collections::HashMap;
use indexmap::IndexMap;

use crate::{
print_with_intermediate_helper,
Expand All @@ -14,8 +14,8 @@ use crate::{
};

pub struct ContextCache {
with_ctx: HashMap<(*const Expr, AssumptionRef), RcExpr>,
symbol_gen: HashMap<(*const Expr, AssumptionRef), String>,
with_ctx: IndexMap<(*const Expr, AssumptionRef), RcExpr>,
symbol_gen: IndexMap<(*const Expr, AssumptionRef), String>,
/// How many placeholder contexts we've created (used to make a unique name each time)
loop_context_placeholder_counter: usize,
/// The unions that we need to make between assumptions
Expand Down Expand Up @@ -48,8 +48,8 @@ impl ContextCache {

pub fn new() -> ContextCache {
ContextCache {
with_ctx: HashMap::new(),
symbol_gen: HashMap::new(),
with_ctx: IndexMap::new(),
symbol_gen: IndexMap::new(),
loop_context_placeholder_counter: 0,
loop_context_unions: Vec::new(),
symbolic_ctx: false,
Expand All @@ -59,8 +59,8 @@ impl ContextCache {

pub fn new_symbolic_ctx() -> ContextCache {
ContextCache {
with_ctx: HashMap::new(),
symbol_gen: HashMap::new(),
with_ctx: IndexMap::new(),
symbol_gen: IndexMap::new(),
loop_context_placeholder_counter: 0,
loop_context_unions: Vec::new(),
symbolic_ctx: true,
Expand All @@ -70,8 +70,8 @@ impl ContextCache {

pub fn new_dummy_ctx() -> ContextCache {
ContextCache {
with_ctx: HashMap::new(),
symbol_gen: HashMap::new(),
with_ctx: IndexMap::new(),
symbol_gen: IndexMap::new(),
loop_context_placeholder_counter: 0,
loop_context_unions: Vec::new(),
symbolic_ctx: false,
Expand All @@ -94,7 +94,7 @@ impl ContextCache {
&self,
printed: &mut String,
tree_state: &mut TreeToEgglog,
term_cache: &mut HashMap<Term, String>,
term_cache: &mut IndexMap<Term, String>,
) -> String {
self.loop_context_unions
.iter()
Expand Down
9 changes: 5 additions & 4 deletions dag_in_context/src/from_egglog.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
//! Converts from an egglog AST directly to the rust representation of that AST.
//! Common subexpressions (common terms) must be converted to the same RcExpr (pointer equality).

use std::{collections::HashMap, rc::Rc};
use std::rc::Rc;

use egglog::{ast::Literal, match_term_app, Term};
use indexmap::IndexMap;

use crate::schema::{
Assumption, BaseType, BinaryOp, Constant, Expr, RcExpr, TernaryOp, TreeProgram, Type, UnaryOp,
};

pub struct FromEgglog<'a> {
pub termdag: &'a egglog::TermDag,
pub conversion_cache: HashMap<Term, RcExpr>,
pub conversion_cache: IndexMap<Term, RcExpr>,
}

pub fn program_from_egglog(program: Term, termdag: &egglog::TermDag) -> TreeProgram {
let mut converter = FromEgglog {
termdag,
conversion_cache: HashMap::new(),
conversion_cache: IndexMap::new(),
};
converter.program_from_egglog(program)
}
Expand All @@ -28,7 +29,7 @@ pub fn program_from_egglog_preserve_ctx_nodes(
) -> TreeProgram {
let mut converter = FromEgglog {
termdag,
conversion_cache: HashMap::new(),
conversion_cache: IndexMap::new(),
};
converter.program_from_egglog(program)
}
Expand Down
Loading

0 comments on commit 047ef3b

Please sign in to comment.