[differential] Refactor to reuse common item description in cost/config_impact items

Reviewed By: ngorogiannis

Differential Revision: D26820770

fbshipit-source-id: 2e4f9ce52
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent f719294d41
commit e9fe04b39f

@ -135,12 +135,11 @@ type cost_info = {
trace : json_trace_item list; trace : json_trace_item list;
} }
type item = {hash: string ; loc: loc ; procedure_name: string ; procedure_id: string }
type cost_item = { type cost_item = {
hash : string; inherit item;
loc : loc;
procedure_name : string;
procedure_id : string;
is_on_ui_thread : bool; is_on_ui_thread : bool;
exec_cost : cost_info; exec_cost : cost_info;
autoreleasepool_size : cost_info; autoreleasepool_size : cost_info;
@ -149,11 +148,7 @@ type cost_item = {
type costs_report = cost_item list type costs_report = cost_item list
type config_impact_item = { type config_impact_item = {
hash : string; inherit item; unchecked_callees : string;
loc : loc;
procedure_name : string;
procedure_id : string;
unchecked_callees : string;
} }
type config_impact_report = config_impact_item list type config_impact_report = config_impact_item list

@ -55,6 +55,31 @@ let dedup (issues : Jsonbug_t.jsonbug list) =
|> snd |> sort_by_location |> snd |> sort_by_location
let create_json_bug ~qualifier ~line ~file ~source_file ~trace ~(item : Jsonbug_t.item)
~(issue_type : IssueType.t) =
{ Jsonbug_j.bug_type= issue_type.unique_id
; qualifier
; severity= IssueType.string_of_severity Advice
; line
; column= item.loc.cnum
; procedure= item.procedure_id
; procedure_start_line= line
; file
; bug_trace= JsonReports.loc_trace_to_jsonbug_record trace Advice
; key= ""
; node_key= None
; hash= item.hash
; dotty= None
; infer_source_loc= None
; bug_type_hum= issue_type.hum
; linters_def_file= None
; doc_url= None
; traceview_id= None
; censored_reason= JsonReports.censored_reason issue_type source_file
; access= None
; extras= None }
module CostsSummary = struct module CostsSummary = struct
module DegreeMap = Caml.Map.Make (Int) module DegreeMap = Caml.Map.Make (Int)
@ -289,29 +314,13 @@ let issue_of_cost kind CostIssues.{complexity_increase_issue; unreachable_issue;
:: polynomial_traces issue_type curr_degree_with_term :: polynomial_traces issue_type curr_degree_with_term
|> Errlog.concat_traces |> Errlog.concat_traces
in in
let severity = IssueType.Advice in let convert (Jsonbug_t.{hash; loc; procedure_name; procedure_id} : Jsonbug_t.cost_item) :
Jsonbug_t.item =
{hash; loc; procedure_name; procedure_id}
in
Some Some
{ Jsonbug_j.bug_type= issue_type.IssueType.unique_id (create_json_bug ~qualifier ~line ~file ~source_file ~trace ~item:(convert cost_info)
; qualifier ~issue_type)
; severity= IssueType.string_of_severity severity
; line
; column
; procedure= cost_info.Jsonbug_t.procedure_id
; procedure_start_line= line
; file
; bug_trace= JsonReports.loc_trace_to_jsonbug_record trace severity
; key= ""
; node_key= None
; hash= cost_info.Jsonbug_t.hash
; dotty= None
; infer_source_loc= None
; bug_type_hum= issue_type.IssueType.hum
; linters_def_file= None
; doc_url= None
; traceview_id= None
; censored_reason= JsonReports.censored_reason issue_type source_file
; access= None
; extras= None }
else None else None
@ -422,31 +431,16 @@ module ConfigImpactItem = struct
if should_report then if should_report then
let qualifier, trace = get_qualifier_trace ~change_type callees in let qualifier, trace = get_qualifier_trace ~change_type callees in
let file = config_impact_item.loc.file in let file = config_impact_item.loc.file in
let source_file = SourceFile.create ~warn_on_error:false file in
let line = config_impact_item.loc.lnum in let line = config_impact_item.loc.lnum in
let convert
(Jsonbug_t.{hash; loc; procedure_name; procedure_id} : Jsonbug_t.config_impact_item) :
Jsonbug_t.item =
{hash; loc; procedure_name; procedure_id}
in
Some Some
{ Jsonbug_j.bug_type= IssueType.config_impact_analysis.unique_id (create_json_bug ~qualifier ~line ~file ~source_file ~trace
; qualifier ~item:(convert config_impact_item) ~issue_type:IssueType.config_impact_analysis)
; severity= IssueType.string_of_severity Advice
; line
; column= config_impact_item.loc.cnum
; procedure= config_impact_item.procedure_id
; procedure_start_line= line
; file
; bug_trace= JsonReports.loc_trace_to_jsonbug_record trace Advice
; key= ""
; node_key= None
; hash= config_impact_item.hash
; dotty= None
; infer_source_loc= None
; bug_type_hum= IssueType.config_impact_analysis.hum
; linters_def_file= None
; doc_url= None
; traceview_id= None
; censored_reason=
SourceFile.create ~warn_on_error:false file
|> JsonReports.censored_reason IssueType.config_impact_analysis
; access= None
; extras= None }
else None else None

Loading…
Cancel
Save