Fix bug in closure conversion

This commit is contained in:
Louis Gesbert 2024-07-05 18:02:25 +02:00
parent 961a93ae83
commit ec6b50988b

View File

@ -220,7 +220,7 @@ let rec transform_closures_expr :
EnumConstructor.Map.add cons EnumConstructor.Map.add cons
(Expr.eabs new_binder tys (Mark.get e1)) (Expr.eabs new_binder tys (Mark.get e1))
new_cases ) new_cases )
| _ -> failwith "should not happen") | _ -> assert false)
cases cases
(free_vars, EnumConstructor.Map.empty) (free_vars, EnumConstructor.Map.empty)
in in
@ -273,6 +273,9 @@ let rec transform_closures_expr :
| EAbs { binder; tys } -> | EAbs { binder; tys } ->
let vars, arg = Bindlib.unmbind binder in let vars, arg = Bindlib.unmbind binder in
let new_free_vars, new_arg = (transform_closures_expr ctx) arg in let new_free_vars, new_arg = (transform_closures_expr ctx) arg in
let new_free_vars =
Array.fold_left (fun m v -> Var.Map.remove v m) new_free_vars vars
in
let new_arg = let new_arg =
Expr.make_abs vars new_arg tys (Expr.mark_pos m_arg) Expr.make_abs vars new_arg tys (Expr.mark_pos m_arg)
in in
@ -510,7 +513,7 @@ let rec hoist_closures_expr :
EnumConstructor.Map.add cons EnumConstructor.Map.add cons
(Expr.eabs new_binder tys (Mark.get e1)) (Expr.eabs new_binder tys (Mark.get e1))
new_cases ) new_cases )
| _ -> failwith "should not happen") | _ -> assert false)
cases cases
(collected_closures, EnumConstructor.Map.empty) (collected_closures, EnumConstructor.Map.empty)
in in