[cost] Remove dead field Struct.subs

Summary:
This diff removes a dead field `Struct.subs`, which was used in
heuristics finding methods from sub-classes.

Reviewed By: ezgicicek

Differential Revision: D22945346

fbshipit-source-id: 4b3bf0093
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent 3573e0d202
commit 270918fea7

@ -43,7 +43,6 @@ type t =
{ fields: fields (** non-static fields *) { fields: fields (** non-static fields *)
; statics: fields (** static fields *) ; statics: fields (** static fields *)
; supers: Typ.Name.t list (** superclasses *) ; supers: Typ.Name.t list (** superclasses *)
; subs: Typ.Name.Set.t (** subclasses, initialized after merging type environments *)
; methods: Procname.t list (** methods defined *) ; methods: Procname.t list (** methods defined *)
; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *) ; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *)
; annots: Annot.Item.t (** annotations *) ; annots: Annot.Item.t (** annotations *)
@ -58,8 +57,8 @@ let pp_field pe f (field_name, typ, ann) =
let pp pe name f let pp pe name f
({fields; statics; subs; supers; methods; exported_objc_methods; annots; java_class_info; dummy}[@warning ({fields; statics; supers; methods; exported_objc_methods; annots; java_class_info; dummy}[@warning
"+9"]) "+9"])
= =
let pp_field pe f (field_name, typ, ann) = let pp_field pe f (field_name, typ, ann) =
F.fprintf f "@;<0 2>%a %a %a" (Typ.pp_full pe) typ Fieldname.pp field_name Annot.Item.pp ann F.fprintf f "@;<0 2>%a %a %a" (Typ.pp_full pe) typ Fieldname.pp field_name Annot.Item.pp ann
@ -76,7 +75,6 @@ let pp pe name f
@[<v>fields: {@[<v>%a@]}@,\ @[<v>fields: {@[<v>%a@]}@,\
statics: {@[<v>%a@]}@,\ statics: {@[<v>%a@]}@,\
supers: {@[<v>%a@]}@,\ supers: {@[<v>%a@]}@,\
subs: {@[<v>%a@]}@,\
methods: {@[<v>%a@]}@,\ methods: {@[<v>%a@]}@,\
exported_obj_methods: {@[<v>%a@]}@,\ exported_obj_methods: {@[<v>%a@]}@,\
annots: {@[<v>%a@]}@,\ annots: {@[<v>%a@]}@,\
@ -89,8 +87,6 @@ let pp pe name f
statics statics
(seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n)) (seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n))
supers supers
(seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n))
(Typ.Name.Set.elements subs)
(seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m)) (seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
methods methods
(seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m)) (seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
@ -105,16 +101,14 @@ let internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods
; methods= [] ; methods= []
; exported_objc_methods= [] ; exported_objc_methods= []
; supers= [] ; supers= []
; subs= Typ.Name.Set.empty
; annots= Annot.Item.empty ; annots= Annot.Item.empty
; java_class_info= None ; java_class_info= None
; dummy= false } ; dummy= false }
in in
let mk_struct_ ?(default = default_) ?(fields = default.fields) ?(statics = default.statics) let mk_struct_ ?(default = default_) ?(fields = default.fields) ?(statics = default.statics)
?(methods = default.methods) ?(exported_objc_methods = default.exported_objc_methods) ?(methods = default.methods) ?(exported_objc_methods = default.exported_objc_methods)
?(supers = default.supers) ?(subs = default.subs) ?(annots = default.annots) ?(supers = default.supers) ?(annots = default.annots) ?(dummy = default.dummy) () =
?(dummy = default.dummy) () = {fields; statics; methods; exported_objc_methods; supers; annots; java_class_info; dummy}
{fields; statics; methods; exported_objc_methods; supers; subs; annots; java_class_info; dummy}
in in
mk_struct_ ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots ?dummy () mk_struct_ ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots ?dummy ()
@ -188,8 +182,6 @@ let get_field_type_and_annotation ~lookup field_name_to_lookup typ =
let is_dummy {dummy} = dummy let is_dummy {dummy} = dummy
let add_sub sub x = {x with subs= Typ.Name.Set.add sub x.subs}
let merge_lists ~compare ~newer ~current = let merge_lists ~compare ~newer ~current =
let equal x y = Int.equal 0 (compare x y) in let equal x y = Int.equal 0 (compare x y) in
match (newer, current) with match (newer, current) with

@ -26,7 +26,6 @@ type t =
{ fields: fields (** non-static fields *) { fields: fields (** non-static fields *)
; statics: fields (** static fields *) ; statics: fields (** static fields *)
; supers: Typ.Name.t list (** superclasses *) ; supers: Typ.Name.t list (** superclasses *)
; subs: Typ.Name.Set.t (** subclasses, initialized after merging type environments *)
; methods: Procname.t list (** methods defined *) ; methods: Procname.t list (** methods defined *)
; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *) ; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *)
; annots: Annot.Item.t (** annotations *) ; annots: Annot.Item.t (** annotations *)
@ -70,9 +69,6 @@ val get_field_type_and_annotation :
lookup:lookup -> Fieldname.t -> Typ.t -> (Typ.t * Annot.Item.t) option lookup:lookup -> Fieldname.t -> Typ.t -> (Typ.t * Annot.Item.t) option
(** Return the type of the field [fn] and its annotation, None if [typ] has no field named [fn] *) (** Return the type of the field [fn] and its annotation, None if [typ] has no field named [fn] *)
val add_sub : Typ.Name.t -> t -> t
(** Add a subclass to the struct type *)
val merge : Typ.Name.t -> newer:t -> current:t -> t val merge : Typ.Name.t -> newer:t -> current:t -> t
(** best effort directed merge of two structs for the same typename *) (** best effort directed merge of two structs for the same typename *)

@ -171,19 +171,6 @@ let store_to_filename tenv tenv_filename =
if Config.debug_mode then store_debug_file tenv tenv_filename if Config.debug_mode then store_debug_file tenv tenv_filename
let init_inheritances tenv =
let sub_to_supers =
TypenameHash.fold (fun sub {Struct.supers} acc -> (sub, supers) :: acc) tenv []
in
List.iter sub_to_supers ~f:(fun (sub, supers) ->
List.iter supers ~f:(fun super ->
(* Ignore the super class of java.lang.Object since its sub-classes are too many, which
harms the analysis precision. *)
if not (Typ.Name.equal super Typ.Name.Java.java_lang_object) then
Option.iter (lookup tenv super) ~f:(fun super_struct ->
Struct.add_sub sub super_struct |> TypenameHash.replace tenv super ) ) )
let store_global tenv = let store_global tenv =
(* update in-memory global tenv for later uses by this process, e.g. in single-core mode the (* update in-memory global tenv for later uses by this process, e.g. in single-core mode the
frontend and backend run in the same process *) frontend and backend run in the same process *)
@ -192,7 +179,6 @@ let store_global tenv =
let tenv = TypenameHashNormalizer.normalize tenv in let tenv = TypenameHashNormalizer.normalize tenv in
L.debug Capture Quiet "Tenv.store: canonicalized tenv has size %d bytes.@." L.debug Capture Quiet "Tenv.store: canonicalized tenv has size %d bytes.@."
(Obj.(reachable_words (repr tenv)) * (Sys.word_size / 8)) ; (Obj.(reachable_words (repr tenv)) * (Sys.word_size / 8)) ;
init_inheritances tenv ;
global_tenv := Some tenv ; global_tenv := Some tenv ;
store_to_filename tenv global_tenv_path store_to_filename tenv global_tenv_path

@ -40,7 +40,7 @@ class InheritanceTest {
public void foo(int x) {} public void foo(int x) {}
} }
/* By heuristics, [Impl1.foo] is selected. It is hard to say good or bad. */ /* As of now, we cannot find implementations of interface methods. */
public void call_interface_method2_linear_FN(MyInterface2 c, int x) { public void call_interface_method2_linear_FN(MyInterface2 c, int x) {
c.foo(x); c.foo(x);
} }

Loading…
Cancel
Save