Skip to content

Commit

Permalink
Fix computation of extra_args during CPS conversion of Lstaticraise (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
mshinwell committed Jul 30, 2021
1 parent c0fd776 commit d84079b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
16 changes: 8 additions & 8 deletions middle_end/flambda2/from_lambda/lambda_to_flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,12 @@ let rec cps_non_tail acc env ccenv (lam : L.lambda)
k k_exn
| Lstaticraise (static_exn, args) ->
let continuation = Env.get_static_exn_continuation env static_exn in
let extra_args =
List.map (fun var : IR.simple -> Var var)
(Env.extra_args_for_continuation env continuation)
in
cps_non_tail_list acc env ccenv args
(fun acc env ccenv args ->
let extra_args =
List.map (fun var : IR.simple -> Var var)
(Env.extra_args_for_continuation env continuation)
in
compile_staticfail acc env ccenv
~continuation ~args:(args @ extra_args)
) k_exn
Expand Down Expand Up @@ -1251,12 +1251,12 @@ and cps_tail acc env ccenv (lam : L.lambda) (k : Continuation.t)
k k_exn
| Lstaticraise (static_exn, args) ->
let continuation = Env.get_static_exn_continuation env static_exn in
let extra_args =
List.map (fun var : IR.simple -> Var var)
(Env.extra_args_for_continuation env continuation)
in
cps_non_tail_list acc env ccenv args
(fun acc env ccenv args ->
let extra_args =
List.map (fun var : IR.simple -> Var var)
(Env.extra_args_for_continuation env continuation)
in
compile_staticfail acc env ccenv
~continuation ~args:(args @ extra_args)
) k_exn
Expand Down
30 changes: 30 additions & 0 deletions middle_end/flambda2/tests/mlexamples/extra_args_and_staticraise.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(* After [Base.Hashtbl.fold].
This example produces the following lambda code:
(let
(f/9 =
(function x/11[int] init/12[int] : int
(let (m/13 =v[int] init/12)
(catch
(try (exit 1 (for i/14 0 to x/11 (assign m/13 (+ m/13 i/14))))
with exn/23 0)
with (1 val/22[int]) m/13))))
(makeblock 0 f/9))
which is interesting because of the for-loop as an argument to
[exit], in conjunction with the mutable variable [m]. *)

type 'a ref = { mutable contents : 'a }
external ref : 'a -> 'a ref = "%makemutable"
external ( ! ) : 'a ref -> 'a = "%field0"
external ( := ) : 'a ref -> 'a -> unit = "%setfield0"
external ( + ) : int -> int -> int = "%addint"
let f x init =
let m = ref init in
match
for i = 0 to x do
m := !m + i
done
with
| () -> !m
| exception _ -> 0

0 comments on commit d84079b

Please sign in to comment.