From 0def5c4111b7f5567a10bf1f98d99082e8b6ef86 Mon Sep 17 00:00:00 2001 From: jrm Date: Mon, 14 Dec 2015 21:44:42 -0800 Subject: [PATCH] No longer enforce the subtyping rule for the @PerformanceCritical annotation Summary: public The contravariant subtyping rule for the PerformanceCritial annotation was meant to document the code but can be very too verbose on exisiting project. It is also not necessary as we can get this annotation from the supertypes. I am disabling it for now, but keep the code in case we want to revive it at some point in the future. Reviewed By: sblackshear Differential Revision: D2750212 fb-gh-sync-id: 2424281 --- infer/src/checkers/performanceCritical.ml | 14 ++++- .../PerformanceCriticalSubtypingExample.java | 18 ------- .../PerformanceCriticalSubtypingTest.java | 54 ------------------- 3 files changed, 12 insertions(+), 74 deletions(-) delete mode 100644 infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java delete mode 100644 infer/tests/endtoend/java/checkers/PerformanceCriticalSubtypingTest.java 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)); - } - -}