From 96a8b1cf5a689396ed22e37f624cc523ef2ebff5 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Thu, 10 Oct 2019 03:04:10 -0700 Subject: [PATCH] [cost] Add some cost models of IntHashMap Summary: Costs of `IntHashMap.getElement`, `put`, and `remove` are O(1). Reviewed By: ezgicicek Differential Revision: D17829788 fbshipit-source-id: f1f6edfbb --- infer/src/absint/PatternMatch.ml | 4 +++- infer/src/absint/PatternMatch.mli | 3 +++ infer/src/checkers/costModels.ml | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 189c80285..f26cd535e 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -64,10 +64,12 @@ let implements_collections = implements "java.util.Collections" let implements_list = implements "java.util.List" +let implements_xmob_utils class_name = implements ("com.moblica.common.xmob.utils." ^ class_name) + let implements_pseudo_collection t s = implements "android.util.SparseArray" t s || implements "android.util.SparseIntArray" t s - || implements "com.moblica.common.xmob.utils.IntArrayList" t s + || implements_xmob_utils "IntArrayList" t s let implements_enumeration = implements "java.util.Enumeration" diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index 08d5e9179..6f279ccc9 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -91,6 +91,9 @@ val implements_google : string -> Tenv.t -> string -> bool val implements_android : string -> Tenv.t -> string -> bool (** Check whether class implements a class of Android *) +val implements_xmob_utils : string -> Tenv.t -> string -> bool +(** Check whether class implements a class of xmod.utils *) + val supertype_exists : Tenv.t -> (Typ.Name.t -> Typ.Struct.t -> bool) -> Typ.Name.t -> bool (** Holds iff the predicate holds on a supertype of the named type, including the type itself *) diff --git a/infer/src/checkers/costModels.ml b/infer/src/checkers/costModels.ml index 4ac574c2f..af1492aab 100644 --- a/infer/src/checkers/costModels.ml +++ b/infer/src/checkers/costModels.ml @@ -9,6 +9,8 @@ open! IStd module BasicCost = CostDomain.BasicCost open BufferOverrunUtils.ModelEnv +let unit_cost_model _model_env ~ret:_ _inferbo_mem = BasicCost.one + let linear exp ~of_function {integer_type_widths; location} ~ret:_ inferbo_mem = let itv = BufferOverrunSemantics.eval integer_type_widths exp inferbo_mem @@ -164,7 +166,11 @@ module Call = struct $+ capt_exp $+ capt_exp $--> JavaString.substring_no_end ; +PatternMatch.implements_inject "Provider" &:: "get" - <>--> modeled ~of_function:"Provider.get" ] + <>--> modeled ~of_function:"Provider.get" + ; +PatternMatch.implements_xmob_utils "IntHashMap" &:: "" <>--> unit_cost_model + ; +PatternMatch.implements_xmob_utils "IntHashMap" &:: "getElement" <>--> unit_cost_model + ; +PatternMatch.implements_xmob_utils "IntHashMap" &:: "put" <>--> unit_cost_model + ; +PatternMatch.implements_xmob_utils "IntHashMap" &:: "remove" <>--> unit_cost_model ] in merge_dispatchers dispatcher FbCostModels.Call.dispatch end