[cost] Add an option printing/suppressing function pointers in cost

Summary:
This diff adds an option hiding function pointers in costs to users: `cost-suppress-func-ptr` is
true by default.

Reviewed By: ezgicicek

Differential Revision: D24448212

fbshipit-source-id: 88f6b5ea1
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent adcad19ee1
commit 198c700e87

@ -72,6 +72,10 @@ OPTIONS
Activates: Enable cost and disable all other checkers (Conversely:
--no-cost-only)
--no-cost-suppress-func-ptr
Deactivates: Suppress printing function pointers in cost reports
(Conversely: --cost-suppress-func-ptr)
--custom-symbols json
Specify named lists of symbols available to rules

@ -279,6 +279,10 @@ OPTIONS
Activates: Enable cost and disable all other checkers (Conversely:
--no-cost-only) See also infer-analyze(1).
--no-cost-suppress-func-ptr
Deactivates: Suppress printing function pointers in cost reports
(Conversely: --cost-suppress-func-ptr) See also infer-analyze(1).
--cost-tests-only-autoreleasepool
Activates: [EXPERIMENTAL] Report only autoreleasepool size results
in cost tests (Conversely: --no-cost-tests-only-autoreleasepool)

@ -279,6 +279,10 @@ OPTIONS
Activates: Enable cost and disable all other checkers (Conversely:
--no-cost-only) See also infer-analyze(1).
--no-cost-suppress-func-ptr
Deactivates: Suppress printing function pointers in cost reports
(Conversely: --cost-suppress-func-ptr) See also infer-analyze(1).
--cost-tests-only-autoreleasepool
Activates: [EXPERIMENTAL] Report only autoreleasepool size results
in cost tests (Conversely: --no-cost-tests-only-autoreleasepool)

@ -945,6 +945,12 @@ and costs_previous =
"Costs report of the base revision to use for comparison"
and cost_suppress_func_ptr =
CLOpt.mk_bool ~default:true ~long:"cost-suppress-func-ptr"
~in_help:InferCommand.[(Analyze, manual_generic)]
"Suppress printing function pointers in cost reports"
and cost_tests_only_autoreleasepool =
CLOpt.mk_bool ~long:"cost-tests-only-autoreleasepool"
~in_help:InferCommand.[(Report, manual_generic); (ReportDiff, manual_generic)]
@ -2753,6 +2759,8 @@ and cost_scuba_logging = !cost_scuba_logging
and costs_previous = !costs_previous
and cost_suppress_func_ptr = !cost_suppress_func_ptr
and cost_tests_only_autoreleasepool = !cost_tests_only_autoreleasepool
and cxx = !cxx

@ -232,6 +232,8 @@ val cost_scuba_logging : bool
val costs_previous : string option
val cost_suppress_func_ptr : bool
val cost_tests_only_autoreleasepool : bool
val cxx : bool

@ -132,6 +132,8 @@ module NonNegativeNonTopPolynomial = struct
let pp = pp_hum ~hum:true
let is_func_ptr = function FuncPtr _ -> true | NonNegativeBoundWithDegreeKind _ -> false
end
module M = struct
@ -513,23 +515,20 @@ module NonNegativeNonTopPolynomial = struct
Above s_trace
let rec is_zero_degree_poly {const; terms} =
NonNegativeInt.is_zero const && is_zero_degree_terms terms
and is_zero_degree_terms terms =
M.for_all (fun key v -> Key.is_func_ptr key || is_zero_degree_poly v) terms
(** Emit a pair (d,t) where d is the degree of the polynomial and t is the first term with such
degree. When calculating the degree, it ignores symbols of function pointer, so they are
addressed as if zero cost. *)
let degree_with_term {poly; autoreleasepool_trace} =
let rec is_func_ptr_poly {const; terms} =
NonNegativeInt.is_zero const
&& M.for_all
(fun key v ->
match key with
| FuncPtr _ ->
true
| NonNegativeBoundWithDegreeKind _ ->
is_func_ptr_poly v )
terms
in
let rec degree_with_term_poly ({terms} as poly) =
if is_func_ptr_poly poly then (Degree.zero, true, poly)
if is_zero_degree_poly poly then (Degree.zero, true, poly)
else
M.fold
(fun t p cur_max ->
@ -584,19 +583,28 @@ module NonNegativeNonTopPolynomial = struct
in
( M.fold
(fun s p print_plus ->
pp_sub ~hum ~print_plus (add_symb s symbs) fmt p ;
true )
if Config.cost_suppress_func_ptr && (Key.is_func_ptr s || is_zero_degree_poly p) then
print_plus
else (
pp_sub ~hum ~print_plus (add_symb s symbs) fmt p ;
true ) )
terms print_plus
: bool )
|> ignore
in
fun ~hum fmt {const; terms} ->
let const_not_zero = not (NonNegativeInt.is_zero const) in
if const_not_zero || M.is_empty terms then NonNegativeInt.pp fmt const ;
if
const_not_zero || M.is_empty terms
|| (Config.cost_suppress_func_ptr && is_zero_degree_terms terms)
then NonNegativeInt.pp fmt const ;
( M.fold
(fun s p print_plus ->
pp_sub ~hum ~print_plus ((s, PositiveInt.one), []) fmt p ;
true )
if Config.cost_suppress_func_ptr && (Key.is_func_ptr s || is_zero_degree_poly p) then
print_plus
else (
pp_sub ~hum ~print_plus ((s, PositiveInt.one), []) fmt p ;
true ) )
terms const_not_zero
: bool )
|> ignore

@ -20,10 +20,12 @@ $(CURRENT_REPORT):
$(QUIET)$(COPY) src/DiffExample.current.java src/DiffExample.java
$(QUIET)$(COPY) src/DiffExampleUIThread.current.java src/DiffExampleUIThread.java
$(QUIET)$(call silent_on_success,Testing Cost Differential: current,\
$(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- $(JAVAC) -cp $(CLASSPATH) $(COPIED))
$(INFER_BIN) --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(CURRENT_DIR) \
-- $(JAVAC) -cp $(CLASSPATH) $(COPIED))
$(PREVIOUS_REPORT):
$(QUIET)$(COPY) src/DiffExample.previous.java src/DiffExample.java
$(QUIET)$(COPY) src/DiffExampleUIThread.previous.java src/DiffExampleUIThread.java
$(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\
$(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- $(JAVAC) -cp $(CLASSPATH) $(COPIED))
$(INFER_BIN) --debug --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(PREVIOUS_DIR) \
-- $(JAVAC) -cp $(CLASSPATH) $(COPIED))

@ -20,9 +20,11 @@ $(CURRENT_REPORT) $(PREVIOUS_REPORT): $(OBJC_DEPS)
$(CURRENT_REPORT):
$(QUIET)$(COPY) src/DiffBlock.current.m src/DiffBlock.m
$(QUIET)$(call silent_on_success,Testing Cost Differential: current,\
$(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- clang $(CLANG_OPTIONS) $(COPIED))
$(INFER_BIN) --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(CURRENT_DIR) \
-- clang $(CLANG_OPTIONS) $(COPIED))
$(PREVIOUS_REPORT):
$(QUIET)$(COPY) src/DiffBlock.previous.m src/DiffBlock.m
$(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\
$(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- clang $(CLANG_OPTIONS) $(COPIED))
$(INFER_BIN) --debug --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(PREVIOUS_DIR) \
-- clang $(CLANG_OPTIONS) $(COPIED))

@ -6,7 +6,8 @@
TESTS_DIR = ../../..
CLANG_OPTIONS = -c
INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR)
INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR) \
--no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-issues-tests

@ -8,7 +8,8 @@ TESTS_DIR = ../../..
# see explanations in cpp/biabduction/Makefile for the custom isystem
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(CLANG_INCLUDES)/c++/v1/ -c
INFER_OPTIONS = --cost-only --ml-buckets cpp --no-filtering --debug-exceptions \
--project-root $(TESTS_DIR) --report-force-relative-path --debug
--project-root $(TESTS_DIR) --report-force-relative-path --debug \
--no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-issues-tests

@ -5,7 +5,8 @@
TESTS_DIR = ../../..
INFER_OPTIONS = --cost-only --no-inclusive-cost --bufferoverrun --debug-exceptions
INFER_OPTIONS = --cost-only --no-inclusive-cost --bufferoverrun --debug-exceptions \
--no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-issues-tests
SOURCES = $(wildcard *.java)

@ -5,7 +5,7 @@
TESTS_DIR = ../../..
INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions
INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-issues-tests
SOURCES = $(wildcard *.java)

@ -7,7 +7,8 @@ TESTS_DIR = ../../..
CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS)
INFER_OPTIONS = --cost-only --debug-exceptions --project-root $(TESTS_DIR) \
--report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX)
--report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) \
--no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-tests-only-autoreleasepool --cost-issues-tests

@ -7,7 +7,8 @@ TESTS_DIR = ../../..
CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS)
INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR) \
--report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX)
--report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) \
--no-cost-suppress-func-ptr
INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-issues-tests

Loading…
Cancel
Save