From 84a30c4530f1332409693736a3fb238db0f72c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Thu, 13 May 2021 02:48:46 -0700 Subject: [PATCH] [ConfigImpact] Track the intermediate callers for better readability Summary: Current traces are difficult to read since they keep mentioning the same leaf call at each step. This diff improves the traces by tracking the intermediate callers. Reviewed By: skcho Differential Revision: D28384762 fbshipit-source-id: 78c4cbf7f --- infer/src/cost/ConfigImpactAnalysis.ml | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/infer/src/cost/ConfigImpactAnalysis.ml b/infer/src/cost/ConfigImpactAnalysis.ml index 4486580ec..47dd81c1e 100644 --- a/infer/src/cost/ConfigImpactAnalysis.ml +++ b/infer/src/cost/ConfigImpactAnalysis.ml @@ -78,11 +78,17 @@ module UncheckedCallee = struct ; call_type: call_type [@compare.ignore] } [@@deriving compare] - and call_type = Direct | Indirect of t + and call_type = Direct | Indirect of {unchecked: t; via: Procname.t} let pp_common ~with_location f {callee; location; call_type} = - F.fprintf f "%a is %scalled" Procname.pp callee - (match call_type with Direct -> "" | Indirect _ -> "indirectly ") ; + let pp_call_type f () = + match call_type with + | Direct -> + () + | Indirect {via} -> + F.fprintf f " indirectly via %a" Procname.pp via + in + F.fprintf f "%a is called%a" Procname.pp callee pp_call_type () ; if with_location then F.fprintf f " at %a" Location.pp location @@ -97,25 +103,31 @@ module UncheckedCallee = struct f unchecked_callees - let make ~is_known_expensive callee location = + let make ~is_known_expensive ~callee location = {callee; is_known_expensive; location; call_type= Direct} let is_known_expensive {is_known_expensive} = is_known_expensive - let replace_location_by_call location x = {x with location; call_type= Indirect x} + let replace_location_by_call ~via location x = + {x with location; call_type= Indirect {unchecked= x; via}} + let rec make_err_trace ({location} as x) = let desc = F.asprintf "%a" pp_without_location x in let trace_elem = Errlog.make_trace_element 0 location desc [] in - match x.call_type with Direct -> [trace_elem] | Indirect x -> trace_elem :: make_err_trace x + match x.call_type with + | Direct -> + [trace_elem] + | Indirect {unchecked} -> + trace_elem :: make_err_trace unchecked end module UncheckedCallees = struct include AbstractDomain.FiniteSet (UncheckedCallee) - let replace_location_by_call location x = - map (UncheckedCallee.replace_location_by_call location) x + let replace_location_by_call ~via location x = + map (UncheckedCallee.replace_location_by_call ~via location) x let encode astate = Marshal.to_string astate [] |> Base64.encode_exn @@ -138,8 +150,8 @@ module UncheckedCalleesCond = struct fields_map - let replace_location_by_call location fields_map = - map (UncheckedCallees.replace_location_by_call location) fields_map + let replace_location_by_call ~via location fields_map = + map (UncheckedCallees.replace_location_by_call ~via location) fields_map let has_known_expensive_callee fields_map = @@ -539,7 +551,7 @@ module Dom = struct dispatch tenv pname args - let call tenv analyze_dependency ~(instantiated_cost : CostInstantiate.instantiated_cost) callee + let call tenv analyze_dependency ~(instantiated_cost : CostInstantiate.instantiated_cost) ~callee args location ({config_checks; field_checks; unchecked_callees; unchecked_callees_cond} as astate) = let join_unchecked_callees new_unchecked_callees new_unchecked_callees_cond = @@ -587,7 +599,7 @@ module Dom = struct (* If callee is known expensive by model, add callee's name. *) join_unchecked_callees (UncheckedCallees.singleton - (UncheckedCallee.make ~is_known_expensive:true callee location)) + (UncheckedCallee.make ~is_known_expensive:true ~callee location)) UncheckedCalleesCond.empty | None -> ( match callee_summary with @@ -607,8 +619,9 @@ module Dom = struct in (* If callee's summary is not leaf, use it. *) join_unchecked_callees - (UncheckedCallees.replace_location_by_call location callee_summary) - (UncheckedCalleesCond.replace_location_by_call location callee_summary_cond) + (UncheckedCallees.replace_location_by_call ~via:callee location callee_summary) + (UncheckedCalleesCond.replace_location_by_call location ~via:callee + callee_summary_cond) | None when Procname.is_objc_init callee || is_unmodeled_call -> (* If callee is unknown ObjC initializer or has no cost model, ignore it. *) astate @@ -616,7 +629,7 @@ module Dom = struct (* Otherwise, add callee's name. *) join_unchecked_callees (UncheckedCallees.singleton - (UncheckedCallee.make ~is_known_expensive:false callee location)) + (UncheckedCallee.make ~is_known_expensive:false ~callee location)) UncheckedCalleesCond.empty ) else astate end @@ -724,7 +737,7 @@ module TransferFunctions = struct {loc= location; pname= callee; node= CFG.Node.to_instr idx node; args; ret} in let instantiated_cost = get_instantiated_cost call in - Dom.call tenv analyze_dependency ~instantiated_cost callee args location astate + Dom.call tenv analyze_dependency ~instantiated_cost ~callee args location astate |> add_ret analyze_dependency ret_id callee ) | Prune (e, _, _, _) -> Dom.prune e astate