diff --git a/infer/src/checkers/performanceCritical.ml b/infer/src/checkers/performanceCritical.ml index f6f54b9a5..3a629cb4f 100644 --- a/infer/src/checkers/performanceCritical.ml +++ b/infer/src/checkers/performanceCritical.ml @@ -9,19 +9,29 @@ module L = Logging - +(* Automatically detect if a method is considered as performance critical + by looking for the annotation in the super-types *) let infer_performance_critical_methods = true +(* Warning name when a performance critical method directly or indirectly + calls a method annotatd as expensive *) let calls_expensive_method = "CHECKERS_CALLS_EXPENSIVE_METHOD" +(* Warning name for the subtyping rule: method not annotated as expensive cannot be overridden + by a method annotated as expensive *) let expensive_overrides_unexpensive = "CHECKERS_EXPENSIVE_OVERRIDES_UNANNOTATED" +(* Warning name for the subtyping rule: methods overriding methods annotated as performance critical + should also be annotated as performance critical *) let unannotated_overrides_performance_critical = "CHECKERS_UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL" +(* Triggers report on violation of the sybtyping rule for the performance critical annotation *) +let enforce_performance_critical_subtyping_rule = false + let check_attributes check attributes = let annotated_signature = Annotations.get_annotated_signature attributes in @@ -176,7 +186,7 @@ let check_one_procedure tenv pname pdesc = if expensive then PatternMatch.proc_iter_overridden_methods check_expensive_subtyping_rules tenv pname; - if not performance_critical then + if enforce_performance_critical_subtyping_rule && not performance_critical then PatternMatch.proc_iter_overridden_methods check_performance_critical_subtyping_rules tenv pname; diff --git a/infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java b/infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java deleted file mode 100644 index d30f8d498..000000000 --- a/infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2013 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -package codetoanalyze.java.checkers; - -public class PerformanceCriticalSubtypingExample implements ExpensiveInterfaceExample.I { - - public void m1() {} - - public void m2() {} - -} diff --git a/infer/tests/endtoend/java/checkers/PerformanceCriticalSubtypingTest.java b/infer/tests/endtoend/java/checkers/PerformanceCriticalSubtypingTest.java deleted file mode 100644 index 716d1496a..000000000 --- a/infer/tests/endtoend/java/checkers/PerformanceCriticalSubtypingTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -package endtoend.java.checkers; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class PerformanceCriticalSubtypingTest { - - public static final String SOURCE_FILE = - "infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java"; - - public static final String UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL = - "CHECKERS_UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL"; - - private static InferResults inferResults; - - @BeforeClass - public static void loadResults() throws InterruptedException, IOException { - inferResults = - InferResults.loadCheckersResults(PerformanceCriticalSubtypingTest.class, SOURCE_FILE); - } - - @Test - public void matchErrors() - throws IOException, InterruptedException, InferException { - String[] methods = { - "m1", - }; - assertThat( - "Results should contain " + UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL, - inferResults, - containsExactly( - UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL, - SOURCE_FILE, - methods)); - } - -}