Skip to content

Commit

Permalink
Fix tricky bug in the optimiser
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Dec 19, 2024
1 parent aa30e14 commit c4e036a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions compiler/shared_ast/optimizations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ let binder_vars_used_at_most_once
let rec vars_count (e : ('a dcalc_lcalc, 'm) gexpr) : int array =
match e with
| EVar v, _ ->
Array.map
(fun i -> if Bindlib.eq_vars v (Array.get vars i) then 1 else 0)
(Array.make (Array.length vars) 0)
Array.map (fun vi -> if Bindlib.eq_vars v vi then 1 else 0) vars
| e ->
Expr.shallow_fold
(fun e' acc -> Array.map2 (fun x y -> x + y) (vars_count e') acc)
Expand Down
2 changes: 1 addition & 1 deletion runtimes/c/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,8 @@ void register_error_handler(void (*f)(const struct catala_error *)){

void catala_init()
{
mp_set_memory_functions(&catala_malloc,&catala_realloc,&catala_free);
mpz_init_set_ui(zconst_100, 100);
mp_set_memory_functions(&catala_malloc,&catala_realloc,&catala_free);
if (setjmp(catala_error_jump_buffer)) {
char *error_kind;
const catala_code_position pos = catala_error_raised.position;
Expand Down
10 changes: 8 additions & 2 deletions tests/tuples/good/tuplists.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,20 @@ let S : S_in → S =
in
let r4 : list of (money, decimal) =
map (λ (x_y_z: (decimal, money, money)) →
(x_y_z.1 * x_y_z.0, x_y_z.1 / x_y_z.2))
let x : decimal = x_y_z.0 in
let y : money = x_y_z.1 in
let z : money = x_y_z.2 in
(y * x, y / z))
tlist
in
let r5 : list of (money, decimal) =
map2
(λ (x: decimal) (y_z: (money, money)) →
let x_y_z : (decimal, money, money) = (x, y_z.0, y_z.1) in
(x_y_z.1 * x_y_z.0, x_y_z.1 / x_y_z.2))
let x1 : decimal = x_y_z.0 in
let y : money = x_y_z.1 in
let z : money = x_y_z.2 in
(y * x1, y / z))
lis1
map2 (λ (y: money) (z: money) → (y, z)) lis2 lis3
in
Expand Down

0 comments on commit c4e036a

Please sign in to comment.