[cost] Include the previous cost's trace in differential traces

Summary:
For complexity issues from O(m) to O(n), we only include the trace of the current complexity O(n). However, this makes it difficult to understand what the original complexity O(m) was. Especially in fixed issues where n=1, we only get a constant cost with no trace attached, so it is difficult to see how the symbol m disappeared.

This diff includes the traces for the previous cost in the cost issues.

Reviewed By: skcho

Differential Revision: D23680360

fbshipit-source-id: 3f2b21b20
master
Ezgi Çiçek 5 years ago committed by Facebook GitHub Bot
parent cd1cfe3487
commit dcad238f11

@ -6,6 +6,7 @@
*)
open! IStd
open! AbstractDomain.Types
(** set of lists of locations for remembering what trace ends have been reported *)
module LocListSet = struct
@ -208,8 +209,20 @@ module CostItem = struct
(pp_degree ~only_bigO:false) curr_item
end
let polynomial_traces = function
| None ->
[]
| Some (Val (_, degree_term)) ->
Polynomials.NonNegativeNonTopPolynomial.get_symbols degree_term
|> List.map ~f:Bounds.NonNegativeBound.make_err_trace
| Some (Below traces) ->
[("", Polynomials.UnreachableTraces.make_err_trace traces)]
| Some (Above traces) ->
[("", Polynomials.TopTraces.make_err_trace traces)]
let issue_of_cost kind CostIssues.{complexity_increase_issue; unreachable_issue; infinite_issue}
~delta ~prev_item
~delta ~prev_item:({CostItem.degree_with_term= prev_degree_with_term} as prev_item)
~curr_item:
({CostItem.cost_item= cost_info; degree_with_term= curr_degree_with_term} as curr_item) =
let file = cost_info.Jsonbug_t.loc.file in
@ -266,25 +279,15 @@ let issue_of_cost kind CostIssues.{complexity_increase_issue; unreachable_issue;
let line = cost_info.Jsonbug_t.loc.lnum in
let column = cost_info.Jsonbug_t.loc.cnum in
let trace =
let polynomial_traces =
match curr_degree_with_term with
| None ->
[]
| Some (Val (_, degree_term)) ->
Polynomials.NonNegativeNonTopPolynomial.get_symbols degree_term
|> List.map ~f:Bounds.NonNegativeBound.make_err_trace
| Some (Below traces) ->
[("", Polynomials.UnreachableTraces.make_err_trace traces)]
| Some (Above traces) ->
[("", Polynomials.TopTraces.make_err_trace traces)]
in
let curr_cost_trace =
let marker_cost_trace msg cost_item =
[ Errlog.make_trace_element 0
{Location.line; col= column; file= source_file}
(Format.asprintf "Updated %a" CostItem.pp_cost_msg curr_item)
(Format.asprintf "%s %a" msg CostItem.pp_cost_msg cost_item)
[] ]
in
("", curr_cost_trace) :: polynomial_traces |> Errlog.concat_traces
(("", marker_cost_trace "Previous" prev_item) :: polynomial_traces prev_degree_with_term)
@ (("", marker_cost_trace "Updated" curr_item) :: polynomial_traces curr_degree_with_term)
|> Errlog.concat_traces
in
let severity = IssueType.Advice in
Some

@ -1,2 +1,2 @@
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f6(java.util.ArrayList):void, 0, [Updated Cost of f6 is 5 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Call to void DiffExample.f5(ArrayList),Modeled call to Collections.sort,{list.length},Call to void DiffExample.f5(ArrayList),Modeled call to Collections.sort]
EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f1(int):void, 0, [Updated Cost of f1 is 3 (degree is 0)]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f6(java.util.ArrayList):void, 0, [Previous Cost of f6 is 7 + 13 ⋅ n + 5 ⋅ n × n (degree is 2),{n},Call to void DiffExample.f2(int),Call to int DiffExample.f1(int),Loop,{n},Call to void DiffExample.f2(int),Loop,Updated Cost of f6 is 5 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Call to void DiffExample.f5(ArrayList),Modeled call to Collections.sort,{list.length},Call to void DiffExample.f5(ArrayList),Modeled call to Collections.sort]
EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f1(int):void, 0, [Previous Cost of f1 is 5 + 5 ⋅ x (degree is 1),{x},Loop,Updated Cost of f1 is 3 (degree is 0)]

@ -1,4 +1,4 @@
INFINITE_EXECUTION_TIME, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Updated Cost of f4 is 6 + 5 ⋅ k (degree is 1),{k},Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Updated Cost of f5 is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort]
EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f2(int):void, 0, [Updated Cost of f2 is 5 + 5 ⋅ x (degree is 1),{x},Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Previous Cost of f4 is 5 (degree is 0),Updated Cost of f4 is 6 + 5 ⋅ k (degree is 1),{k},Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Previous Cost of f5 is 9 + 5 ⋅ n (degree is 1),{n},Call to int DiffExample.f1(int),Loop,Updated Cost of f5 is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort]
EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f2(int):void, 0, [Previous Cost of f2 is 3 (degree is 0),Updated Cost of f2 is 5 + 5 ⋅ x (degree is 1),{x},Loop]

Loading…
Cancel
Save