From ace23a1670dfe0b9efe84ec415d7c31044cf73ca Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Wed, 19 Feb 2020 02:22:16 -0800 Subject: [PATCH] [java] use plain strings instead of mangled for JavaClassName Summary: The way `Mangled.t` is used in `JavaClassName` means that it's always a plain string (we never have a "mangled" part). Remove the indirection and extra allocation. Also, simplify the API by throwing away one function that was used just once and wastefully. Reviewed By: artempyanykh Differential Revision: D19950672 fbshipit-source-id: b61fcba6e --- infer/src/IR/JavaClassName.ml | 9 ++++++++- infer/src/IR/Typ.ml | 5 ----- infer/src/IR/Typ.mli | 3 --- infer/src/checkers/androidFramework.ml | 17 ++++++++--------- .../tests/codetoanalyze/java/racerd/issues.exp | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/infer/src/IR/JavaClassName.ml b/infer/src/IR/JavaClassName.ml index 4b7736779..7cd97de55 100644 --- a/infer/src/IR/JavaClassName.ml +++ b/infer/src/IR/JavaClassName.ml @@ -6,4 +6,11 @@ *) open! IStd -include Mangled + +type t = string [@@deriving compare] + +let from_string str = str + +let to_string str = str + +let pp = String.pp diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 140fa1b74..ce477cf67 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -486,11 +486,6 @@ module Name = struct let from_string name_str = JavaClass (JavaClassName.from_string name_str) - let from_package_class package_name class_name = - if String.equal package_name "" then from_string class_name - else from_string (package_name ^ "." ^ class_name) - - let is_class = function JavaClass _ -> true | _ -> false let java_io_serializable = from_string "java.io.Serializable" diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index d9a47c926..6b9916fe3 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -239,9 +239,6 @@ module Name : sig val from_string : string -> t (** Create a typename from a Java classname in the form "package.class" *) - val from_package_class : string -> string -> t - (** Create a typename from a package name and a class name *) - val is_class : t -> bool (** [is_class name] holds if [name] names a Java class *) diff --git a/infer/src/checkers/androidFramework.ml b/infer/src/checkers/androidFramework.ml index bdce355aa..75fca9592 100644 --- a/infer/src/checkers/androidFramework.ml +++ b/infer/src/checkers/androidFramework.ml @@ -25,15 +25,14 @@ let is_destroy_method pname = false -let is_subtype_package_class tenv tname package classname = - PatternMatch.is_subtype tenv tname (Typ.Name.Java.from_package_class package classname) +let is_autocloseable tenv tname = + PatternMatch.is_subtype_of_str tenv tname "java.lang.AutoCloseable" -let is_autocloseable tenv tname = is_subtype_package_class tenv tname "java.lang" "AutoCloseable" +let is_view tenv tname = PatternMatch.is_subtype_of_str tenv tname "android.view.View" -let is_view tenv tname = is_subtype_package_class tenv tname "android.view" "View" - -let is_fragment tenv tname = - is_subtype_package_class tenv tname "androidx.fragment.app" "Fragment" - || is_subtype_package_class tenv tname "android.app" "Fragment" - || is_subtype_package_class tenv tname "android.support.v4.app" "Fragment" +let is_fragment = + let fragments = + ["androidx.fragment.app.Fragment"; "android.app.Fragment"; "android.support.v4.app.Fragment"] + in + fun tenv tname -> List.exists fragments ~f:(PatternMatch.is_subtype_of_str tenv tname) diff --git a/infer/tests/codetoanalyze/java/racerd/issues.exp b/infer/tests/codetoanalyze/java/racerd/issues.exp index 729213174..82bf133e4 100644 --- a/infer/tests/codetoanalyze/java/racerd/issues.exp +++ b/infer/tests/codetoanalyze/java/racerd/issues.exp @@ -86,7 +86,7 @@ codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership. codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership.writeToNotOwnedInCalleeBad1(codetoanalyze.java.checkers.Obj):void, 157, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [call to void Ownership.writeToFormal(Obj),access to `o.f`] codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership.writeToNotOwnedInCalleeBad2():void, 162, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [call to void Ownership.writeToFormal(Obj),access to `o.f`] codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership.writeToNotOwnedInCalleeBad3(codetoanalyze.java.checkers.Obj):void, 166, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [call to void Ownership.callWriteToFormal(Obj),call to void Ownership.writeToFormal(Obj),access to `o.f`] -codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership.writeToOwnedInCalleeOk2():void, 183, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [,access to `this.field`,,access to `this.field`] +codetoanalyze/java/racerd/Ownership.java, codetoanalyze.java.checkers.Ownership.writeToOwnedInCalleeOk2():void, 183, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [,access to `this.field`,,call to void Ownership.setField(Obj),access to `this.field`] codetoanalyze/java/racerd/RaceWithMainThread.java, codetoanalyze.java.checkers.RaceWithMainThread.conditional2_bad(boolean):void, 130, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [access to `this.ff`] codetoanalyze/java/racerd/RaceWithMainThread.java, codetoanalyze.java.checkers.RaceWithMainThread.conditionalMainThreadWriteBad():void, 219, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [call to void RaceWithMainThread.conditionalMainThreadWrite2(boolean),access to `this.mOnlyWrittenOnMain`] codetoanalyze/java/racerd/RaceWithMainThread.java, codetoanalyze.java.checkers.RaceWithMainThread.conditional_isMainThread_ElseBranch_Bad():void, 152, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [access to `this.ff`]