Summary: See explanations in D17955104 Reviewed By: ezgicicek Differential Revision: D17955282 fbshipit-source-id: a9d75e8a1master
parent
8251e2dea8
commit
27c0d7258d
@ -0,0 +1,60 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
open! IStd
|
||||
module F = Format
|
||||
module CallEvent = PulseCallEvent
|
||||
module ValueHistory = PulseValueHistory
|
||||
|
||||
type 'a t =
|
||||
| Immediate of {imm: 'a; location: Location.t; history: ValueHistory.t}
|
||||
| ViaCall of {f: CallEvent.t; location: Location.t; history: ValueHistory.t; in_call: 'a t}
|
||||
[@@deriving compare]
|
||||
|
||||
let rec get_immediate = function
|
||||
| Immediate {imm; _} ->
|
||||
imm
|
||||
| ViaCall {in_call; _} ->
|
||||
get_immediate in_call
|
||||
|
||||
|
||||
let get_outer_location = function Immediate {location; _} | ViaCall {location; _} -> location
|
||||
|
||||
let get_history = function Immediate {history; _} | ViaCall {history; _} -> history
|
||||
|
||||
let get_start_location trace =
|
||||
match get_history trace |> List.last with
|
||||
| Some event ->
|
||||
ValueHistory.location_of_event event
|
||||
| None ->
|
||||
get_outer_location trace
|
||||
|
||||
|
||||
let rec pp pp_immediate fmt = function
|
||||
| Immediate {imm; location= _; history} ->
|
||||
if Config.debug_level_analysis < 3 then pp_immediate fmt imm
|
||||
else F.fprintf fmt "%a::%a" ValueHistory.pp history pp_immediate imm
|
||||
| ViaCall {f; location= _; history; in_call} ->
|
||||
if Config.debug_level_analysis < 3 then pp pp_immediate fmt in_call
|
||||
else
|
||||
F.fprintf fmt "%a::%a[%a]" ValueHistory.pp history CallEvent.pp f (pp pp_immediate) in_call
|
||||
|
||||
|
||||
let rec add_to_errlog ~nesting pp_immediate trace errlog =
|
||||
match trace with
|
||||
| Immediate {imm; location; history} ->
|
||||
ValueHistory.add_to_errlog ~nesting history
|
||||
@@ Errlog.make_trace_element nesting location (F.asprintf "%a" pp_immediate imm) []
|
||||
:: errlog
|
||||
| ViaCall {f; location; in_call; history} ->
|
||||
ValueHistory.add_to_errlog ~nesting history
|
||||
@@ (fun errlog ->
|
||||
Errlog.make_trace_element nesting location
|
||||
(F.asprintf "when calling %a here" CallEvent.pp f)
|
||||
[]
|
||||
:: errlog )
|
||||
@@ add_to_errlog ~nesting:(nesting + 1) pp_immediate in_call
|
||||
@@ errlog
|
@ -0,0 +1,37 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
open! IStd
|
||||
module F = Format
|
||||
module CallEvent = PulseCallEvent
|
||||
module ValueHistory = PulseValueHistory
|
||||
|
||||
type 'a t =
|
||||
| Immediate of {imm: 'a; location: Location.t; history: ValueHistory.t}
|
||||
| ViaCall of
|
||||
{ f: CallEvent.t
|
||||
; location: Location.t (** location of the call event *)
|
||||
; history: ValueHistory.t (** the call involves a value with this prior history *)
|
||||
; in_call: 'a t (** last step of the trace is in a call to [f] made at [location] *) }
|
||||
[@@deriving compare]
|
||||
|
||||
val pp : (F.formatter -> 'a -> unit) -> F.formatter -> 'a t -> unit
|
||||
|
||||
val get_outer_location : 'a t -> Location.t
|
||||
(** skip histories and go straight to the where the action is: either the action itself or the
|
||||
call that leads to the action *)
|
||||
|
||||
val get_start_location : 'a t -> Location.t
|
||||
(** initial step in the history if not empty, or else same as {!get_outer_location} *)
|
||||
|
||||
val get_immediate : 'a t -> 'a
|
||||
|
||||
val add_to_errlog :
|
||||
nesting:int
|
||||
-> (F.formatter -> 'a -> unit)
|
||||
-> 'a t
|
||||
-> Errlog.loc_trace_elem list
|
||||
-> Errlog.loc_trace_elem list
|
Loading…
Reference in new issue