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

@ -26,7 +26,6 @@ type t =
{ fields: fields (** non-static fields *)
; statics: fields (** static fields *)
; supers: Typ.Name.t list (** superclasses *)
; subs: Typ.Name.Set.t (** subclasses, initialized after merging type environments *)
; methods: Procname.t list (** methods defined *)
; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *)
; 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
(** 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
(** 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
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 =
(* 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 *)
@ -192,7 +179,6 @@ let store_global tenv =
let tenv = TypenameHashNormalizer.normalize tenv in
L.debug Capture Quiet "Tenv.store: canonicalized tenv has size %d bytes.@."
(Obj.(reachable_words (repr tenv)) * (Sys.word_size / 8)) ;
init_inheritances tenv ;
global_tenv := Some tenv ;
store_to_filename tenv global_tenv_path

@ -40,7 +40,7 @@ class InheritanceTest {
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) {
c.foo(x);
}

Loading…
Cancel
Save