From 895ac9c41cf617d07bf04b7be68be0f5bf7e2512 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 20 Jan 2020 10:17:26 -0800 Subject: [PATCH] [starvation] MayBlock and StrictModelCall events should take procname, not string Summary: Change `MayBlock` and `StrictModeCall` constructors from taking a string to a `Procname.t`, which was the sole source of that string anyway. Reviewed By: ezgicicek Differential Revision: D19465226 fbshipit-source-id: e3ed6ef88 --- infer/src/concurrency/starvation.ml | 6 ++--- infer/src/concurrency/starvationDomain.ml | 30 ++++++++-------------- infer/src/concurrency/starvationDomain.mli | 4 +-- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/infer/src/concurrency/starvation.ml b/infer/src/concurrency/starvation.ml index 348dc249c..498b4b630 100644 --- a/infer/src/concurrency/starvation.ml +++ b/infer/src/concurrency/starvation.ml @@ -630,13 +630,13 @@ let report_on_parallel_composition ~should_report_starvation tenv pdesc pair loc if CriticalPair.can_run_in_parallel pair other_pair then let acquisitions = other_pair.CriticalPair.elem.acquisitions in match other_pair.CriticalPair.elem.event with - | MayBlock (block_descr, sev) + | MayBlock (_, sev) as event when should_report_starvation && Acquisitions.lock_is_held_in_other_thread lock acquisitions -> let error_message = Format.asprintf - "Method %a runs on UI thread and%a, which may be held by another thread which %s." - pname_pp pname Lock.pp_locks lock block_descr + "Method %a runs on UI thread and%a, which may be held by another thread which %a." + pname_pp pname Lock.pp_locks lock Event.describe event in let ltr, loc = make_trace_and_loc () in ReportMap.add_starvation sev tenv pdesc loc ltr error_message report_map diff --git a/infer/src/concurrency/starvationDomain.ml b/infer/src/concurrency/starvationDomain.ml index ecc6d3daf..ca95aae8b 100644 --- a/infer/src/concurrency/starvationDomain.ml +++ b/infer/src/concurrency/starvationDomain.ml @@ -208,18 +208,18 @@ end module Event = struct type t = | LockAcquire of Lock.t - | MayBlock of (string * StarvationModels.severity) - | StrictModeCall of string + | MayBlock of (Procname.t * StarvationModels.severity) + | StrictModeCall of Procname.t | MonitorWait of Lock.t [@@deriving compare] let pp fmt = function | LockAcquire lock -> F.fprintf fmt "LockAcquire(%a)" Lock.pp lock - | MayBlock (msg, sev) -> - F.fprintf fmt "MayBlock(%s, %a)" msg StarvationModels.pp_severity sev - | StrictModeCall msg -> - F.fprintf fmt "StrictModeCall(%s)" msg + | MayBlock (pname, sev) -> + F.fprintf fmt "MayBlock(%a, %a)" Procname.pp pname StarvationModels.pp_severity sev + | StrictModeCall pname -> + F.fprintf fmt "StrictModeCall(%a)" Procname.pp pname | MonitorWait lock -> F.fprintf fmt "MonitorWait(%a)" Lock.pp lock @@ -228,27 +228,17 @@ module Event = struct match elem with | LockAcquire lock -> Lock.pp_locks fmt lock - | MayBlock (msg, _) -> - F.pp_print_string fmt msg - | StrictModeCall msg -> - F.pp_print_string fmt msg + | MayBlock (pname, _) | StrictModeCall pname -> + F.fprintf fmt "calls %a" describe_pname pname | MonitorWait lock -> F.fprintf fmt "calls `wait` on %a" Lock.describe lock let make_acquire lock = LockAcquire lock - let make_call_descr callee = F.asprintf "calls %a" describe_pname callee - - let make_blocking_call callee sev = - let descr = make_call_descr callee in - MayBlock (descr, sev) - - - let make_strict_mode_call callee = - let descr = make_call_descr callee in - StrictModeCall descr + let make_blocking_call callee sev = MayBlock (callee, sev) + let make_strict_mode_call callee = StrictModeCall callee let make_object_wait lock = MonitorWait lock end diff --git a/infer/src/concurrency/starvationDomain.mli b/infer/src/concurrency/starvationDomain.mli index d50a506bf..149a1c864 100644 --- a/infer/src/concurrency/starvationDomain.mli +++ b/infer/src/concurrency/starvationDomain.mli @@ -58,8 +58,8 @@ end module Event : sig type t = | LockAcquire of Lock.t - | MayBlock of (string * StarvationModels.severity) - | StrictModeCall of string + | MayBlock of (Procname.t * StarvationModels.severity) + | StrictModeCall of Procname.t | MonitorWait of Lock.t [@@deriving compare]