Skip to content

Commit

Permalink
[ocamlformat] Upgrade ocamlformat to v0.2 from opam
Browse files Browse the repository at this point in the history
Summary:
Change ocamlformat installation procedure to use opam instead of
pinning.

Reformat all code with v0.2, which has a few improvements.

Reviewed By: jvillard

Differential Revision: D6292057

fbshipit-source-id: 759967f
  • Loading branch information
jberdine authored and facebook-github-bot committed Nov 10, 2017
1 parent 794c867 commit f62ab09
Show file tree
Hide file tree
Showing 99 changed files with 244 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
margin 100
sparse true
version v0.1
version v0.2
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ opam.lock: opam
# This is a magical version number that doesn't reinstall the world when added on top of what we
# have in opam.lock. To upgrade this version number, manually try to install several utop versions
# until you find one that doesn't recompile the world. TODO(t20828442): get rid of magic
OPAM_DEV_DEPS = ocp-indent merlin utop.2.0.1
OPAM_DEV_DEPS = ocamlformat.$$(grep version .ocamlformat | cut -d ' ' -f 2) ocp-indent merlin utop.2.0.1

ifneq ($(EMACS),no)
OPAM_DEV_DEPS += tuareg
Expand All @@ -589,9 +589,8 @@ endif
devsetup: Makefile.autoconf
$(QUIET)[ $(OPAM) != "no" ] || (echo 'No `opam` found, aborting setup.' >&2; exit 1)
$(QUIET)$(call silent_on_success,installing $(OPAM_DEV_DEPS),\
OPAMSWITCH=$(OPAMSWITCH); $(OPAM) pin remove --yes ocamlformat $(OPAM_DEV_DEPS)\
OPAMSWITCH=$(OPAMSWITCH); $(OPAM) install --yes --no-checksum user-setup $(OPAM_DEV_DEPS))
$(QUIET)$(call silent_on_success,installing ocamlformat,\
OPAMSWITCH=$(OPAMSWITCH); $(OPAM) pin add --yes ocamlformat https://github.com/ocaml-ppx/ocamlformat.git#$$(grep version .ocamlformat | cut -d ' ' -f 2))
$(QUIET)echo '$(TERM_INFO)*** Running `opam config setup -a`$(TERM_RESET)' >&2
$(QUIET)OPAMSWITCH=$(OPAMSWITCH); $(OPAM) config --yes setup -a
$(QUIET)echo '$(TERM_INFO)*** Running `opam user-setup`$(TERM_RESET)' >&2
Expand Down
17 changes: 7 additions & 10 deletions infer/src/IR/Cfg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ let remove_proc_desc cfg pname = Typ.Procname.Hash.remove cfg.proc_desc_table pn
let iter_proc_desc cfg f = Typ.Procname.Hash.iter f cfg.proc_desc_table

let find_proc_desc_from_name cfg pname =
try Some (Typ.Procname.Hash.find cfg.proc_desc_table pname)
with Not_found -> None
try Some (Typ.Procname.Hash.find cfg.proc_desc_table pname) with Not_found -> None


(** Create a new procdesc *)
Expand Down Expand Up @@ -253,8 +252,7 @@ let mark_unchanged_pdescs cfg_new cfg_old =
(Procdesc.Node.get_preds n2)
&& instrs_eq (Procdesc.Node.get_instrs n1) (Procdesc.Node.get_instrs n2)
in
try List.for_all2_exn ~f:node_eq n1s n2s
with Invalid_argument _ -> false
try List.for_all2_exn ~f:node_eq n1s n2s with Invalid_argument _ -> false
in
let att1 = Procdesc.get_attributes pd1 and att2 = Procdesc.get_attributes pd2 in
Bool.equal att1.is_defined att2.is_defined && Typ.equal att1.ret_type att2.ret_type
Expand Down Expand Up @@ -318,8 +316,7 @@ let convert_cfg ~callee_pdesc ~resolved_pdesc convert_instr_list =
[]
| node :: other_node ->
let converted_node =
try Procdesc.NodeMap.find node !node_map
with Not_found ->
try Procdesc.NodeMap.find node !node_map with Not_found ->
let new_node = convert_node node
and successors = Procdesc.Node.get_succs node
and exn_nodes = Procdesc.Node.get_exn node in
Expand Down Expand Up @@ -354,8 +351,7 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
in
let subst_map = ref Ident.IdentMap.empty in
let redirect_typename origin_id =
try Some (Ident.IdentMap.find origin_id !subst_map)
with Not_found -> None
try Some (Ident.IdentMap.find origin_id !subst_map) with Not_found -> None
in
let convert_instr instrs = function
| Sil.Load
Expand All @@ -364,8 +360,8 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
, {Typ.desc= Tptr ({desc= Tstruct origin_typename}, Pk_pointer)}
, loc ) ->
let specialized_typname =
try Mangled.Map.find (Pvar.get_name origin_pvar) substitutions
with Not_found -> origin_typename
try Mangled.Map.find (Pvar.get_name origin_pvar) substitutions with Not_found ->
origin_typename
in
subst_map := Ident.IdentMap.add id specialized_typname !subst_map ;
Sil.Load (id, convert_exp origin_exp, mk_ptr_typ specialized_typname, loc) :: instrs
Expand Down Expand Up @@ -610,3 +606,4 @@ let pp_proc_signatures fmt cfg =
F.fprintf fmt "METHOD SIGNATURES@\n@." ;
let sorted_procs = List.sort ~cmp:Procdesc.compare (get_all_procs cfg) in
List.iter ~f:(fun pdesc -> F.fprintf fmt "%a@." Procdesc.pp_signature pdesc) sorted_procs

5 changes: 1 addition & 4 deletions infer/src/IR/Errlog.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ module Err_table = struct
(* map error name to count *)
let count_err (err_name: IssueType.t) n =
let err_string = err_name.IssueType.unique_id in
let count =
try String.Map.find_exn !err_name_map err_string
with Not_found -> 0
in
let count = try String.Map.find_exn !err_name_map err_string with Not_found -> 0 in
err_name_map := String.Map.add ~key:err_string ~data:(count + n) !err_name_map
in
let count key err_datas =
Expand Down
1 change: 1 addition & 0 deletions infer/src/IR/Exp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,4 @@ let is_objc_block_closure = function
Typ.Procname.is_objc_block name
| _ ->
false

8 changes: 2 additions & 6 deletions infer/src/IR/LintIssues.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ let errLogMap = ref Typ.Procname.Map.empty
let exists_issues () = not (Typ.Procname.Map.is_empty !errLogMap)

let get_err_log procname =
try Typ.Procname.Map.find procname !errLogMap
with Not_found ->
try Typ.Procname.Map.find procname !errLogMap with Not_found ->
let errlog = Errlog.empty () in
errLogMap := Typ.Procname.Map.add procname errlog !errLogMap ;
errlog
Expand All @@ -38,10 +37,7 @@ let load_issues issues_file = Serialization.read_from_file lint_issues_serialize
(** Load all the lint issues in the given dir and update the issues map *)
let load_issues_to_errlog_map dir =
let issues_dir = Filename.concat Config.results_dir dir in
let children_opt =
try Some (Sys.readdir issues_dir)
with Sys_error _ -> None
in
let children_opt = try Some (Sys.readdir issues_dir) with Sys_error _ -> None in
let load_issues_to_map issues_file =
let file = DB.filename_from_string (Filename.concat issues_dir issues_file) in
match load_issues file with
Expand Down
1 change: 1 addition & 0 deletions infer/src/IR/Pvar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,4 @@ let get_initializer_pname {pv_name; pv_kind} =
(Config.clang_initializer_prefix ^ Mangled.to_string_full pv_name))
| _ ->
None

20 changes: 6 additions & 14 deletions infer/src/IR/Sil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1945,10 +1945,7 @@ type sharing_env = {exph: Exp.t Exp.Hash.t; hpredh: hpred HpredInstHash.t}
let create_sharing_env () = {exph= Exp.Hash.create 3; hpredh= HpredInstHash.create 3}

(** Return a canonical representation of the exp *)
let exp_compact sh e =
try Exp.Hash.find sh.exph e
with Not_found -> Exp.Hash.add sh.exph e e ; e

let exp_compact sh e = try Exp.Hash.find sh.exph e with Not_found -> Exp.Hash.add sh.exph e e ; e

let rec sexp_compact sh se =
match se with
Expand All @@ -1975,8 +1972,7 @@ let _hpred_compact sh hpred =


let hpred_compact sh hpred =
try HpredInstHash.find sh.hpredh hpred
with Not_found ->
try HpredInstHash.find sh.hpredh hpred with Not_found ->
let hpred' = _hpred_compact sh hpred in
HpredInstHash.add sh.hpredh hpred' hpred' ;
hpred'
Expand Down Expand Up @@ -2052,17 +2048,15 @@ let sigma_to_sigma_ne sigma : (atom list * hpred list) list =
let hpara_instantiate para e1 e2 elist =
let subst_for_svars =
let g id e = (id, e) in
try List.map2_exn ~f:g para.svars elist
with Invalid_argument _ -> assert false
try List.map2_exn ~f:g para.svars elist with Invalid_argument _ -> assert false
in
let ids_evars =
let g _ = Ident.create_fresh Ident.kprimed in
List.map ~f:g para.evars
in
let subst_for_evars =
let g id id' = (id, Exp.Var id') in
try List.map2_exn ~f:g para.evars ids_evars
with Invalid_argument _ -> assert false
try List.map2_exn ~f:g para.evars ids_evars with Invalid_argument _ -> assert false
in
let subst =
`Exp
Expand All @@ -2079,17 +2073,15 @@ let hpara_instantiate para e1 e2 elist =
let hpara_dll_instantiate (para: hpara_dll) cell blink flink elist =
let subst_for_svars =
let g id e = (id, e) in
try List.map2_exn ~f:g para.svars_dll elist
with Invalid_argument _ -> assert false
try List.map2_exn ~f:g para.svars_dll elist with Invalid_argument _ -> assert false
in
let ids_evars =
let g _ = Ident.create_fresh Ident.kprimed in
List.map ~f:g para.evars_dll
in
let subst_for_evars =
let g id id' = (id, Exp.Var id') in
try List.map2_exn ~f:g para.evars_dll ids_evars
with Invalid_argument _ -> assert false
try List.map2_exn ~f:g para.evars_dll ids_evars with Invalid_argument _ -> assert false
in
let subst =
`Exp
Expand Down
3 changes: 1 addition & 2 deletions infer/src/IR/Subtype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ end)
let check_subtype =
let subtMap = ref SubtypesMap.empty in
fun tenv c1 c2 ->
( try SubtypesMap.find (c1, c2) !subtMap
with Not_found ->
( try SubtypesMap.find (c1, c2) !subtMap with Not_found ->
let is_subt = check_subclass_tenv tenv c1 c2 in
subtMap := SubtypesMap.add (c1, c2) is_subt !subtMap ;
is_subt
Expand Down
9 changes: 3 additions & 6 deletions infer/src/IR/Tenv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ let mem tenv name = TypenameHash.mem tenv name

(** Look up a name in the global type environment. *)
let lookup tenv name : Typ.Struct.t option =
try Some (TypenameHash.find tenv name)
with Not_found ->
try Some (TypenameHash.find tenv name) with Not_found ->
(* ToDo: remove the following additional lookups once C/C++ interop is resolved *)
match (name : Typ.Name.t) with
| CStruct m -> (
try Some (TypenameHash.find tenv (CppClass (m, NoTemplate)))
with Not_found -> None )
try Some (TypenameHash.find tenv (CppClass (m, NoTemplate))) with Not_found -> None )
| CppClass (m, NoTemplate) -> (
try Some (TypenameHash.find tenv (CStruct m))
with Not_found -> None )
try Some (TypenameHash.find tenv (CStruct m)) with Not_found -> None )
| _ ->
None

Expand Down
3 changes: 1 addition & 2 deletions infer/src/absint/AbstractDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ module Map (Key : PrettyPrintable.PrintableOrderedType) (ValueDomain : S) = stru
else
M.for_all
(fun k lhs_v ->
try ValueDomain.( <= ) ~lhs:lhs_v ~rhs:(M.find k rhs)
with Not_found -> false)
try ValueDomain.( <= ) ~lhs:lhs_v ~rhs:(M.find k rhs) with Not_found -> false)
lhs


Expand Down
3 changes: 1 addition & 2 deletions infer/src/absint/AbstractInterpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ struct

(** extract the state of node [n] from [inv_map] *)
let extract_state node_id inv_map =
try Some (InvariantMap.find node_id inv_map)
with Not_found -> None
try Some (InvariantMap.find node_id inv_map) with Not_found -> None


(** extract the postcondition of node [n] from [inv_map] *)
Expand Down
5 changes: 1 addition & 4 deletions infer/src/absint/FormalMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ let empty = AccessPath.BaseMap.empty

let is_formal = AccessPath.BaseMap.mem

let get_formal_index base t =
try Some (AccessPath.BaseMap.find base t)
with Not_found -> None

let get_formal_index base t = try Some (AccessPath.BaseMap.find base t) with Not_found -> None

let get_formal_base index t =
List.find ~f:(fun (_, i) -> Int.equal i index) (AccessPath.BaseMap.bindings t)
Expand Down
3 changes: 1 addition & 2 deletions infer/src/absint/LowerHil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ struct

let exec_instr ((actual_state, id_map) as astate) extras node instr =
let f_resolve_id id =
try Some (IdAccessPathMapDomain.find id id_map)
with Not_found -> None
try Some (IdAccessPathMapDomain.find id id_map) with Not_found -> None
in
match
HilInstr.of_sil ~include_array_indexes:HilConfig.include_array_indexes ~f_resolve_id instr
Expand Down
6 changes: 2 additions & 4 deletions infer/src/absint/ProcCfg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ module Exceptional = struct
let add_exn_pred exn_preds_acc exn_succ_node =
let exn_succ_node_id = Procdesc.Node.get_id exn_succ_node in
let existing_exn_preds =
try Procdesc.IdMap.find exn_succ_node_id exn_preds_acc
with Not_found -> []
try Procdesc.IdMap.find exn_succ_node_id exn_preds_acc with Not_found -> []
in
if not (List.mem ~equal:Procdesc.Node.equal existing_exn_preds n) then
(* don't add duplicates *)
Expand All @@ -216,8 +215,7 @@ module Exceptional = struct
let normal_preds _ n = Procdesc.Node.get_preds n

let exceptional_preds (_, exn_pred_map) n =
try Procdesc.IdMap.find (Procdesc.Node.get_id n) exn_pred_map
with Not_found -> []
try Procdesc.IdMap.find (Procdesc.Node.get_id n) exn_pred_map with Not_found -> []


(** get all normal and exceptional successors of [n]. *)
Expand Down
4 changes: 2 additions & 2 deletions infer/src/absint/Scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module ReversePostorder (CFG : ProcCfg.S) = struct
let schedule_succ worklist_acc node_to_schedule =
let id_to_schedule = CFG.id node_to_schedule in
let old_work =
try M.find id_to_schedule worklist_acc
with Not_found -> WorkUnit.make t.cfg node_to_schedule
try M.find id_to_schedule worklist_acc with Not_found ->
WorkUnit.make t.cfg node_to_schedule
in
let new_work = WorkUnit.add_visited_pred t.cfg old_work node_id in
M.add id_to_schedule new_work worklist_acc
Expand Down
4 changes: 3 additions & 1 deletion infer/src/backend/BuiltinDefn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ let execute___set_file_attribute {Builtin.tenv; pdesc; prop_; path; ret_id; args
| _ ->
raise (Exceptions.Wrong_argument_number __POS__)


(** Set the resource attribute of the first real argument of method as ignore, the first argument is
assumed to be "this" *)
let execute___method_set_ignore_attribute {Builtin.tenv; pdesc; prop_; path; ret_id; args; loc}
Expand Down Expand Up @@ -1066,6 +1067,7 @@ let __objc_cast = Builtin.register BuiltinDecl.__objc_cast execute___objc_cast
let __objc_dictionary_literal =
Builtin.register BuiltinDecl.__objc_dictionary_literal execute___objc_dictionary_literal


let __objc_release_cf = Builtin.register BuiltinDecl.__objc_release_cf execute___objc_release_cf

let __objc_retain_cf = Builtin.register BuiltinDecl.__objc_retain_cf execute___objc_retain_cf
Expand All @@ -1081,6 +1083,7 @@ let __print_value = Builtin.register BuiltinDecl.__print_value execute___print_v
let __require_allocated_array =
Builtin.register BuiltinDecl.__require_allocated_array execute___require_allocated_array


let __set_array_length = Builtin.register BuiltinDecl.__set_array_length execute___set_array_length

let __set_file_attribute =
Expand All @@ -1090,7 +1093,6 @@ let __set_file_attribute =
(* set a hidden field in the struct to the given value *)
let __set_hidden_field = Builtin.register BuiltinDecl.__set_hidden_field execute___set_hidden_field


let __set_locked_attribute =
Builtin.register BuiltinDecl.__set_locked_attribute execute___set_locked_attribute

Expand Down
9 changes: 3 additions & 6 deletions infer/src/backend/InferPrint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ let load_specfiles () =
let is_specs_file fname =
Sys.is_directory fname <> `Yes && Filename.check_suffix fname Config.specs_files_suffix
in
let all_filenames =
try Array.to_list (Sys.readdir dir)
with Sys_error _ -> []
in
let all_filenames = try Array.to_list (Sys.readdir dir) with Sys_error _ -> [] in
let all_filepaths = List.map ~f:(fun fname -> Filename.concat dir fname) all_filenames in
List.filter ~f:is_specs_file all_filepaths
in
Expand Down Expand Up @@ -585,8 +582,8 @@ module Stats = struct


let process_loc loc stats =
try Hashtbl.find stats.files loc.Location.file
with Not_found -> Hashtbl.add stats.files loc.Location.file ()
try Hashtbl.find stats.files loc.Location.file with Not_found ->
Hashtbl.add stats.files loc.Location.file ()


let loc_trace_to_string_list linereader indent_num ltr =
Expand Down
1 change: 1 addition & 0 deletions infer/src/backend/SymExecBlocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ let resolve_method_with_block_args_and_analyze caller_pdesc pname act_params =
None )
| _ ->
None

3 changes: 1 addition & 2 deletions infer/src/backend/abs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ let create_condition_ls ids_private id_base p_leftover (inst: Sil.exp_subst) =
let inst_private, inst_public = Sil.sub_domain_partition f inst in
let insts_of_public_ids = Sil.sub_range inst_public in
let inst_of_base =
try Sil.sub_find (Ident.equal id_base) inst_public
with Not_found -> assert false
try Sil.sub_find (Ident.equal id_base) inst_public with Not_found -> assert false
in
let insts_of_private_ids = Sil.sub_range inst_private in
(insts_of_private_ids, insts_of_public_ids, inst_of_base)
Expand Down
4 changes: 2 additions & 2 deletions infer/src/backend/builtin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ let is_registered name =

(** get the symbolic execution handler associated to the builtin function name *)
let get name : t option =
try Some (Typ.Procname.Hash.find builtin_functions name)
with Not_found -> check_register_populated () ; None
try Some (Typ.Procname.Hash.find builtin_functions name) with Not_found ->
check_register_populated () ; None


(** register a builtin [Typ.Procname.t] and symbolic execution handler *)
Expand Down
3 changes: 1 addition & 2 deletions infer/src/backend/dom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ end = struct
let lookup' tbl e default =
match e with
| Exp.Var _ -> (
try Hashtbl.find tbl e
with Not_found -> Hashtbl.replace tbl e default ; default )
try Hashtbl.find tbl e with Not_found -> Hashtbl.replace tbl e default ; default )
| _ ->
assert false

Expand Down
Loading

0 comments on commit f62ab09

Please sign in to comment.