@@ -30,18 +30,31 @@ module R = struct
3030end
3131
3232(* Eval and reify exceptions *)
33- let eval_exn ~f x =
33+ let rec eval_exn ~f ~ retry x =
3434 try
3535 let res = f x in
3636 R. Completed (Ok res)
3737 with
3838 | Sys. Break -> R. Interrupted
3939 | exn ->
40- let e , info = Exninfo. capture exn in
40+ let exn , info = Exninfo. capture exn in
4141 let loc = Loc. (get_loc info) in
42- let msg = CErrors. iprint (e, info) in
43- if CErrors. is_anomaly e then R. Completed (Error (Anomaly (loc, msg)))
44- else R. Completed (Error (User (loc, msg)))
42+ let msg = CErrors. iprint (exn , info) in
43+ let anomaly = CErrors. is_anomaly exn in
44+ let bt = Printexc. backtrace_status () in
45+ match anomaly, bt, retry with
46+ | true , true , _
47+ | true , false , false ->
48+ R. Completed (Error (Anomaly (loc, msg)))
49+ | true , false , true ->
50+ (* This doesn't work because the state unfreeze will restore the
51+ "no-backtrace" status *)
52+ CDebug. set_flags " backtrace" ;
53+ let res = eval_exn ~f ~retry: false x in
54+ CDebug. set_flags " -backtrace" ;
55+ res
56+ | false , _ , _ ->
57+ R. Completed (Error (User (loc, msg)))
4558
4659module E = struct
4760 type 'a t =
5972let fb_queue : Message.t list ref = ref []
6073
6174(* Eval with reified exceptions and feedback *)
62- let eval ~f x =
63- let r = eval_exn ~f x in
75+ let eval ~f ~ pure x =
76+ let r = eval_exn ~retry: pure ~ f x in
6477 let feedback = List. rev ! fb_queue in
6578 let () = fb_queue := [] in
6679 { E. r; feedback }
0 commit comments