Skip to content

Commit

Permalink
Fix symbolic context methods to not return cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Fischman committed Jun 4, 2024
1 parent 9529798 commit 9b909e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
8 changes: 4 additions & 4 deletions dag_in_context/src/add_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ impl TreeProgram {

/// add stand-in variables for all the contexts in the program
/// useful for testing if you don't care about context in the test
pub fn add_symbolic_ctx(&self) -> (TreeProgram, ContextCache) {
pub fn add_symbolic_ctx(&self) -> TreeProgram {
self.add_context_internal(|_| Assumption::dummy(), ContextCache::new_symbolic_ctx())
.0
}

pub fn add_dummy_ctx(&self) -> (TreeProgram, ContextCache) {
Expand Down Expand Up @@ -188,10 +189,9 @@ impl Expr {
(value, cache)
}

pub fn add_symbolic_ctx(self: &RcExpr) -> (RcExpr, ContextCache) {
pub fn add_symbolic_ctx(self: &RcExpr) -> RcExpr {
let mut cache = ContextCache::new_symbolic_ctx();
let value = self.add_ctx_with_cache(Assumption::dummy(), &mut cache);
(value, cache)
self.add_ctx_with_cache(Assumption::dummy(), &mut cache)
}

pub fn add_ctx(self: &RcExpr, current_ctx: Assumption) -> (RcExpr, ContextCache) {
Expand Down
7 changes: 2 additions & 5 deletions dag_in_context/src/optimizations/loop_unroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn loop_unroll_simple() -> crate::Result {
.add_arg_type(base(intt()));

let unrolled_add = add(add(add(add(getat(0), int(1)), int(1)), int(1)), int(1));
let (expected, expected_cache) = dowhile(
let expected = dowhile(
parallel!(int(0)),
parallel!(less_than(unrolled_add.clone(), int(8)), unrolled_add),
)
Expand All @@ -49,10 +49,7 @@ fn loop_unroll_simple() -> crate::Result {

egglog_test(
&format!("{prog}"),
&format!(
"{expected}\n{}\n(check (= {prog} {expected}))",
expected_cache.get_unions()
),
&format!("(check (= {prog} {expected}))"),
vec![prog.to_program(base(intt()), tuplet!(intt()))],
intv(0),
tuplev!(intv(8)),
Expand Down
14 changes: 3 additions & 11 deletions dag_in_context/src/utility/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn test_subst_if() -> crate::Result {

let replace_with = parallel!(ttrue(), int(5)).add_arg_type(emptyt());

let (expected, expected_cache) = tif(
let expected = tif(
ttrue(),
add(int(5), int(1)),
add(arg(), int(1)),
Expand All @@ -195,16 +195,8 @@ fn test_subst_if() -> crate::Result {
.add_symbolic_ctx();
let ctx = Assumption::dummy();

let build = format!(
"
(let substituted (Subst {ctx}
{replace_with}
{expr}))"
);
let check = format!(
"{expected}\n{}\n(check (= substituted {expected}))",
expected_cache.get_unions()
);
let build = format!("(let substituted (Subst {ctx} {replace_with} {expr}))");
let check = format!("(check (= substituted {expected}))");

crate::egglog_test(
&build.to_string(),
Expand Down

0 comments on commit 9b909e8

Please sign in to comment.