[caml] do not use `let _ =`

Summary:
Use `ignore` instead, as this will warn if the argument is an arrow type,
unlike `let _ = ...`. This makes the code more future-proof: if an argument is
added to a function called in `let _ = f x` then the compiler will complain
instead of silently turning a value into a partial evaluation.

Also got rid of particularly irksome `let _ = <stuff returning unit> in` where I could.

Reviewed By: mbouaziz

Differential Revision: D9217176

fbshipit-source-id: 3be463405
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 12c0e245c6
commit e5a5d64760

@ -34,7 +34,7 @@ let empty_stats () = {files_linked= 0; targets_merged= 0}
let link_exists s = let link_exists s =
try try
let _ = Unix.lstat s in ignore (Unix.lstat s) ;
true true
with Unix.Unix_error _ -> false with Unix.Unix_error _ -> false

@ -2568,7 +2568,7 @@ let prop_iter_gc_fields iter =
prop_iter_map f iter prop_iter_map f iter
let prop_case_split tenv prop = let prop_expand tenv prop =
let pi_sigma_list = Sil.sigma_to_sigma_ne prop.sigma in let pi_sigma_list = Sil.sigma_to_sigma_ne prop.sigma in
let f props_acc (pi, sigma) = let f props_acc (pi, sigma) =
let sigma' = sigma_normalize_prop tenv prop sigma in let sigma' = sigma_normalize_prop tenv prop sigma in
@ -2578,13 +2578,6 @@ let prop_case_split tenv prop =
List.fold ~f ~init:[] pi_sigma_list List.fold ~f ~init:[] pi_sigma_list
let prop_expand prop =
(*
let _ = check_prop_normalized prop in
*)
prop_case_split prop
(*** START of module Metrics ***) (*** START of module Metrics ***)
module Metrics : sig module Metrics : sig
val prop_size : 'a t -> int val prop_size : 'a t -> int

@ -1932,16 +1932,14 @@ module Subtyping_check = struct
end end
let cast_exception tenv texp1 texp2 e1 subs = let cast_exception tenv texp1 texp2 e1 subs =
let _ = ( match (texp1, texp2) with
match (texp1, texp2) with | Exp.Sizeof {typ= t1}, Exp.Sizeof {typ= t2; subtype= st2} ->
| Exp.Sizeof {typ= t1}, Exp.Sizeof {typ= t2; subtype= st2} -> if
if Config.developer_mode
Config.developer_mode || (Subtype.is_cast st2 && not (Subtyping_check.check_subtype tenv t1 t2))
|| (Subtype.is_cast st2 && not (Subtyping_check.check_subtype tenv t1 t2)) then ProverState.checks := Class_cast_check (texp1, texp2, e1) :: !ProverState.checks
then ProverState.checks := Class_cast_check (texp1, texp2, e1) :: !ProverState.checks | _ ->
| _ -> () ) ;
()
in
raise (IMPL_EXC ("class cast exception", subs, EXC_FALSE)) raise (IMPL_EXC ("class cast exception", subs, EXC_FALSE))
@ -2073,17 +2071,15 @@ let rec hpred_imply tenv calc_index_frame calc_missing subs prop1 sigma2 hpred2
| Sil.Hpointsto (e2_, se2, texp2) | Sil.Hpointsto (e2_, se2, texp2)
-> ( -> (
let e2 = Sil.exp_sub (`Exp (snd subs)) e2_ in let e2 = Sil.exp_sub (`Exp (snd subs)) e2_ in
let _ = ( match e2 with
match e2 with | Exp.Lvar _ ->
| Exp.Lvar _ -> ()
() | Exp.Var v ->
| Exp.Var v -> if Ident.is_primed v then (
if Ident.is_primed v then ( d_impl_err ("rhs |-> not implemented", subs, EXC_FALSE_HPRED hpred2) ;
d_impl_err ("rhs |-> not implemented", subs, EXC_FALSE_HPRED hpred2) ; raise (Exceptions.Abduction_case_not_implemented __POS__) )
raise (Exceptions.Abduction_case_not_implemented __POS__) ) | _ ->
| _ -> () ) ;
()
in
match Prop.prop_iter_create prop1 with match Prop.prop_iter_create prop1 with
| None -> | None ->
raise (IMPL_EXC ("lhs is empty", subs, EXC_FALSE)) raise (IMPL_EXC ("lhs is empty", subs, EXC_FALSE))
@ -2182,17 +2178,15 @@ let rec hpred_imply tenv calc_index_frame calc_missing subs prop1 sigma2 hpred2
-> ( -> (
(* for now ignore implications between PE and NE *) (* for now ignore implications between PE and NE *)
let e2, f2 = (Sil.exp_sub (`Exp (snd subs)) e2_, Sil.exp_sub (`Exp (snd subs)) f2_) in let e2, f2 = (Sil.exp_sub (`Exp (snd subs)) e2_, Sil.exp_sub (`Exp (snd subs)) f2_) in
let _ = ( match e2 with
match e2 with | Exp.Lvar _ ->
| Exp.Lvar _ -> ()
() | Exp.Var v ->
| Exp.Var v -> if Ident.is_primed v then (
if Ident.is_primed v then ( d_impl_err ("rhs |-> not implemented", subs, EXC_FALSE_HPRED hpred2) ;
d_impl_err ("rhs |-> not implemented", subs, EXC_FALSE_HPRED hpred2) ; raise (Exceptions.Abduction_case_not_implemented __POS__) )
raise (Exceptions.Abduction_case_not_implemented __POS__) ) | _ ->
| _ -> () ) ;
()
in
if Exp.equal e2 f2 && Sil.equal_lseg_kind k Sil.Lseg_PE then (subs, prop1) if Exp.equal e2 f2 && Sil.equal_lseg_kind k Sil.Lseg_PE then (subs, prop1)
else else
match Prop.prop_iter_create prop1 with match Prop.prop_iter_create prop1 with
@ -2253,28 +2247,24 @@ let rec hpred_imply tenv calc_index_frame calc_missing subs prop1 sigma2 hpred2
(* for now ignore implications between PE and NE *) (* for now ignore implications between PE and NE *)
let iF2, oF2 = (Sil.exp_sub (`Exp (snd subs)) iF2, Sil.exp_sub (`Exp (snd subs)) oF2) in let iF2, oF2 = (Sil.exp_sub (`Exp (snd subs)) iF2, Sil.exp_sub (`Exp (snd subs)) oF2) in
let iB2, oB2 = (Sil.exp_sub (`Exp (snd subs)) iB2, Sil.exp_sub (`Exp (snd subs)) oB2) in let iB2, oB2 = (Sil.exp_sub (`Exp (snd subs)) iB2, Sil.exp_sub (`Exp (snd subs)) oB2) in
let _ = ( match oF2 with
match oF2 with | Exp.Lvar _ ->
| Exp.Lvar _ -> ()
() | Exp.Var v ->
| Exp.Var v -> if Ident.is_primed v then (
if Ident.is_primed v then ( d_impl_err ("rhs dllseg not implemented", subs, EXC_FALSE_HPRED hpred2) ;
d_impl_err ("rhs dllseg not implemented", subs, EXC_FALSE_HPRED hpred2) ; raise (Exceptions.Abduction_case_not_implemented __POS__) )
raise (Exceptions.Abduction_case_not_implemented __POS__) ) | _ ->
| _ -> () ) ;
() ( match oB2 with
in | Exp.Lvar _ ->
let _ = ()
match oB2 with | Exp.Var v ->
| Exp.Lvar _ -> if Ident.is_primed v then (
() d_impl_err ("rhs dllseg not implemented", subs, EXC_FALSE_HPRED hpred2) ;
| Exp.Var v -> raise (Exceptions.Abduction_case_not_implemented __POS__) )
if Ident.is_primed v then ( | _ ->
d_impl_err ("rhs dllseg not implemented", subs, EXC_FALSE_HPRED hpred2) ; () ) ;
raise (Exceptions.Abduction_case_not_implemented __POS__) )
| _ ->
()
in
match Prop.prop_iter_create prop1 with match Prop.prop_iter_create prop1 with
| None -> | None ->
raise (IMPL_EXC ("lhs is empty", subs, EXC_FALSE)) raise (IMPL_EXC ("lhs is empty", subs, EXC_FALSE))

@ -95,7 +95,7 @@ let rec format_string_type_names (fmt_string: string) (start: int) : string list
try try
let fmt_re = Str.regexp "%[0-9]*\\.?[0-9]*[A-mo-z]" in let fmt_re = Str.regexp "%[0-9]*\\.?[0-9]*[A-mo-z]" in
(* matches '%2.1d' etc. *) (* matches '%2.1d' etc. *)
let _ = Str.search_forward fmt_re fmt_string start in ignore (Str.search_forward fmt_re fmt_string start) ;
let fmt_match = Str.matched_string fmt_string in let fmt_match = Str.matched_string fmt_string in
let fmt_type = String.sub fmt_match ~pos:(String.length fmt_match - 1) ~len:1 in let fmt_type = String.sub fmt_match ~pos:(String.length fmt_match - 1) ~len:1 in
fmt_type :: format_string_type_names fmt_string (Str.match_end ()) fmt_type :: format_string_type_names fmt_string (Str.match_end ())

@ -141,7 +141,7 @@ let rec expand_message_string context message an =
(* reg exp should match alphanumeric id with possibly somee _ *) (* reg exp should match alphanumeric id with possibly somee _ *)
let re = Str.regexp "%[a-zA-Z0-9_]+%" in let re = Str.regexp "%[a-zA-Z0-9_]+%" in
try try
let _ = Str.search_forward re message 0 in ignore (Str.search_forward re message 0) ;
let ms = Str.matched_string message in let ms = Str.matched_string message in
let res = evaluate_place_holder context ms an in let res = evaluate_place_holder context ms an in
L.(debug Linters Medium) "@\nMatched string '%s'@\n" ms ; L.(debug Linters Medium) "@\nMatched string '%s'@\n" ms ;

@ -2079,7 +2079,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
} }
*) *)
and objCForCollectionStmt_trans trans_state item items body stmt_info = and objCForCollectionStmt_trans trans_state item items body stmt_info =
let _ = instruction trans_state item in ignore (instruction trans_state item) ;
(* Here we do ast transformation, so we don't need the value of the translation of the *) (* Here we do ast transformation, so we don't need the value of the translation of the *)
(* variable item but we still need to add the variable to the locals *) (* variable item but we still need to add the variable to the locals *)
let assign_next_object, cond = Ast_expressions.make_next_object_exp stmt_info item items in let assign_next_object, cond = Ast_expressions.make_next_object_exp stmt_info item items in

@ -91,12 +91,12 @@ let category_decl qual_type_to_sil_type procname_from_decl tenv decl =
let name = CAst_utils.get_qualified_name name_info in let name = CAst_utils.get_qualified_name name_info in
let class_name = get_classname_from_category_decl cdi in let class_name = get_classname_from_category_decl cdi in
L.(debug Capture Verbose) "ADDING: ObjCCategoryDecl for '%a'@\n" QualifiedCppName.pp name ; L.(debug Capture Verbose) "ADDING: ObjCCategoryDecl for '%a'@\n" QualifiedCppName.pp name ;
let _ = add_class_decl qual_type_to_sil_type tenv cdi in add_class_decl qual_type_to_sil_type tenv cdi ;
let typ = let typ =
process_category qual_type_to_sil_type procname_from_decl tenv class_name decl_info process_category qual_type_to_sil_type procname_from_decl tenv class_name decl_info
decl_list decl_list
in in
let _ = add_category_implementation qual_type_to_sil_type tenv cdi in add_category_implementation qual_type_to_sil_type tenv cdi ;
typ typ
| _ -> | _ ->
assert false assert false
@ -109,7 +109,7 @@ let category_impl_decl qual_type_to_sil_type procname_from_decl tenv decl =
let name = CAst_utils.get_qualified_name name_info in let name = CAst_utils.get_qualified_name name_info in
let class_name = get_classname_from_category_impl cii in let class_name = get_classname_from_category_impl cii in
L.(debug Capture Verbose) "ADDING: ObjCCategoryImplDecl for '%a'@\n" QualifiedCppName.pp name ; L.(debug Capture Verbose) "ADDING: ObjCCategoryImplDecl for '%a'@\n" QualifiedCppName.pp name ;
let _ = add_category_decl qual_type_to_sil_type tenv cii in add_category_decl qual_type_to_sil_type tenv cii ;
let typ = let typ =
process_category qual_type_to_sil_type procname_from_decl tenv class_name decl_info process_category qual_type_to_sil_type procname_from_decl tenv class_name decl_info
decl_list decl_list

@ -133,11 +133,11 @@ let interface_declaration qual_type_to_sil_type procname_from_decl tenv decl =
add_class_to_tenv qual_type_to_sil_type procname_from_decl tenv decl_info name_info add_class_to_tenv qual_type_to_sil_type procname_from_decl tenv decl_info name_info
decl_list ocidi decl_list ocidi
in in
let _ = add_class_implementation qual_type_to_sil_type tenv ocidi in add_class_implementation qual_type_to_sil_type tenv ocidi ;
let _ = add_super_class_decl qual_type_to_sil_type tenv ocidi in add_super_class_decl qual_type_to_sil_type tenv ocidi ;
let _ = add_protocols_decl qual_type_to_sil_type tenv ocidi.Clang_ast_t.otdi_protocols in add_protocols_decl qual_type_to_sil_type tenv ocidi.Clang_ast_t.otdi_protocols ;
let known_categories = ocidi.Clang_ast_t.otdi_known_categories in let known_categories = ocidi.Clang_ast_t.otdi_known_categories in
let _ = add_categories_decl qual_type_to_sil_type tenv known_categories in add_categories_decl qual_type_to_sil_type tenv known_categories ;
typ typ
| _ -> | _ ->
assert false assert false
@ -151,7 +151,7 @@ let interface_impl_declaration qual_type_to_sil_type procname_from_decl tenv dec
let class_name = CAst_utils.get_qualified_name name_info in let class_name = CAst_utils.get_qualified_name name_info in
L.(debug Capture Verbose) L.(debug Capture Verbose)
"ADDING: ObjCImplementationDecl for class '%a'@\n" QualifiedCppName.pp class_name ; "ADDING: ObjCImplementationDecl for class '%a'@\n" QualifiedCppName.pp class_name ;
let _ = add_class_decl qual_type_to_sil_type tenv idi in add_class_decl qual_type_to_sil_type tenv idi ;
let class_tn_name = Typ.Name.Objc.from_qual_name class_name in let class_tn_name = Typ.Name.Objc.from_qual_name class_name in
let fields = CField_decl.get_fields qual_type_to_sil_type tenv class_tn_name decl_list in let fields = CField_decl.get_fields qual_type_to_sil_type tenv class_tn_name decl_list in
CField_decl.add_missing_fields tenv class_name fields ; CField_decl.add_missing_fields tenv class_name fields ;

@ -170,7 +170,7 @@ let get_copyright_year cstart cend lines =
let do_line line = let do_line line =
try try
let fmt_re = Str.regexp "[0-9]+" in let fmt_re = Str.regexp "[0-9]+" in
let _ = Str.search_forward fmt_re line 0 in ignore (Str.search_forward fmt_re line 0) ;
let fmt_match = Str.matched_string line in let fmt_match = Str.matched_string line in
if String.length fmt_match = 4 then if String.length fmt_match = 4 then
try found := Some (int_of_string fmt_match) with _ -> () try found := Some (int_of_string fmt_match) with _ -> ()

@ -5,16 +5,16 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*) *)
(* Example of ocaml script starting with infer code. To execute a scipt run: (** Example of ocaml script starting with infer code. To execute a scipt run:
./scripts/infer_repl <path/to/this/script.ml> ./scripts/infer_repl <path/to/this/script.ml>
It's used as a basic integration test *) It's used as a basic integration test *)
(* "import" infer code *) (* "import" infer code *)
#use "toplevel_init";; #use "toplevel_init";;
let _ = Ident.create_fresh Ident.knormal in ignore (Ident.create_fresh Ident.knormal) ;
let ident = Ident.create_fresh Ident.knormal in let ident = Ident.create_fresh Ident.knormal in
let e = Exp.Var ident in let e = Exp.Var ident in
print_endline (Exp.to_string e); print_endline (Exp.to_string e) ;
(* pass --flavors flag to change the value *) (* pass --flavors flag to change the value *)
print_endline (string_of_bool Config.flavors) print_endline (string_of_bool Config.flavors)

Loading…
Cancel
Save