[ConfigImpact] Loosen compares of field names and ungated callees

Summary:
To avoid too big abstract states due to instantiated templates in C++,
this diff loosens the compare functions of field names and ungated
callees.

Reviewed By: ezgicicek

Differential Revision: D27625775

fbshipit-source-id: e33e9d34c
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent dcda9b39b3
commit fbcf418ea4

@ -15,6 +15,8 @@ type t = Typ.Name.t t_ [@@deriving compare, equal, yojson_of]
let loose_compare = compare_t_ Typ.Name.loose_compare let loose_compare = compare_t_ Typ.Name.loose_compare
let compare_name = compare_t_ Typ.Name.compare_name
let make class_name field_name = {class_name; field_name} let make class_name field_name = {class_name; field_name}
let get_class_name {class_name} = class_name let get_class_name {class_name} = class_name

@ -14,6 +14,9 @@ type t [@@deriving compare, equal, yojson_of]
val loose_compare : t -> t -> int val loose_compare : t -> t -> int
(** Similar to compare, but addresses [CStruct x] and [CppClass x] as equal. *) (** Similar to compare, but addresses [CStruct x] and [CppClass x] as equal. *)
val compare_name : t -> t -> int
(** Similar to compare, but compares only names, except template arguments. *)
val make : Typ.Name.t -> string -> t val make : Typ.Name.t -> string -> t
(** create a field of the given class and fieldname *) (** create a field of the given class and fieldname *)

@ -524,6 +524,51 @@ type t =
let equal = [%compare.equal: t] let equal = [%compare.equal: t]
let rec compare_name x y =
let open ICompare in
match (x, y) with
| ( CSharp {class_name= class_name1; method_name= method_name1}
, CSharp {class_name= class_name2; method_name= method_name2} )
| ( Java {class_name= class_name1; method_name= method_name1}
, Java {class_name= class_name2; method_name= method_name2} )
| ( ObjC_Cpp {class_name= class_name1; method_name= method_name1}
, ObjC_Cpp {class_name= class_name2; method_name= method_name2} ) ->
Typ.Name.compare_name class_name1 class_name2
<*> fun () -> String.compare method_name1 method_name2
| CSharp _, _ ->
-1
| _, CSharp _ ->
1
| Java _, _ ->
-1
| _, Java _ ->
1
| C {name= name1}, C {name= name2} ->
QualifiedCppName.compare_name name1 name2
| C _, _ ->
-1
| _, C _ ->
1
| Linters_dummy_method, Linters_dummy_method ->
0
| Linters_dummy_method, _ ->
-1
| _, Linters_dummy_method ->
1
| Block _, Block _ ->
0
| Block _, _ ->
-1
| _, Block _ ->
1
| ObjC_Cpp _, _ ->
-1
| _, ObjC_Cpp _ ->
1
| WithBlockParameters (x, _), WithBlockParameters (y, _) ->
compare_name x y
(** hash function for procname *) (** hash function for procname *)
let hash = Hashtbl.hash let hash = Hashtbl.hash

@ -231,6 +231,9 @@ val block_of_procname : t -> Block.t
val equal : t -> t -> bool val equal : t -> t -> bool
val compare_name : t -> t -> int
(** Similar to compare, but compares only names, except parameter types and template arguments. *)
val get_class_type_name : t -> Typ.Name.t option val get_class_type_name : t -> Typ.Name.t option
val get_class_name : t -> string option val get_class_name : t -> string option

@ -24,6 +24,8 @@ let strip_template_args quals =
List.map ~f:no_template_name quals List.map ~f:no_template_name quals
let compare_name quals1 quals2 = compare (strip_template_args quals1) (strip_template_args quals2)
let append_template_args_to_last quals ~args = let append_template_args_to_last quals ~args =
match quals with match quals with
| [last; _] when String.contains last '<' -> | [last; _] when String.contains last '<' ->

@ -32,6 +32,9 @@ val strip_template_args : t -> t
- input: std::shared_ptr<int>::shared_ptr<long> - input: std::shared_ptr<int>::shared_ptr<long>
- output: std::shared_ptr::shared_ptr *) - output: std::shared_ptr::shared_ptr *)
val compare_name : t -> t -> int
(** similar to compare, but compares only names, except template arguments *)
val append_template_args_to_last : t -> args:string -> t val append_template_args_to_last : t -> args:string -> t
(** append template arguments to the last qualifier. Fails if qualified name is empty or it already (** append template arguments to the last qualifier. Fails if qualified name is empty or it already
has template args *) has template args *)

@ -374,6 +374,39 @@ module Name = struct
compare x y compare x y
let rec compare_name x y =
let open ICompare in
match (x, y) with
| ( (CStruct name1 | CUnion name1 | CppClass {name= name1})
, (CStruct name2 | CUnion name2 | CppClass {name= name2}) ) ->
QualifiedCppName.compare_name name1 name2
| (CStruct _ | CUnion _ | CppClass _), _ ->
-1
| _, (CStruct _ | CUnion _ | CppClass _) ->
1
| CSharpClass name1, CSharpClass name2 ->
String.compare (CSharpClassName.classname name1) (CSharpClassName.classname name2)
| CSharpClass _, _ ->
-1
| _, CSharpClass _ ->
1
| JavaClass name1, JavaClass name2 ->
String.compare (JavaClassName.classname name1) (JavaClassName.classname name2)
| JavaClass _, _ ->
-1
| _, JavaClass _ ->
1
| ObjcClass (name1, names1), ObjcClass (name2, names2) ->
QualifiedCppName.compare_name name1 name2
<*> fun () -> List.compare compare_name names1 names2
| ObjcClass _, _ ->
-1
| _, ObjcClass _ ->
1
| ObjcProtocol name1, ObjcProtocol name2 ->
QualifiedCppName.compare_name name1 name2
let hash = Hashtbl.hash let hash = Hashtbl.hash
let qual_name = function let qual_name = function

@ -155,6 +155,9 @@ module Name : sig
val loose_compare : t -> t -> int val loose_compare : t -> t -> int
(** Similar to compare, but addresses [CStruct x] and [CppClass x] as equal. *) (** Similar to compare, but addresses [CStruct x] and [CppClass x] as equal. *)
val compare_name : t -> t -> int
(** Similar to compare, but compares only names, except template arguments. *)
val equal : t -> t -> bool val equal : t -> t -> bool
(** Equality for typenames *) (** Equality for typenames *)

@ -41,7 +41,7 @@ module ConfigChecks = AbstractDomain.SafeInvertedMap (ConfigName) (Branch)
module Field = struct module Field = struct
include Fieldname include Fieldname
let compare = Fieldname.loose_compare let compare = Fieldname.compare_name
end end
module Fields = AbstractDomain.FiniteSet (Field) module Fields = AbstractDomain.FiniteSet (Field)
@ -58,8 +58,12 @@ module FieldChecks = struct
end end
module UncheckedCallee = struct module UncheckedCallee = struct
type callee_name = Procname.t
let compare_callee_name = Procname.compare_name
type t = type t =
{ callee: Procname.t { callee: callee_name
; location: Location.t [@compare.ignore] ; location: Location.t [@compare.ignore]
; call_type: call_type [@compare.ignore] } ; call_type: call_type [@compare.ignore] }
[@@deriving compare] [@@deriving compare]

@ -0,0 +1,10 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
let ( <*> ) x y = if x <> 0 then x else y ()

@ -0,0 +1,10 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
val ( <*> ) : int -> (unit -> int) -> int
Loading…
Cancel
Save