From cbe4d9b0fd657dc365db1fd72b195d529acac00e Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 2 Oct 2018 05:49:01 -0700 Subject: [PATCH] [concurrency] drop option type from method matcher records Summary: Option is not needed, just set `default` record to agree with function default arguments. Reviewed By: da319 Differential Revision: D10050463 fbshipit-source-id: e7d13bbd5 --- infer/src/concurrency/ConcurrencyModels.ml | 2 +- infer/src/concurrency/MethodMatcher.ml | 18 +++++++-------- infer/src/concurrency/MethodMatcher.mli | 6 ++--- infer/src/concurrency/StarvationModels.ml | 26 ++++++++++------------ 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/infer/src/concurrency/ConcurrencyModels.ml b/infer/src/concurrency/ConcurrencyModels.ml index 47864940a..8db61fcaf 100644 --- a/infer/src/concurrency/ConcurrencyModels.ml +++ b/infer/src/concurrency/ConcurrencyModels.ml @@ -190,7 +190,7 @@ let ui_matcher_records = (* according to Android documentation, *all* methods of the View class run on UI thread, but let's be a bit conservative and catch all methods that start with "on". https://developer.android.com/reference/android/view/View.html *) - method_prefix= Some true + method_prefix= true ; classname= "android.view.View" ; methods= ["on"] } ] diff --git a/infer/src/concurrency/MethodMatcher.ml b/infer/src/concurrency/MethodMatcher.ml index 449acecd6..c1baa0716 100644 --- a/infer/src/concurrency/MethodMatcher.ml +++ b/infer/src/concurrency/MethodMatcher.ml @@ -43,21 +43,21 @@ let call_matches ?(search_superclasses = true) ?(method_prefix = false) type t = Tenv.t -> Typ.Procname.t -> HilExp.t list -> bool type record = - { search_superclasses: bool option - ; method_prefix: bool option - ; actuals_pred: (HilExp.t list -> bool) option + { search_superclasses: bool + ; method_prefix: bool + ; actuals_pred: HilExp.t list -> bool ; classname: string ; methods: string list } let of_record {search_superclasses; method_prefix; actuals_pred; classname; methods} = - call_matches ?search_superclasses ?method_prefix ?actuals_pred classname methods + call_matches ~search_superclasses ~method_prefix ~actuals_pred classname methods |> Staged.unstage let default = - { search_superclasses= Some true - ; method_prefix= Some false - ; actuals_pred= Some (fun _ -> true) + { search_superclasses= true + ; method_prefix= false + ; actuals_pred= (fun _ -> true) ; classname= "" ; methods= [] } @@ -73,9 +73,9 @@ let of_json top_json = let rec parse_fields assoclist acc = match assoclist with | ("search_superclasses", `Bool b) :: rest -> - {acc with search_superclasses= Some b} |> parse_fields rest + {acc with search_superclasses= b} |> parse_fields rest | ("method_prefix", `Bool b) :: rest -> - {acc with method_prefix= Some b} |> parse_fields rest + {acc with method_prefix= b} |> parse_fields rest | ("classname", `String classname) :: rest -> {acc with classname} |> parse_fields rest | ("methods", `List methodnames) :: rest -> diff --git a/infer/src/concurrency/MethodMatcher.mli b/infer/src/concurrency/MethodMatcher.mli index 5c39959ae..105b0907f 100644 --- a/infer/src/concurrency/MethodMatcher.mli +++ b/infer/src/concurrency/MethodMatcher.mli @@ -28,9 +28,9 @@ val call_matches : which must return [true] for the matcher to return [true]. The default returns [true]. *) type record = - { search_superclasses: bool option - ; method_prefix: bool option - ; actuals_pred: (HilExp.t list -> bool) option + { search_superclasses: bool + ; method_prefix: bool + ; actuals_pred: HilExp.t list -> bool ; classname: string ; methods: string list } diff --git a/infer/src/concurrency/StarvationModels.ml b/infer/src/concurrency/StarvationModels.ml index a3f87871b..faeeafb33 100644 --- a/infer/src/concurrency/StarvationModels.ml +++ b/infer/src/concurrency/StarvationModels.ml @@ -96,10 +96,10 @@ let strict_mode_matcher = let open StarvationDomain.Event in (* NB [default] searches superclasses too. Most of the classes below are final and we don't really want to search superclasses for those that aren't, so for performance, disable that *) - let dont_search_superclasses = {default with search_superclasses= Some false} in + let dont_search_superclasses = {default with search_superclasses= false} in let matcher_records = [ { dont_search_superclasses with - classname= "dalvik.system.BlockGuard$Policy"; methods= ["on"]; method_prefix= Some true } + classname= "dalvik.system.BlockGuard$Policy"; methods= ["on"]; method_prefix= true } ; { dont_search_superclasses with classname= "java.lang.System"; methods= ["gc"; "runFinalization"] } ; {dont_search_superclasses with classname= "java.lang.Runtime"; methods= ["gc"]} @@ -108,7 +108,7 @@ let strict_mode_matcher = ; { dont_search_superclasses with classname= "java.net.Socket" ; methods= [Typ.Procname.Java.constructor_method_name] - ; actuals_pred= Some (function [] | [_] -> false | _ -> true) } + ; actuals_pred= (function [] | [_] -> false | _ -> true) } ; {dont_search_superclasses with classname= "java.net.DatagramSocket"; methods= ["connect"]} ; { dont_search_superclasses with classname= "java.io.File" @@ -147,13 +147,12 @@ let standard_matchers = let high_sev = [ {default with classname= "java.lang.Thread"; methods= ["sleep"]} ; { default with - classname= "java.lang.Object" - ; methods= ["wait"] - ; actuals_pred= Some empty_or_excessive_timeout } + classname= "java.lang.Object"; methods= ["wait"]; actuals_pred= empty_or_excessive_timeout + } ; { default with classname= "java.util.concurrent.CountDownLatch" ; methods= ["await"] - ; actuals_pred= Some empty_or_excessive_timeout } + ; actuals_pred= empty_or_excessive_timeout } (* an IBinder.transact call is an RPC. If the 4th argument (5th counting `this` as the first) is int-zero then a reply is expected and returned from the remote process, thus potentially blocking. If the 4th argument is anything else, we assume a one-way call which doesn't block. *) @@ -161,24 +160,23 @@ let standard_matchers = classname= "android.os.IBinder" ; methods= ["transact"] ; actuals_pred= - Some - (fun actuals -> - List.nth actuals 4 |> Option.value_map ~default:false ~f:HilExp.is_int_zero ) } + (fun actuals -> + List.nth actuals 4 |> Option.value_map ~default:false ~f:HilExp.is_int_zero ) } ; { default with classname= "android.accounts.AccountManager" ; methods= ["setUserData"] - ; search_superclasses= Some false } ] + ; search_superclasses= false } ] in let low_sev = [ { default with classname= "java.util.concurrent.Future" ; methods= ["get"] - ; actuals_pred= Some empty_or_excessive_timeout - ; search_superclasses= Some false } + ; actuals_pred= empty_or_excessive_timeout + ; search_superclasses= false } ; { default with classname= "android.os.AsyncTask" ; methods= ["get"] - ; actuals_pred= Some empty_or_excessive_timeout } ] + ; actuals_pred= empty_or_excessive_timeout } ] in let high_sev_matcher = List.map high_sev ~f:of_record |> of_list in let low_sev_matcher = List.map low_sev ~f:of_record |> of_list in