Skip to content

Commit

Permalink
Panic instead of partially running actions (#234)
Browse files Browse the repository at this point in the history
* Panic instead of ignoring errors in EGraph::step_rules

* Fix semi_naive_set_function test by moving lookup into query

* Fix herbie-tutorial test

* Add explicit panic message
  • Loading branch information
Alex-Fischman authored Sep 14, 2023
1 parent 4d67f26 commit 8cd5fda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,15 @@ impl EGraph {
// run one iteration when n == 0
if num_vars == 0 {
rule.matches += 1;
// we can ignore results here
stack.clear();
let _ = self.run_actions(stack, &[], &rule.program, true);
self.run_actions(stack, &[], &rule.program, true)
.unwrap_or_else(|e| panic!("error while running actions for {name}: {e}"));
} else {
for values in all_values.chunks(num_vars) {
rule.matches += 1;
// we can ignore results here
stack.clear();
let _ = self.run_actions(stack, values, &rule.program, true);
self.run_actions(stack, values, &rule.program, true)
.unwrap_or_else(|e| panic!("error while running actions for {name}: {e}"));
}
}

Expand Down
10 changes: 4 additions & 6 deletions tests/herbie-tutorial.egg
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
(rule ((Num r))
((set (lower-bound (Num r)) r)
(set (upper-bound (Num r)) r)))
(rule ((= e (Add a b)))
((set (lower-bound e)
(+ (lower-bound a) (lower-bound b)))))
(rule ((= e (Add a b)))
((set (upper-bound e)
(+ (upper-bound a) (upper-bound b)))))
(rule ((= e (Add a b)) (= x (lower-bound a)) (= y (lower-bound b)))
((set (lower-bound e) (+ x y))))
(rule ((= e (Add a b)) (= x (upper-bound a)) (= y (upper-bound b)))
((set (upper-bound e) (+ x y))))
(rule ((= e (Mul a b)))
((set (lower-bound e)
(min (* (lower-bound a) (lower-bound b))
Expand Down
2 changes: 1 addition & 1 deletion tests/semi_naive_set_function.egg
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
(function g (i64) i64 :merge (max old new))
(set (g 0) 0)
(set (g 1) 1)
(rule ((= x (g x))) ((set (g (+ x 1)) (+ (g (- x 1)) 2))))
(rule ((= x (g x)) (= y (g (- x 1)))) ((set (g (+ x 1)) (+ y 2))))

(run 100)
(print-table g)
Expand Down

0 comments on commit 8cd5fda

Please sign in to comment.