From dcdc5ec168a44e2c5c25ddc2c338402d4b50f92d Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Tue, 11 Sep 2018 10:23:37 -0700 Subject: [PATCH] [Perf] Add hash to costs report Reviewed By: mbouaziz Differential Revision: D9769723 fbshipit-source-id: 56dbf41fe --- infer/src/atd/jsonbug.atd | 1 + infer/src/backend/Differential.ml | 3 ++- infer/src/backend/InferPrint.ml | 18 ++++++++---------- infer/src/unit/DifferentialTests.ml | 3 ++- infer/src/unit/DifferentialTestsUtils.ml | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/infer/src/atd/jsonbug.atd b/infer/src/atd/jsonbug.atd index b1b6d9a53..fe655f28c 100644 --- a/infer/src/atd/jsonbug.atd +++ b/infer/src/atd/jsonbug.atd @@ -55,6 +55,7 @@ type hum_info = { } type cost_item = { + hash : string; loc : loc; procedure_id : string; polynomial : string; diff --git a/infer/src/backend/Differential.ml b/infer/src/backend/Differential.ml index 4f495aff6..d382831d5 100644 --- a/infer/src/backend/Differential.ml +++ b/infer/src/backend/Differential.ml @@ -127,7 +127,8 @@ let of_reports ~(current_report : Jsonbug_t.report) ~(previous_report : Jsonbug_ ~(current_costs : Jsonbug_t.costs_report) ~(previous_costs : Jsonbug_t.costs_report) : t = let to_map report = List.fold_left - ~f:(fun map issue -> Map.add_multi map ~key:issue.Jsonbug_t.hash ~data:issue) + ~f:(fun map (issue : Jsonbug_t.jsonbug) -> + Map.add_multi map ~key:issue.Jsonbug_t.hash ~data:issue ) ~init:String.Map.empty report in let fold_aux ~key:_ ~data (left, both, right) = diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index f603af37b..aea7a2855 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -49,9 +49,9 @@ let compute_key (bug_type : string) (proc_name : Typ.Procname.t) (filename : str String.concat ~sep:"|" [base_filename; simple_procedure_name; bug_type] -let compute_hash (severity : string) (bug_type : string) (proc_name : Typ.Procname.t) - (filename : string) (qualifier : string) = - let base_filename = Filename.basename filename in +let compute_hash ~(severity : string) ~(bug_type : string) ~(proc_name : Typ.Procname.t) + ~(file : string) ~(qualifier : string) = + let base_filename = Filename.basename file in let hashable_procedure_name = Typ.Procname.hashable_name proc_name in let location_independent_qualifier = (* Removing the line,column, and infer temporary variable (e.g., n$67) information from the @@ -309,7 +309,7 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct ; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace err_key.severity ; node_key= Option.map ~f: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 + ; hash= compute_hash ~severity ~bug_type ~proc_name ~file ~qualifier ; dotty= error_desc_to_dotty_string err_key.err_desc ; infer_source_loc= json_ml_loc ; bug_type_hum= err_key.err_name.IssueType.hum @@ -353,11 +353,9 @@ module JsonCostsPrinter = MakeJsonListPrinter (struct else None in let cost_item = - { Jsonbug_t.loc= - { Jsonbug_t.file= SourceFile.to_string loc.Location.file - ; lnum= loc.Location.line - ; cnum= loc.Location.col - ; enum= -1 } + let file = SourceFile.to_string loc.Location.file in + { Jsonbug_t.hash= compute_hash ~severity:"" ~bug_type:"" ~proc_name ~file ~qualifier:"" + ; loc= {file; lnum= loc.Location.line; cnum= loc.Location.col; enum= -1} ; procedure_id= Typ.Procname.to_string proc_name ; polynomial= CostDomain.BasicCost.encode post ; hum } @@ -429,7 +427,7 @@ let pp_custom_of_report fmt report fields = List.iter ~f:(pp_custom_of_issue fmt) report -let tests_jsonbug_compare bug1 bug2 = +let tests_jsonbug_compare (bug1 : Jsonbug_t.jsonbug) (bug2 : Jsonbug_t.jsonbug) = let open Jsonbug_t in [%compare: string * string * int * string * Caml.Digest.t] (bug1.file, bug1.procedure, bug1.line - bug1.procedure_start_line, bug1.bug_type, bug1.hash) diff --git a/infer/src/unit/DifferentialTests.ml b/infer/src/unit/DifferentialTests.ml index cf612a0d3..834f22179 100644 --- a/infer/src/unit/DifferentialTests.ml +++ b/infer/src/unit/DifferentialTests.ml @@ -34,7 +34,8 @@ let test_diff_keeps_duplicated_hashes = let hashes_expected = 3 in let hashes_found = List.fold ~init:0 - ~f:(fun acc i -> if String.equal i.Jsonbug_t.hash "2" then acc + 1 else acc) + ~f:(fun acc (i : Jsonbug_t.jsonbug) -> + if String.equal i.Jsonbug_t.hash "2" then acc + 1 else acc ) diff.introduced in let pp_diff fmt (expected, actual) = diff --git a/infer/src/unit/DifferentialTestsUtils.ml b/infer/src/unit/DifferentialTestsUtils.ml index 619ba906e..969acdbea 100644 --- a/infer/src/unit/DifferentialTestsUtils.ml +++ b/infer/src/unit/DifferentialTestsUtils.ml @@ -47,6 +47,6 @@ let pp_diff_of_string_list = pp_diff_of_list ~pp:Format.pp_print_string let pp_diff_of_int_list = pp_diff_of_list ~pp:Format.pp_print_int (* Sort hashes to make things easier to compare *) -let sorted_hashes_of_issues issues = - let hash i = i.Jsonbug_t.hash in +let sorted_hashes_of_issues (issues : Jsonbug_t.report) = + let hash (i : Jsonbug_t.jsonbug) = i.Jsonbug_t.hash in List.sort ~compare:String.compare (List.rev_map ~f:hash issues)