From d17cbfc15507f3c1ac8dfd103fc7b0a974714663 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Tue, 20 Apr 2021 04:52:25 -0700 Subject: [PATCH] [absint] Add filter_map to MonoMap signature Reviewed By: jvillard Differential Revision: D27879096 fbshipit-source-id: da5aae3ef --- infer/src/absint/AbstractDomain.ml | 6 ++++++ infer/src/cost/ConfigImpactAnalysis.ml | 9 ++++----- infer/src/istd/PrettyPrintable.ml | 2 ++ infer/src/istd/PrettyPrintable.mli | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/infer/src/absint/AbstractDomain.ml b/infer/src/absint/AbstractDomain.ml index 8a4b83ea7..77cf52dfc 100644 --- a/infer/src/absint/AbstractDomain.ml +++ b/infer/src/absint/AbstractDomain.ml @@ -607,6 +607,12 @@ module SafeInvertedMap (Key : PrettyPrintable.PrintableOrderedType) (ValueDomain let filter = M.filter + let filter_map f x = + M.filter_map + (fun k v -> match f k v with Some v when ValueDomain.is_top v -> None | v_opt -> v_opt) + x + + let partition = M.partition let cardinal = M.cardinal diff --git a/infer/src/cost/ConfigImpactAnalysis.ml b/infer/src/cost/ConfigImpactAnalysis.ml index 589b71928..81cd57f9c 100644 --- a/infer/src/cost/ConfigImpactAnalysis.ml +++ b/infer/src/cost/ConfigImpactAnalysis.ml @@ -134,12 +134,11 @@ module UncheckedCalleesCond = struct let filter_known_expensive fields_map = - fold - (fun fields callees acc -> + filter_map + (fun _ callees -> let expensive_callees = UncheckedCallees.filter_known_expensive callees in - if UncheckedCallees.is_empty expensive_callees then acc - else add fields expensive_callees acc ) - fields_map empty + Option.some_if (not (UncheckedCallees.is_empty expensive_callees)) expensive_callees ) + fields_map end module Loc = struct diff --git a/infer/src/istd/PrettyPrintable.ml b/infer/src/istd/PrettyPrintable.ml index 13aec2d18..b70df295b 100644 --- a/infer/src/istd/PrettyPrintable.ml +++ b/infer/src/istd/PrettyPrintable.ml @@ -83,6 +83,8 @@ module type MonoMap = sig val filter : (key -> value -> bool) -> t -> t + val filter_map : (key -> value -> value option) -> t -> t + val partition : (key -> value -> bool) -> t -> t * t val cardinal : t -> int diff --git a/infer/src/istd/PrettyPrintable.mli b/infer/src/istd/PrettyPrintable.mli index 0001cab25..373124edf 100644 --- a/infer/src/istd/PrettyPrintable.mli +++ b/infer/src/istd/PrettyPrintable.mli @@ -85,6 +85,8 @@ module type MonoMap = sig val filter : (key -> value -> bool) -> t -> t + val filter_map : (key -> value -> value option) -> t -> t + val partition : (key -> value -> bool) -> t -> t * t val cardinal : t -> int