From 9dad4c36483ec342380e98cb09b45b73f725d39d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 21 Aug 2018 05:22:44 -0700 Subject: [PATCH] Reporting cleanup 12: node_id_key -> node Reviewed By: jvillard Differential Revision: D9360943 fbshipit-source-id: 6f2c5720c --- infer/src/IR/Errlog.ml | 28 ++++++++++++++------------ infer/src/IR/Errlog.mli | 12 +++++------ infer/src/backend/InferPrint.ml | 7 +------ infer/src/backend/reporting.ml | 35 ++++++++++++++++----------------- infer/src/backend/reporting.mli | 3 +-- infer/src/biabduction/State.ml | 19 +++++++----------- infer/src/biabduction/State.mli | 5 +---- 7 files changed, 48 insertions(+), 61 deletions(-) diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index a0898ac4f..9ebb34942 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -60,9 +60,9 @@ let compute_local_exception_line loc_trace = List.fold_until ~init:(None, None) ~f:compute_local_exception_line ~finish:snd loc_trace -type node_id_key = +type node = | FrontendNode of {node_key: Procdesc.NodeKey.t} - | BackendNode of {node_id: Procdesc.Node.id; node_key: Procdesc.NodeKey.t} + | BackendNode of {node: Procdesc.Node.t} type err_key = { severity: Exceptions.severity @@ -73,7 +73,8 @@ type err_key = (** Data associated to a specific error *) type err_data = - { node_id_key: node_id_key + { node_id: int + ; node_key: Procdesc.NodeKey.t ; session: int ; loc: Location.t ; loc_in_ml_source: L.ocaml_pos option @@ -173,15 +174,8 @@ let pp_warnings fmt (errlog: t) = let pp_html source path_to_root fmt (errlog: t) = let pp_eds fmt err_datas = let pp_nodeid_session_loc fmt err_data = - let node_id = - match err_data.node_id_key with - | FrontendNode _ -> - 0 - | BackendNode {node_id} -> - (node_id :> int) - in Io_infer.Html.pp_session_link source path_to_root fmt - (node_id, err_data.session, err_data.loc.Location.line) + (err_data.node_id, err_data.session, err_data.loc.Location.line) in ErrDataSet.iter (pp_nodeid_session_loc fmt) err_datas in @@ -220,7 +214,7 @@ let update errlog_old errlog_new = ErrLogHash.iter (fun err_key l -> ignore (add_issue errlog_old err_key l)) errlog_new -let log_issue procname ~clang_method_kind severity err_log ~loc ~node_id_key ~session ~ltr +let log_issue procname ~clang_method_kind severity err_log ~loc ~node ~session ~ltr ~linters_def_file ~doc_url ~access ~extras exn = let error = Exceptions.recognize_exception exn in let severity = Option.value error.severity ~default:severity in @@ -268,8 +262,16 @@ let log_issue procname ~clang_method_kind severity err_log ~loc ~node_id_key ~se EventLogger.log issue ) ; if should_report && not hide_java_loc_zero && not hide_memory_error then let added = + let node_id, node_key = + match node with + | FrontendNode {node_key} -> + (0, node_key) + | BackendNode {node} -> + ((Procdesc.Node.get_id node :> int), Procdesc.Node.compute_key node) + in let err_data = - { node_id_key + { node_id + ; node_key ; session ; loc ; loc_in_ml_source= error.ocaml_pos diff --git a/infer/src/IR/Errlog.mli b/infer/src/IR/Errlog.mli index b83080564..3ee94c2f0 100644 --- a/infer/src/IR/Errlog.mli +++ b/infer/src/IR/Errlog.mli @@ -34,9 +34,9 @@ val compute_local_exception_line : loc_trace -> int option This extra information adds value to the report itself, and may avoid digging into the trace to understand the cause of the report. *) -type node_id_key = +type node = | FrontendNode of {node_key: Procdesc.NodeKey.t} - | BackendNode of {node_id: Procdesc.Node.id; node_key: Procdesc.NodeKey.t} + | BackendNode of {node: Procdesc.Node.t} type err_key = private { severity: Exceptions.severity @@ -47,7 +47,8 @@ type err_key = private (** Data associated to a specific error *) type err_data = private - { node_id_key: node_id_key + { node_id: int + ; node_key: Procdesc.NodeKey.t ; session: int ; loc: Location.t ; loc_in_ml_source: Logging.ocaml_pos option @@ -94,6 +95,5 @@ val update : t -> t -> unit val log_issue : Typ.Procname.t -> clang_method_kind:ClangMethodKind.t option -> Exceptions.severity -> t - -> loc:Location.t -> node_id_key:node_id_key -> session:int -> ltr:loc_trace - -> linters_def_file:string option -> doc_url:string option -> access:string option - -> extras:Jsonbug_t.extra option -> exn -> unit + -> loc:Location.t -> node:node -> session:int -> ltr:loc_trace -> linters_def_file:string option + -> doc_url:string option -> access:string option -> extras:Jsonbug_t.extra option -> exn -> unit diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index 112cab1ea..7a0af09bb 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -301,11 +301,6 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct | _ -> Typ.Procname.to_string proc_name in - let node_key = - match err_data.node_id_key with - | FrontendNode {node_key} | BackendNode {node_key} -> - Procdesc.NodeKey.to_string node_key - in let bug = { Jsonbug_j.bug_class= Exceptions.err_class_string err_data.err_class ; kind= severity @@ -320,7 +315,7 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct ; procedure_start_line ; file ; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace err_key.severity - ; node_key + ; node_key= Procdesc.NodeKey.to_string err_data.node_key ; key= compute_key bug_type proc_name file ; hash= compute_hash severity bug_type proc_name file qualifier ; dotty= error_desc_to_dotty_string err_key.err_desc diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 317f303a9..33aae636a 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -12,23 +12,23 @@ type log_t = ?ltr:Errlog.loc_trace -> ?linters_def_file:string -> ?doc_url:string -> ?access:string -> ?extras:Jsonbug_t.extra -> exn -> unit -let log_issue_from_errlog procname ~clang_method_kind severity err_log ~loc ~node_id_key ~ltr +let log_issue_from_errlog procname ~clang_method_kind severity err_log ~loc ~node ~ltr ~linters_def_file ~doc_url ~access ~extras exn = let issue_type = (Exceptions.recognize_exception exn).name in if not Config.filtering (* no-filtering takes priority *) || issue_type.IssueType.enabled then let session = (State.get_session () :> int) in - Errlog.log_issue procname ~clang_method_kind severity err_log ~loc ~node_id_key ~session ~ltr + Errlog.log_issue procname ~clang_method_kind severity err_log ~loc ~node ~session ~ltr ~linters_def_file ~doc_url ~access ~extras exn let log_frontend_issue procname severity errlog ~loc ~node_key ~ltr ~linters_def_file ~doc_url exn = - let node_id_key = Errlog.FrontendNode {node_key} in - log_issue_from_errlog procname ~clang_method_kind:None severity errlog ~loc ~node_id_key ~ltr + let node = Errlog.FrontendNode {node_key} in + log_issue_from_errlog procname ~clang_method_kind:None severity errlog ~loc ~node ~ltr ~linters_def_file ~doc_url ~access:None ~extras:None exn -let log_issue_from_summary severity summary ~node_id_key ~loc ?ltr ?linters_def_file ?doc_url - ?access ?extras exn = +let log_issue_from_summary severity summary ~node ~loc ?ltr ?linters_def_file ?doc_url ?access + ?extras exn = let attrs = Summary.get_attributes summary in let procname = attrs.proc_name in let is_java_generated_method = @@ -48,20 +48,19 @@ let log_issue_from_summary severity summary ~node_id_key ~loc ?ltr ?linters_def_ let err_log = Summary.get_err_log summary in let clang_method_kind = Some attrs.clang_method_kind in let ltr = match ltr with None -> State.get_loc_trace () | Some ltr -> ltr in - log_issue_from_errlog procname ~clang_method_kind severity err_log ~loc ~node_id_key ~ltr + let node = Errlog.BackendNode {node} in + log_issue_from_errlog procname ~clang_method_kind severity err_log ~loc ~node ~ltr ~linters_def_file ~doc_url ~access ~extras exn -let log_issue_deprecated severity proc_name ?node_id_key ?loc ?ltr ?linters_def_file ?doc_url - ?access ?extras:_ exn = +let log_issue_deprecated severity proc_name ?node ?loc ?ltr ?linters_def_file ?doc_url ?access + ?extras:_ exn = match Summary.get proc_name with | Some summary -> - let node_id_key = - match node_id_key with None -> State.get_node_id_key () | Some node_id_key -> node_id_key - in + let node = match node with None -> State.get_node () | Some node -> node in let loc = match loc with None -> State.get_loc () | Some loc -> loc in - log_issue_from_summary severity summary ~node_id_key ~loc ?ltr ?linters_def_file ?doc_url - ?access exn + log_issue_from_summary severity summary ~node ~loc ?ltr ?linters_def_file ?doc_url ?access + exn | None -> L.(die InternalError) "Trying to report error on procedure %a, but cannot because no summary exists for this \ @@ -71,8 +70,8 @@ let log_issue_deprecated severity proc_name ?node_id_key ?loc ?ltr ?linters_def_ let log_issue_from_summary_simplified severity summary ~loc ?ltr ?linters_def_file ?doc_url ?access ?extras exn = - let node_id_key = State.get_node_id_key () in - log_issue_from_summary severity summary ~node_id_key ~loc ?ltr ?linters_def_file ?doc_url ?access + let node = State.get_node () in + log_issue_from_summary severity summary ~node ~loc ?ltr ?linters_def_file ?doc_url ?access ?extras exn @@ -82,8 +81,8 @@ let log_warning = log_issue_from_summary_simplified Exceptions.Warning let log_issue_external procname severity ~loc ~ltr ?access exn = let errlog = IssueLog.get_errlog procname in - let node_id_key = State.get_node_id_key () in - log_issue_from_errlog procname ~clang_method_kind:None severity errlog ~loc ~node_id_key ~ltr + let node = Errlog.BackendNode {node= State.get_node ()} in + log_issue_from_errlog procname ~clang_method_kind:None severity errlog ~loc ~node ~ltr ~linters_def_file:None ~doc_url:None ~access ~extras:None exn diff --git a/infer/src/backend/reporting.mli b/infer/src/backend/reporting.mli index c15ad4a90..49d3a9d5f 100644 --- a/infer/src/backend/reporting.mli +++ b/infer/src/backend/reporting.mli @@ -14,8 +14,7 @@ type log_t = -> ?extras:Jsonbug_t.extra -> exn -> unit val log_issue_deprecated : - Exceptions.severity -> Typ.Procname.t -> ?node_id_key:Errlog.node_id_key -> ?loc:Location.t - -> log_t + Exceptions.severity -> Typ.Procname.t -> ?node:Procdesc.Node.t -> ?loc:Location.t -> log_t (** Report an issue in the given procedure. DEPRECATED as it can create race conditions between checkers. Use log_error/warning instead *) diff --git a/infer/src/biabduction/State.ml b/infer/src/biabduction/State.ml index c5c35aea6..e26182554 100644 --- a/infer/src/biabduction/State.ml +++ b/infer/src/biabduction/State.ml @@ -20,7 +20,7 @@ type failure_stats = ; (* number of node failures (i.e. at least one instruction failure) *) mutable node_ok: int ; (* number of node successes (i.e. no instruction failures) *) - mutable first_failure: (Location.t * Errlog.node_id_key * int * Errlog.loc_trace * exn) option + mutable first_failure: (Location.t * Procdesc.Node.t * int * Errlog.loc_trace * exn) option (* exception at the first failure *) } module NodeHash = Procdesc.NodeHash @@ -164,11 +164,6 @@ let mk_find_duplicate_nodes : Procdesc.t -> Procdesc.Node.t -> Procdesc.NodeSet. let get_node_id () = Procdesc.Node.get_id !gs.last_node -let get_node_id_key () = - Errlog.BackendNode - {node_id= Procdesc.Node.get_id !gs.last_node; node_key= Procdesc.Node.compute_key !gs.last_node} - - let get_inst_update pos = let loc = get_loc () in Sil.inst_update loc pos @@ -251,17 +246,17 @@ let mark_instr_ok () = let mark_instr_fail exn = let loc = get_loc () in - let node_id_key = get_node_id_key () in + let node = get_node () in let session = get_session () in let loc_trace = get_loc_trace () in - let fs = get_failure_stats (get_node ()) in + let fs = get_failure_stats node in if is_none fs.first_failure then - fs.first_failure <- Some (loc, node_id_key, (session :> int), loc_trace, exn) ; + fs.first_failure <- Some (loc, node, (session :> int), loc_trace, exn) ; fs.instr_fail <- fs.instr_fail + 1 type log_issue = - Typ.Procname.t -> ?node_id_key:Errlog.node_id_key -> ?loc:Location.t -> ?ltr:Errlog.loc_trace + Typ.Procname.t -> ?node:Procdesc.Node.t -> ?loc:Location.t -> ?ltr:Errlog.loc_trace -> ?linters_def_file:string -> ?doc_url:string -> ?access:string -> ?extras:Jsonbug_t.extra -> exn -> unit @@ -269,11 +264,11 @@ let process_execution_failures (log_issue: log_issue) pname = let do_failure _ fs = (* L.out "Node:%a node_ok:%d node_fail:%d@." Procdesc.Node.pp node fs.node_ok fs.node_fail; *) match (fs.node_ok, fs.first_failure) with - | 0, Some (loc, node_id_key, _, loc_trace, exn) when not Config.debug_exceptions -> + | 0, Some (loc, node, _, loc_trace, exn) when not Config.debug_exceptions -> let error = Exceptions.recognize_exception exn in let desc' = Localise.verbatim_desc ("exception: " ^ error.name.IssueType.unique_id) in let exn' = Exceptions.Analysis_stops (desc', error.ocaml_pos) in - log_issue pname ~loc ~node_id_key ~ltr:loc_trace exn' + log_issue pname ~loc ~node ~ltr:loc_trace exn' | _ -> () in diff --git a/infer/src/biabduction/State.mli b/infer/src/biabduction/State.mli index 0d22fac70..afa5f1e0a 100644 --- a/infer/src/biabduction/State.mli +++ b/infer/src/biabduction/State.mli @@ -37,9 +37,6 @@ val get_loc_trace : unit -> Errlog.loc_trace val get_node : unit -> Procdesc.Node.t (** Get last node seen in symbolic execution *) -val get_node_id_key : unit -> Errlog.node_id_key -(** Get id and key of last node seen in symbolic execution *) - val get_normalized_pre : (Tenv.t -> Prop.normal Prop.t -> Prop.normal Prop.t) -> Prop.normal Prop.t option (** return the normalized precondition extracted form the last prop seen, if any @@ -75,7 +72,7 @@ val mk_find_duplicate_nodes : Procdesc.t -> Procdesc.Node.t -> Procdesc.NodeSet. and normalized (w.r.t. renaming of let - bound ids) list of instructions. *) type log_issue = - Typ.Procname.t -> ?node_id_key:Errlog.node_id_key -> ?loc:Location.t -> ?ltr:Errlog.loc_trace + Typ.Procname.t -> ?node:Procdesc.Node.t -> ?loc:Location.t -> ?ltr:Errlog.loc_trace -> ?linters_def_file:string -> ?doc_url:string -> ?access:string -> ?extras:Jsonbug_t.extra -> exn -> unit