Skip to content

Commit

Permalink
[coq] Enable backtraces on anomaly
Browse files Browse the repository at this point in the history
This means we will re-execute the anomaly sentence, which may not be
very safe.

Fixes #153
  • Loading branch information
ejgallego committed Jan 9, 2023
1 parent 5e4999a commit 0019655
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 7 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# coq-lsp 0.1.3:
------------------------
# coq-lsp 0.1.3: Prediction
---------------------------

- Much improved handling of Coq fatal errors, the server is now
hardened against them (@ejgallego, #155, #157, #160, fixes #91)
hardened against them, and will stop checking on anomalies
(@ejgallego, #155, #157, #160, fixes #91)
- If a command produces an anomaly, coq-lsp will re-execute it with
backtracks enabled, as to produce a report (@ejgallego, #161, fixes
#153)

# coq-lsp 0.1.2: Message
------------------------
Expand Down
19 changes: 16 additions & 3 deletions coq/protect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module R = struct
map_error ~f
end

let eval ~f x =
let rec eval ~f ~loop x =
try
let res = f x in
R.Completed (Ok res)
Expand All @@ -39,5 +39,18 @@ let eval ~f x =
let e, info = Exninfo.capture exn in
let loc = Loc.(get_loc info) in
let msg = CErrors.iprint (e, info) in
if CErrors.is_anomaly e then R.Completed (Error (Anomaly (loc, msg)))
else R.Completed (Error (User (loc, msg)))
let anomaly = CErrors.is_anomaly e in
let bt = Printexc.backtrace_status () in
match anomaly, bt, loop with
| true, true, _
| true, false, false ->
R.Completed (Error (Anomaly (loc, msg)))
| true, false, true ->
CDebug.set_flags "backtrace";
let res = eval ~f ~loop:false x in
CDebug.set_flags "-backtrace";
res
| false, _, _ ->
R.Completed (Error (User (loc, msg)))

let eval ~f x = eval ~f ~loop:true x

0 comments on commit 0019655

Please sign in to comment.