From d3f3386c9ed7069a93827e5ced3929d5e5a257d9 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 20 Feb 2018 05:39:52 -0800 Subject: [PATCH] [wibble] rename `Ident{Set,Map,Hash}` -> `{Set,Map,Hash}` Summary: Just some minor renaming to be more consistent with other modules. I was about to use these modules and was too lazy to type `Ident.IdentSet`. Reviewed By: da319, avarun42 Differential Revision: D6999808 fbshipit-source-id: c24edef --- infer/src/IR/Ident.ml | 8 ++++---- infer/src/IR/Ident.mli | 8 ++++---- infer/src/IR/Procdesc.ml | 14 +++++++------- infer/src/absint/PatternMatch.ml | 7 +++---- infer/src/backend/abs.ml | 9 ++++----- infer/src/backend/dom.ml | 3 +-- infer/src/backend/prop.ml | 7 +++---- infer/src/checkers/NullabilityPreanalysis.ml | 12 ++++++------ infer/src/checkers/idenv.ml | 8 ++++---- 9 files changed, 36 insertions(+), 40 deletions(-) diff --git a/infer/src/IR/Ident.ml b/infer/src/IR/Ident.ml index f64296cfb..5be340562 100644 --- a/infer/src/IR/Ident.ml +++ b/infer/src/IR/Ident.ml @@ -75,19 +75,19 @@ let equal i1 i2 = (** {2 Set for identifiers} *) -module IdentSet = Caml.Set.Make (struct +module Set = Caml.Set.Make (struct type nonrec t = t let compare = compare end) -module IdentMap = Caml.Map.Make (struct +module Map = Caml.Map.Make (struct type nonrec t = t let compare = compare end) -module IdentHash = Hashtbl.Make (struct +module Hash = Hashtbl.Make (struct type nonrec t = t let equal = equal @@ -95,7 +95,7 @@ module IdentHash = Hashtbl.Make (struct let hash (id: t) = Hashtbl.hash id end) -let idlist_to_idset ids = List.fold ~f:(fun set id -> IdentSet.add id set) ~init:IdentSet.empty ids +let idlist_to_idset ids = List.fold ~f:(fun set id -> Set.add id set) ~init:Set.empty ids (** {2 Conversion between Names and Strings} *) module NameHash = Hashtbl.Make (struct diff --git a/infer/src/IR/Ident.mli b/infer/src/IR/Ident.mli index 14e1a2dc8..4ca8e4338 100644 --- a/infer/src/IR/Ident.mli +++ b/infer/src/IR/Ident.mli @@ -31,13 +31,13 @@ val equal_kind : kind -> kind -> bool (** Equality for kind. *) (** Set for identifiers. *) -module IdentSet : Caml.Set.S with type elt = t +module Set : Caml.Set.S with type elt = t (** Hash table with ident as key. *) -module IdentHash : Caml.Hashtbl.S with type key = t +module Hash : Caml.Hashtbl.S with type key = t (** Map with ident as key. *) -module IdentMap : Caml.Map.S with type key = t +module Map : Caml.Map.S with type key = t module NameGenerator : sig type t @@ -52,7 +52,7 @@ module NameGenerator : sig (** Set the current name generator. *) end -val idlist_to_idset : t list -> IdentSet.t +val idlist_to_idset : t list -> Set.t (** Convert an identfier list to an identifier set *) val kprimed : kind diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 647d1704f..a5fd02389 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -551,9 +551,9 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions = | exp -> exp in - let subst_map = ref Ident.IdentMap.empty in + let subst_map = ref Ident.Map.empty in let redirect_typename origin_id = - try Some (Ident.IdentMap.find origin_id !subst_map) with Not_found -> None + try Some (Ident.Map.find origin_id !subst_map) with Not_found -> None in let convert_instr instrs = function | Sil.Load @@ -565,11 +565,11 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions = 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 ; + subst_map := Ident.Map.add id specialized_typname !subst_map ; Sil.Load (id, convert_exp origin_exp, mk_ptr_typ specialized_typname, loc) :: instrs | Sil.Load (id, (Exp.Var origin_id as origin_exp), ({Typ.desc= Tstruct _} as origin_typ), loc) -> let updated_typ : Typ.t = - try Typ.mk ~default:origin_typ (Tstruct (Ident.IdentMap.find origin_id !subst_map)) + try Typ.mk ~default:origin_typ (Tstruct (Ident.Map.find origin_id !subst_map)) with Not_found -> origin_typ in Sil.Load (id, convert_exp origin_exp, updated_typ, loc) :: instrs @@ -670,7 +670,7 @@ let specialize_with_block_args_instrs resolved_pdesc substitutions = match instr with | Sil.Load (id, Exp.Lvar block_param, _, _) when Mangled.Map.mem (Pvar.get_name block_param) substitutions -> - let id_map = Ident.IdentMap.add id (Pvar.get_name block_param) id_map in + let id_map = Ident.Map.add id (Pvar.get_name block_param) id_map in (* we don't need the load the block param instruction anymore *) (instrs, id_map) | Sil.Load (id, origin_exp, origin_typ, loc) -> @@ -683,7 +683,7 @@ let specialize_with_block_args_instrs resolved_pdesc substitutions = | Sil.Call (return_ids, Exp.Var id, origin_args, loc, call_flags) -> ( try let block_name, extra_formals = - let block_var = Ident.IdentMap.find id id_map in + let block_var = Ident.Map.find id id_map in Mangled.Map.find block_var substitutions in (* once we find the block in the map, it means that we need to subsitute it with the @@ -730,7 +730,7 @@ let specialize_with_block_args_instrs resolved_pdesc substitutions = (instrs, id_map) in let f_instr_list instrs = - let instrs, _ = List.fold ~f:convert_instr ~init:([], Ident.IdentMap.empty) instrs in + let instrs, _ = List.fold ~f:convert_instr ~init:([], Ident.Map.empty) instrs in List.rev instrs in f_instr_list diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 9e2d1c17c..5cbf7adda 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -318,16 +318,15 @@ let get_fields_nullified procdesc = (* walk through the instructions and look for instance fields that are assigned to null *) let collect_nullified_flds (nullified_flds, this_ids) _ = function | Sil.Store (Exp.Lfield (Exp.Var lhs, fld, _), _, rhs, _) - when Exp.is_null_literal rhs && Ident.IdentSet.mem lhs this_ids -> + when Exp.is_null_literal rhs && Ident.Set.mem lhs this_ids -> (Typ.Fieldname.Set.add fld nullified_flds, this_ids) | Sil.Load (id, rhs, _, _) when Exp.is_this rhs -> - (nullified_flds, Ident.IdentSet.add id this_ids) + (nullified_flds, Ident.Set.add id this_ids) | _ -> (nullified_flds, this_ids) in let nullified_flds, _ = - Procdesc.fold_instrs collect_nullified_flds (Typ.Fieldname.Set.empty, Ident.IdentSet.empty) - procdesc + Procdesc.fold_instrs collect_nullified_flds (Typ.Fieldname.Set.empty, Ident.Set.empty) procdesc in nullified_flds diff --git a/infer/src/backend/abs.ml b/infer/src/backend/abs.ml index 2e01f3883..b93f118be 100644 --- a/infer/src/backend/abs.ml +++ b/infer/src/backend/abs.ml @@ -963,8 +963,7 @@ let sigma_reachable root_fav sigma = let edge_fires (e, _) = match e with | Exp.Var id -> - if Ident.is_primed id || Ident.is_footprint id then Ident.IdentSet.mem id !reach_set - else true + if Ident.is_primed id || Ident.is_footprint id then Ident.Set.mem id !reach_set else true | _ -> true in @@ -974,7 +973,7 @@ let sigma_reachable root_fav sigma = (edges_to_revisit, modified) | edge :: edges_todo' -> if edge_fires edge then ( - reach_set := Ident.IdentSet.union (snd edge) !reach_set ; + reach_set := Ident.Set.union (snd edge) !reach_set ; apply_once edges_to_revisit edges_todo' true ) else apply_once (edge :: edges_to_revisit) edges_todo' modified in @@ -984,7 +983,7 @@ let sigma_reachable root_fav sigma = in find_fixpoint !edges ; (* L.d_str "reachable: "; - Ident.IdentSet.iter (fun id -> Sil.d_exp (Exp.Var id); L.d_str " ") !reach_set; + Ident.Set.iter (fun id -> Sil.d_exp (Exp.Var id); L.d_str " ") !reach_set; L.d_ln (); *) !reach_set @@ -1022,7 +1021,7 @@ let check_junk ?original_prop pname tenv prop = let id_considered_reachable = (* reachability function *) let reach_set = sigma_reachable fav_root sigma in - fun id -> Ident.IdentSet.mem id reach_set + fun id -> Ident.Set.mem id reach_set in let should_remove_hpred entries = let predicate = function diff --git a/infer/src/backend/dom.ml b/infer/src/backend/dom.ml index 176cb9341..54f5d22fe 100644 --- a/infer/src/backend/dom.ml +++ b/infer/src/backend/dom.ml @@ -1840,8 +1840,7 @@ let pi_partial_meet tenv (p: Prop.normal Prop.t) (ep1: 'a Prop.t) (ep2: 'b Prop. let dom2 = Ident.idlist_to_idset (Sil.sub_domain sub2) in let handle_atom sub dom atom = let fav_list = Sil.fav_to_list (Sil.atom_fav atom) in - if List.for_all ~f:(fun id -> Ident.IdentSet.mem id dom) fav_list then - Sil.atom_sub (`Exp sub) atom + if List.for_all ~f:(fun id -> Ident.Set.mem id dom) fav_list then Sil.atom_sub (`Exp sub) atom else ( L.d_str "handle_atom failed on " ; Sil.d_atom atom ; L.d_ln () ; raise Sil.JoinFail ) in let f1 p' atom = Prop.prop_atom_and tenv p' (handle_atom sub1 dom1 atom) in diff --git a/infer/src/backend/prop.ml b/infer/src/backend/prop.ml index dcd190054..e50093581 100644 --- a/infer/src/backend/prop.ml +++ b/infer/src/backend/prop.ml @@ -219,14 +219,13 @@ let get_pure (p: 'a t) : pi = pi_of_subst p.sub @ p.pi let get_pure_extended p = let base = get_pure p in let primed_atoms, _ = - List.fold base ~init:([], Ident.IdentMap.empty) ~f: - (fun ((atoms, primed_map) as acc) base_atom -> + List.fold base ~init:([], Ident.Map.empty) ~f:(fun ((atoms, primed_map) as acc) base_atom -> let extend_atoms id pid = try - let old_id = Ident.IdentMap.find pid primed_map in + let old_id = Ident.Map.find pid primed_map in let new_atom = Sil.Aeq (Var id, Var old_id) in (new_atom :: atoms, primed_map) - with Not_found -> (atoms, Ident.IdentMap.add pid id primed_map) + with Not_found -> (atoms, Ident.Map.add pid id primed_map) in match base_atom with | Sil.Aeq (Exp.Var id0, Exp.Var id1) when Ident.is_primed id0 && not (Ident.is_primed id1) -> diff --git a/infer/src/checkers/NullabilityPreanalysis.ml b/infer/src/checkers/NullabilityPreanalysis.ml index 266ac9a9a..63232eccf 100644 --- a/infer/src/checkers/NullabilityPreanalysis.ml +++ b/infer/src/checkers/NullabilityPreanalysis.ml @@ -23,13 +23,13 @@ module TransferFunctions (CFG : ProcCfg.S) = struct module CFG = CFG module Domain = FieldsAssignedInConstructors - type extras = Exp.t Ident.IdentHash.t + type extras = Exp.t Ident.Hash.t let exp_is_null ids_map exp = match exp with | Exp.Var id -> ( try - let exp = Ident.IdentHash.find ids_map id in + let exp = Ident.Hash.find ids_map id in Exp.is_null_literal exp with Not_found -> false ) | _ -> @@ -37,14 +37,14 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_self ids_map id = - try match Ident.IdentHash.find ids_map id with Exp.Lvar var -> Pvar.is_self var | _ -> false + try match Ident.Hash.find ids_map id with Exp.Lvar var -> Pvar.is_self var | _ -> false with Not_found -> false - let exec_instr astate (proc_data: Exp.t Ident.IdentHash.t ProcData.t) _ instr = + let exec_instr astate (proc_data: Exp.t Ident.Hash.t ProcData.t) _ instr = match instr with | Sil.Load (id, exp, _, _) -> - Ident.IdentHash.add proc_data.extras id exp ; + Ident.Hash.add proc_data.extras id exp ; astate | Sil.Store (Exp.Lfield (Exp.Var lhs_id, name, typ), exp_typ, rhs, _) -> ( match exp_typ.Typ.desc with @@ -98,7 +98,7 @@ let analysis cfg tenv = if Procdesc.is_defined pdesc && Typ.Procname.is_constructor proc_name then match FieldsAssignedInConstructorsChecker.compute_post - (ProcData.make pdesc tenv (Ident.IdentHash.create 10)) + (ProcData.make pdesc tenv (Ident.Hash.create 10)) ~initial with | Some new_domain -> diff --git a/infer/src/checkers/idenv.ml b/infer/src/checkers/idenv.ml index 108a1c9c2..240f024f4 100644 --- a/infer/src/checkers/idenv.ml +++ b/infer/src/checkers/idenv.ml @@ -12,11 +12,11 @@ open! IStd (** Environment for temporary identifiers used in instructions. Lazy implementation: only created when actually used. *) -type t = Exp.t Ident.IdentHash.t Lazy.t +type t = Exp.t Ident.Hash.t Lazy.t let create_ proc_desc = - let map = Ident.IdentHash.create 1 in - let do_instr _ = function Sil.Load (id, e, _, _) -> Ident.IdentHash.add map id e | _ -> () in + let map = Ident.Hash.create 1 in + let do_instr _ = function Sil.Load (id, e, _, _) -> Ident.Hash.add map id e | _ -> () in Procdesc.iter_instrs do_instr proc_desc ; map @@ -29,7 +29,7 @@ let create proc_desc = let lookup map_ id = let map = Lazy.force map_ in - try Some (Ident.IdentHash.find map id) with Not_found -> None + try Some (Ident.Hash.find map id) with Not_found -> None let expand_expr idenv e =