[sledge] Improve backtraces of invariant violation and replay exceptions

Reviewed By: ngorogiannis

Differential Revision: D24630526

fbshipit-source-id: 0f879e84e
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 51a16621aa
commit 52b511d053

@ -51,14 +51,9 @@ let command ~summary ?readme param =
let report main () = let report main () =
try main () |> Report.status try main () |> Report.status
with exn -> with exn ->
let bt = let bt = Printexc.get_raw_backtrace () in
match exn with
| Invariant.Violation (_, bt, _, _) -> bt
| Replay (_, bt, _) -> bt
| _ -> Printexc.get_raw_backtrace ()
in
let rec status_of_exn = function let rec status_of_exn = function
| Invariant.Violation (exn, _, _, _) | Replay (exn, _, _) -> | Invariant.Violation (exn, _, _) | Replay (exn, _) ->
status_of_exn exn status_of_exn exn
| Frontend.Invalid_llvm msg -> Report.InvalidInput msg | Frontend.Invalid_llvm msg -> Report.InvalidInput msg
| Unimplemented msg -> Report.Unimplemented msg | Unimplemented msg -> Report.Unimplemented msg

@ -178,8 +178,7 @@ end
(** Invariants *) (** Invariants *)
module Invariant : sig module Invariant : sig
exception exception Violation of exn * Lexing.position * Sexp.t
Violation of exn * Printexc.raw_backtrace * Lexing.position * Sexp.t
val invariant : val invariant :
Lexing.position -> 'a -> ('a -> Sexp.t) -> (unit -> unit) -> unit Lexing.position -> 'a -> ('a -> Sexp.t) -> (unit -> unit) -> unit
@ -193,7 +192,7 @@ end
(** Failures *) (** Failures *)
exception Replay of exn * Printexc.raw_backtrace * Sexp.t exception Replay of exn * Sexp.t
exception Unimplemented of string exception Unimplemented of string
val fail : ('a, unit -> _) fmt -> 'a val fail : ('a, unit -> _) fmt -> 'a

@ -148,14 +148,13 @@ module Invariant = struct
{pos_fname: string; pos_lnum: int; pos_bol: int; pos_cnum: int} {pos_fname: string; pos_lnum: int; pos_bol: int; pos_cnum: int}
[@@deriving sexp_of] [@@deriving sexp_of]
exception Violation of exn * Printexc.raw_backtrace * position * Sexp.t exception Violation of exn * position * Sexp.t
;; ;;
register_sexp_of_exn register_sexp_of_exn
(Violation (Violation (Not_found, Lexing.dummy_pos, Sexp.List []))
(Not_found, Printexc.get_callstack 1, Lexing.dummy_pos, Sexp.List []))
(function (function
| Violation (exn, _, pos, payload) -> | Violation (exn, pos, payload) ->
Sexp.List Sexp.List
[ Atom "Invariant.Violation" [ Atom "Invariant.Violation"
; sexp_of_exn exn ; sexp_of_exn exn
@ -168,7 +167,7 @@ module Invariant = struct
( try f () ( try f ()
with exn -> with exn ->
let bt = Printexc.get_raw_backtrace () in let bt = Printexc.get_raw_backtrace () in
let exn = Violation (exn, bt, here, sexp_of_t t) in let exn = Violation (exn, here, sexp_of_t t) in
Printexc.raise_with_backtrace exn bt ) ; Printexc.raise_with_backtrace exn bt ) ;
true ) true )
@ -181,13 +180,13 @@ end
(** Failures *) (** Failures *)
exception Replay of exn * Printexc.raw_backtrace * Sexp.t exception Replay of exn * Sexp.t
;; ;;
register_sexp_of_exn register_sexp_of_exn
(Replay (Not_found, Printexc.get_callstack 1, Sexp.List [])) (Replay (Not_found, Sexp.List []))
(function (function
| Replay (exn, _, payload) -> | Replay (exn, payload) ->
Sexp.List [Atom "Replay"; sexp_of_exn exn; payload] Sexp.List [Atom "Replay"; sexp_of_exn exn; payload]
| exn -> Sexp.Atom (Printexc.to_string exn) ) | exn -> Sexp.Atom (Printexc.to_string exn) )

@ -224,7 +224,6 @@ let trace :
Printexc.raise_with_backtrace exc bt ) Printexc.raise_with_backtrace exc bt )
let raisef ?margin exn fmt = let raisef ?margin exn fmt =
let bt = Printexc.get_raw_backtrace () in
let fs = Format.str_formatter in let fs = Format.str_formatter in
( match margin with ( match margin with
| Some m -> | Some m ->
@ -235,9 +234,7 @@ let raisef ?margin exn fmt =
Format.kfprintf Format.kfprintf
(fun fs () -> (fun fs () ->
Format.pp_close_box fs () ; Format.pp_close_box fs () ;
let msg = Format.flush_str_formatter () in raise (exn (Format.flush_str_formatter ())) )
let exn = exn msg in
Printexc.raise_with_backtrace exn bt )
fs fmt fs fmt
let fail fmt = let fail fmt =

@ -1142,8 +1142,8 @@ let wrap tmr f call =
try f () try f ()
with exn -> with exn ->
let bt = Printexc.get_raw_backtrace () in let bt = Printexc.get_raw_backtrace () in
let sexp = sexp_of_call (call ()) in let exn = Replay (exn, sexp_of_call (call ())) in
raise (Replay (exn, bt, sexp)) Printexc.raise_with_backtrace exn bt
let add_tmr = Timer.create "add" ~at_exit:report let add_tmr = Timer.create "add" ~at_exit:report
let union_tmr = Timer.create "union" ~at_exit:report let union_tmr = Timer.create "union" ~at_exit:report

@ -284,8 +284,9 @@ let rec invariant q =
assert (Var.Set.subset sjn.us ~of_:(Var.Set.union us xs)) ; assert (Var.Set.subset sjn.us ~of_:(Var.Set.union us xs)) ;
invariant sjn ) ) invariant sjn ) )
with exc -> with exc ->
let bt = Printexc.get_raw_backtrace () in
[%Trace.info "%a" pp q] ; [%Trace.info "%a" pp q] ;
raise exc Printexc.raise_with_backtrace exc bt
(** Quantification and Vocabulary *) (** Quantification and Vocabulary *)

Loading…
Cancel
Save