[eradicate] remove the unused code to do the nullability inferrence

Summary: This feature is not currently used and crashes when enabled.

Reviewed By: ngorogiannis

Differential Revision: D9805110

fbshipit-source-id: db405c79e
master
Jeremy Dubreil 6 years ago committed by Facebook Github Bot
parent 817f83972c
commit 3c220f7dbb

@ -86,50 +86,6 @@ let file_modified_time ?(symlink = false) fname =
with Unix.Unix_error _ -> L.(die InternalError) "File %s does not exist." fname
let read_whole_file fd = In_channel.input_all (Unix.in_channel_of_descr fd)
(** Update the file contents with the update function provided.
If the directory does not exist, it is created.
If the file does not exist, it is created, and update is given the empty string.
A lock is used to allow write attempts in parallel. *)
let update_file_with_lock dir fname update =
let reset_file fd =
let n = Unix.lseek fd 0L ~mode:Unix.SEEK_SET in
if n <> 0L then (
L.internal_error "reset_file: lseek fail@." ;
assert false )
in
Utils.create_dir dir ;
let path = Filename.concat dir fname in
let fd = Unix.openfile path ~mode:Unix.[O_CREAT; O_SYNC; O_RDWR] ~perm:0o640 in
Unix.lockf fd ~mode:Unix.F_LOCK ~len:0L ;
let buf = read_whole_file fd in
reset_file fd ;
let str = update buf in
let i = Unix.write fd ~buf:(Bytes.of_string str) ~pos:0 ~len:(String.length str) in
if Int.equal i (String.length str) then (
Unix.lockf fd ~mode:Unix.F_ULOCK ~len:0L ;
Unix.close fd )
else (
L.internal_error "@\nsave_with_lock: fail on path: %s@." path ;
assert false )
(** Read a file using a lock to allow write attempts in parallel. *)
let read_file_with_lock dir fname =
let path = Filename.concat dir fname in
try
let fd = Unix.openfile path ~mode:Unix.[O_RSYNC; O_RDONLY] ~perm:0o646 in
try
Unix.lockf fd ~mode:Unix.F_RLOCK ~len:0L ;
let buf = read_whole_file fd in
Unix.lockf fd ~mode:Unix.F_ULOCK ~len:0L ;
Unix.close fd ;
Some buf
with Unix.Unix_error _ -> L.(die ExternalError) "read_file_with_lock: Unix error"
with Unix.Unix_error _ -> None
(** {2 Results Directory} *)
module Results_dir = struct

@ -78,15 +78,6 @@ val source_dir_get_internal_file : source_dir -> string -> filename
val source_dir_from_source_file : SourceFile.t -> source_dir
(** get the source directory corresponding to a source file *)
val read_file_with_lock : string -> string -> string option
(** Read a file using a lock to allow write attempts in parallel. *)
val update_file_with_lock : string -> string -> (string -> string) -> unit
(** Update the file contents with the update function provided.
If the directory does not exist, it is created.
If the file does not exist, it is created, and update is given the empty string.
A lock is used to allow write attempts in parallel. *)
val is_source_file : string -> bool
(** Check if a path is a Java, C, C++ or Objectve C source file according to the file extention *)

@ -105,9 +105,3 @@ let mark proc_name ann asig (b, bs) =
combine asig.params bs
in
{ret= ret'; params= params'}
let mark_return ann asig =
let ia, t = asig.ret in
let ret' = (mark_ia ann ia true, t) in
{asig with ret= ret'}

@ -22,9 +22,6 @@ val param_has_annot : (Annot.Item.t -> bool) -> Pvar.t -> t -> bool
val mark : Typ.Procname.t -> annotation -> t -> bool * bool list -> t
(** Mark the annotated signature with the given annotation map. *)
val mark_return : annotation -> t -> t
(** Mark the return of the annotated signature with the given annotation. *)
val get : ProcAttributes.t -> t
(** Get a method signature with annotations from a proc_attributes. *)

@ -21,9 +21,7 @@ let get_field_annotation tenv fn typ =
let ia' =
(* TODO (t4968422) eliminate not !Config.eradicate check by marking fields as nullified *)
(* outside of Eradicate in some other way *)
if
(Models.Inference.enabled || not Config.eradicate) && Models.Inference.field_is_marked fn
then AnnotatedSignature.mk_ia AnnotatedSignature.Nullable ia
if not Config.eradicate then AnnotatedSignature.mk_ia AnnotatedSignature.Nullable ia
else ia
in
Some (t, ia')
@ -211,11 +209,10 @@ let check_field_assignment tenv find_canonical_duplicate curr_pdesc node instr_r
true )
&& not (field_is_mutable ())
in
if should_report_nullable || should_report_absent then (
( if should_report_nullable || should_report_absent then
let ann =
if should_report_nullable then AnnotatedSignature.Nullable else AnnotatedSignature.Present
in
if Models.Inference.enabled then Models.Inference.field_add_nullable_annotation fname ;
let origin_descr = TypeAnnotation.descr_origin ta_rhs in
report_error tenv find_canonical_duplicate
(TypeErr.Field_annotation_inconsistent (ann, fname, origin_descr))
@ -283,7 +280,6 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_pname cu
&& not (Typ.Fieldname.Java.is_outer_instance fn)
in
if should_check_field_initialization then (
if Models.Inference.enabled then Models.Inference.field_add_nullable_annotation fn ;
(* Check if field is missing annotation. *)
if
(not (nullable_annotated || nonnull_annotated))
@ -344,8 +340,6 @@ let check_return_annotation tenv find_canonical_duplicate curr_pdesc ret_range
let return_over_annotated =
(not final_nullable) && ret_annotated_nullable && Config.eradicate_return_over_annotated
in
if return_not_nullable && Models.Inference.enabled then
Models.Inference.proc_mark_return_nullable curr_pname ;
( if return_not_nullable || return_value_not_present then
let ann =
if return_not_nullable then AnnotatedSignature.Nullable else AnnotatedSignature.Present
@ -399,7 +393,6 @@ type resolved_param =
let check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_attributes
resolved_params loc instr_ref : unit =
let callee_pname = callee_attributes.ProcAttributes.proc_name in
let tot_param_num = List.length resolved_params in
let check {num= param_num; formal= s1, ta1, t1; actual= orig_e2, ta2} =
let report ann =
let description =
@ -421,9 +414,7 @@ let check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_a
let b2 = TypeAnnotation.get_value ann ta2 in
match (ann, b1, b2) with
| AnnotatedSignature.Nullable, false, true ->
report ann ;
if Models.Inference.enabled then
Models.Inference.proc_add_parameter_nullable callee_pname param_num tot_param_num
report ann
| AnnotatedSignature.Present, true, false ->
report ann
| _ ->

@ -8,100 +8,9 @@
open! IStd
module Hashtbl = Caml.Hashtbl
open ModelTables
module L = Logging
(** Module for standard library models. *)
(** Module for inference of parameter and return annotations. *)
module Inference = struct
let enabled = false
let get_dir () = Filename.concat Config.results_dir "eradicate"
let field_get_dir_fname fn =
let fname = Typ.Fieldname.to_string fn in
(get_dir (), fname)
let field_is_marked fn =
let dir, fname = field_get_dir_fname fn in
DB.read_file_with_lock dir fname <> None
let proc_get_ret_dir_fname pname =
let fname = Typ.Procname.to_filename pname ^ "_ret" in
(get_dir (), fname)
let proc_get_param_dir_fname pname =
let fname = Typ.Procname.to_filename pname ^ "_params" in
(get_dir (), fname)
let update_count_str s_old =
let n =
if String.is_empty s_old then 0
else try int_of_string s_old with Failure _ -> L.die InternalError "int_of_string %s" s_old
in
string_of_int (n + 1)
let update_boolvec_str s_ size index bval =
let s = if String.is_empty s_ then Bytes.make size '0' else Bytes.of_string s_ in
Bytes.set s index (if bval then '1' else '0') ;
Bytes.to_string s
let mark_file update_str dir fname =
DB.update_file_with_lock dir fname update_str ;
match DB.read_file_with_lock dir fname with
| Some buf ->
L.internal_error "Read %s: %s@." fname buf
| None ->
L.internal_error "Read %s: None@." fname
let mark_file_count = mark_file update_count_str
(** Mark the field @Nullable indirectly by writing to a global file. *)
let field_add_nullable_annotation fn =
let dir, fname = field_get_dir_fname fn in
mark_file_count dir fname
(** Mark the return type @Nullable indirectly by writing to a global file. *)
let proc_mark_return_nullable pn =
let dir, fname = proc_get_ret_dir_fname pn in
mark_file_count dir fname
(** Return true if the return type is marked @Nullable in the global file *)
let proc_return_is_marked pname =
let dir, fname = proc_get_ret_dir_fname pname in
DB.read_file_with_lock dir fname <> None
(** Mark the n-th parameter @Nullable indirectly by writing to a global file. *)
let proc_add_parameter_nullable pn n tot =
let dir, fname = proc_get_param_dir_fname pn in
let update_str s = update_boolvec_str s tot n true in
mark_file update_str dir fname
(** Return None if the parameters are not marked, or a vector of marked parameters *)
let proc_parameters_marked pn =
let dir, fname = proc_get_param_dir_fname pn in
match DB.read_file_with_lock dir fname with
| None ->
None
| Some buf ->
let boolvec = ref [] in
String.iter ~f:(fun c -> boolvec := Char.equal c '1' :: !boolvec) buf ;
Some (List.rev !boolvec)
end
(* Inference *)
let match_method_name pn name =
match pn with
| Typ.Procname.Java pn_java ->
@ -123,21 +32,6 @@ let get_modelled_annotated_signature proc_attributes =
let proc_name = proc_attributes.ProcAttributes.proc_name in
let annotated_signature = AnnotatedSignature.get proc_attributes in
let proc_id = Typ.Procname.to_unique_id proc_name in
let infer_parameters ann_sig =
let mark_par =
if Inference.enabled then Inference.proc_parameters_marked proc_name else None
in
match mark_par with
| None ->
ann_sig
| Some bs ->
let mark = (false, bs) in
AnnotatedSignature.mark proc_name AnnotatedSignature.Nullable ann_sig mark
in
let infer_return ann_sig =
let mark_r = Inference.enabled && Inference.proc_return_is_marked proc_name in
if mark_r then AnnotatedSignature.mark_return AnnotatedSignature.Nullable ann_sig else ann_sig
in
let lookup_models_nullable ann_sig =
try
let mark = Hashtbl.find annotated_table_nullable proc_id in
@ -150,8 +44,7 @@ let get_modelled_annotated_signature proc_attributes =
AnnotatedSignature.mark proc_name AnnotatedSignature.Present ann_sig mark
with Caml.Not_found -> ann_sig
in
annotated_signature |> lookup_models_nullable |> lookup_models_present |> infer_return
|> infer_parameters
annotated_signature |> lookup_models_nullable |> lookup_models_present
(** Return true when the procedure has been modelled for nullable. *)

Loading…
Cancel
Save