From 3acf5bf2ad5396399a912fe430e6dbb3b6871c9b Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Tue, 18 Dec 2018 10:57:01 -0800 Subject: [PATCH] [Cost] Do not flag variations to/from zero-costing functions Reviewed By: ezgicicek Differential Revision: D13504638 fbshipit-source-id: 9f07b83d7 --- infer/src/backend/Differential.ml | 42 +++++++++++-------- infer/src/bufferoverrun/polynomials.ml | 2 + infer/src/bufferoverrun/polynomials.mli | 2 + .../differential_of_costs_report/fixed.exp | 1 - 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/infer/src/backend/Differential.ml b/infer/src/backend/Differential.ml index 431c872e7..eb148f9b3 100644 --- a/infer/src/backend/Differential.ml +++ b/infer/src/backend/Differential.ml @@ -217,24 +217,32 @@ let of_costs ~(current_costs : Jsonbug_t.costs_report) ~(previous_costs : Jsonbu in let curr_cost_info, curr_cost = max_degree_polynomial current in let _, prev_cost = max_degree_polynomial previous in - let cmp = CostDomain.BasicCost.compare_by_degree curr_cost prev_cost in - let concat_opt l v = match v with Some v' -> v' :: l | None -> l in - if cmp > 0 then - (* introduced *) - let left' = - issue_of_cost curr_cost_info ~delta:`Increased ~prev_cost ~curr_cost |> concat_opt left - in - (left', both, right) - else if cmp < 0 then - (* fixed *) - let right' = - issue_of_cost curr_cost_info ~delta:`Decreased ~prev_cost ~curr_cost - |> concat_opt right - in - (left, both, right') - else - (* preexisting costs are not issues, since their values have not changed *) + if + Config.filtering + && (CostDomain.BasicCost.is_one curr_cost || CostDomain.BasicCost.is_one prev_cost) + then + (* transitions to/from zero costs are obvious, no need to flag them *) (left, both, right) + else + let cmp = CostDomain.BasicCost.compare_by_degree curr_cost prev_cost in + let concat_opt l v = match v with Some v' -> v' :: l | None -> l in + if cmp > 0 then + (* introduced *) + let left' = + issue_of_cost curr_cost_info ~delta:`Increased ~prev_cost ~curr_cost + |> concat_opt left + in + (left', both, right) + else if cmp < 0 then + (* fixed *) + let right' = + issue_of_cost curr_cost_info ~delta:`Decreased ~prev_cost ~curr_cost + |> concat_opt right + in + (left, both, right') + else + (* preexisting costs are not issues, since their values have not changed *) + (left, both, right) | `Left _ | `Right _ -> (* costs available only on one of the two reports are discarded, since no comparison can be made *) (left, both, right) diff --git a/infer/src/bufferoverrun/polynomials.ml b/infer/src/bufferoverrun/polynomials.ml index 9b73399a4..b3ec2b643 100644 --- a/infer/src/bufferoverrun/polynomials.ml +++ b/infer/src/bufferoverrun/polynomials.ml @@ -348,6 +348,8 @@ module NonNegativePolynomial = struct let is_zero = function NonTop p when NonNegativeNonTopPolynomial.is_zero p -> true | _ -> false + let is_one = function NonTop p when NonNegativeNonTopPolynomial.is_one p -> true | _ -> false + let top_lifted_increasing ~f p1 p2 = match (p1, p2) with Top, _ | _, Top -> Top | NonTop p1, NonTop p2 -> NonTop (f p1 p2) diff --git a/infer/src/bufferoverrun/polynomials.mli b/infer/src/bufferoverrun/polynomials.mli index d86a952b1..2a5b9ef12 100644 --- a/infer/src/bufferoverrun/polynomials.mli +++ b/infer/src/bufferoverrun/polynomials.mli @@ -33,6 +33,8 @@ module NonNegativePolynomial : sig val is_zero : t -> bool + val is_one : t -> bool + val of_non_negative_bound : Bounds.NonNegativeBound.t -> t val plus : t -> t -> t diff --git a/infer/tests/build_systems/differential_of_costs_report/fixed.exp b/infer/tests/build_systems/differential_of_costs_report/fixed.exp index b35e05ce4..e69de29bb 100644 --- a/infer/tests/build_systems/differential_of_costs_report/fixed.exp +++ b/infer/tests/build_systems/differential_of_costs_report/fixed.exp @@ -1 +0,0 @@ -PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f2(int):void, 0