[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
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent ae8b73e480
commit d3f3386c9e

@ -75,19 +75,19 @@ let equal i1 i2 =
(** {2 Set for identifiers} *) (** {2 Set for identifiers} *)
module IdentSet = Caml.Set.Make (struct module Set = Caml.Set.Make (struct
type nonrec t = t type nonrec t = t
let compare = compare let compare = compare
end) end)
module IdentMap = Caml.Map.Make (struct module Map = Caml.Map.Make (struct
type nonrec t = t type nonrec t = t
let compare = compare let compare = compare
end) end)
module IdentHash = Hashtbl.Make (struct module Hash = Hashtbl.Make (struct
type nonrec t = t type nonrec t = t
let equal = equal let equal = equal
@ -95,7 +95,7 @@ module IdentHash = Hashtbl.Make (struct
let hash (id: t) = Hashtbl.hash id let hash (id: t) = Hashtbl.hash id
end) 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} *) (** {2 Conversion between Names and Strings} *)
module NameHash = Hashtbl.Make (struct module NameHash = Hashtbl.Make (struct

@ -31,13 +31,13 @@ val equal_kind : kind -> kind -> bool
(** Equality for kind. *) (** Equality for kind. *)
(** Set for identifiers. *) (** 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. *) (** 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. *) (** 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 module NameGenerator : sig
type t type t
@ -52,7 +52,7 @@ module NameGenerator : sig
(** Set the current name generator. *) (** Set the current name generator. *)
end 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 *) (** Convert an identfier list to an identifier set *)
val kprimed : kind val kprimed : kind

@ -551,9 +551,9 @@ let specialize_types_proc callee_pdesc resolved_pdesc substitutions =
| exp -> | exp ->
exp exp
in in
let subst_map = ref Ident.IdentMap.empty in let subst_map = ref Ident.Map.empty in
let redirect_typename origin_id = 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 in
let convert_instr instrs = function let convert_instr instrs = function
| Sil.Load | 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 -> try Mangled.Map.find (Pvar.get_name origin_pvar) substitutions with Not_found ->
origin_typename origin_typename
in 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, 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) -> | Sil.Load (id, (Exp.Var origin_id as origin_exp), ({Typ.desc= Tstruct _} as origin_typ), loc) ->
let updated_typ : Typ.t = 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 with Not_found -> origin_typ
in in
Sil.Load (id, convert_exp origin_exp, updated_typ, loc) :: instrs 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 match instr with
| Sil.Load (id, Exp.Lvar block_param, _, _) | Sil.Load (id, Exp.Lvar block_param, _, _)
when Mangled.Map.mem (Pvar.get_name block_param) substitutions -> 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 *) (* we don't need the load the block param instruction anymore *)
(instrs, id_map) (instrs, id_map)
| Sil.Load (id, origin_exp, origin_typ, loc) -> | 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) -> ( | Sil.Call (return_ids, Exp.Var id, origin_args, loc, call_flags) -> (
try try
let block_name, extra_formals = 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 Mangled.Map.find block_var substitutions
in in
(* once we find the block in the map, it means that we need to subsitute it with the (* 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) (instrs, id_map)
in in
let f_instr_list instrs = 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 List.rev instrs
in in
f_instr_list f_instr_list

@ -318,16 +318,15 @@ let get_fields_nullified procdesc =
(* walk through the instructions and look for instance fields that are assigned to null *) (* walk through the instructions and look for instance fields that are assigned to null *)
let collect_nullified_flds (nullified_flds, this_ids) _ = function let collect_nullified_flds (nullified_flds, this_ids) _ = function
| Sil.Store (Exp.Lfield (Exp.Var lhs, fld, _), _, rhs, _) | 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) (Typ.Fieldname.Set.add fld nullified_flds, this_ids)
| Sil.Load (id, rhs, _, _) when Exp.is_this rhs -> | 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) (nullified_flds, this_ids)
in in
let nullified_flds, _ = let nullified_flds, _ =
Procdesc.fold_instrs collect_nullified_flds (Typ.Fieldname.Set.empty, Ident.IdentSet.empty) Procdesc.fold_instrs collect_nullified_flds (Typ.Fieldname.Set.empty, Ident.Set.empty) procdesc
procdesc
in in
nullified_flds nullified_flds

@ -963,8 +963,7 @@ let sigma_reachable root_fav sigma =
let edge_fires (e, _) = let edge_fires (e, _) =
match e with match e with
| Exp.Var id -> | Exp.Var id ->
if Ident.is_primed id || Ident.is_footprint id then Ident.IdentSet.mem id !reach_set if Ident.is_primed id || Ident.is_footprint id then Ident.Set.mem id !reach_set else true
else true
| _ -> | _ ->
true true
in in
@ -974,7 +973,7 @@ let sigma_reachable root_fav sigma =
(edges_to_revisit, modified) (edges_to_revisit, modified)
| edge :: edges_todo' -> | edge :: edges_todo' ->
if edge_fires edge then ( 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 ) apply_once edges_to_revisit edges_todo' true )
else apply_once (edge :: edges_to_revisit) edges_todo' modified else apply_once (edge :: edges_to_revisit) edges_todo' modified
in in
@ -984,7 +983,7 @@ let sigma_reachable root_fav sigma =
in in
find_fixpoint !edges ; find_fixpoint !edges ;
(* L.d_str "reachable: "; (* 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 (); *) L.d_ln (); *)
!reach_set !reach_set
@ -1022,7 +1021,7 @@ let check_junk ?original_prop pname tenv prop =
let id_considered_reachable = let id_considered_reachable =
(* reachability function *) (* reachability function *)
let reach_set = sigma_reachable fav_root sigma in 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 in
let should_remove_hpred entries = let should_remove_hpred entries =
let predicate = function let predicate = function

@ -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 dom2 = Ident.idlist_to_idset (Sil.sub_domain sub2) in
let handle_atom sub dom atom = let handle_atom sub dom atom =
let fav_list = Sil.fav_to_list (Sil.atom_fav atom) in 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 if List.for_all ~f:(fun id -> Ident.Set.mem id dom) fav_list then Sil.atom_sub (`Exp sub) atom
Sil.atom_sub (`Exp sub) atom
else ( L.d_str "handle_atom failed on " ; Sil.d_atom atom ; L.d_ln () ; raise Sil.JoinFail ) else ( L.d_str "handle_atom failed on " ; Sil.d_atom atom ; L.d_ln () ; raise Sil.JoinFail )
in in
let f1 p' atom = Prop.prop_atom_and tenv p' (handle_atom sub1 dom1 atom) in let f1 p' atom = Prop.prop_atom_and tenv p' (handle_atom sub1 dom1 atom) in

@ -219,14 +219,13 @@ let get_pure (p: 'a t) : pi = pi_of_subst p.sub @ p.pi
let get_pure_extended p = let get_pure_extended p =
let base = get_pure p in let base = get_pure p in
let primed_atoms, _ = let primed_atoms, _ =
List.fold base ~init:([], Ident.IdentMap.empty) ~f: List.fold base ~init:([], Ident.Map.empty) ~f:(fun ((atoms, primed_map) as acc) base_atom ->
(fun ((atoms, primed_map) as acc) base_atom ->
let extend_atoms id pid = let extend_atoms id pid =
try 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 let new_atom = Sil.Aeq (Var id, Var old_id) in
(new_atom :: atoms, primed_map) (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 in
match base_atom with match base_atom with
| Sil.Aeq (Exp.Var id0, Exp.Var id1) when Ident.is_primed id0 && not (Ident.is_primed id1) -> | Sil.Aeq (Exp.Var id0, Exp.Var id1) when Ident.is_primed id0 && not (Ident.is_primed id1) ->

@ -23,13 +23,13 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
module CFG = CFG module CFG = CFG
module Domain = FieldsAssignedInConstructors module Domain = FieldsAssignedInConstructors
type extras = Exp.t Ident.IdentHash.t type extras = Exp.t Ident.Hash.t
let exp_is_null ids_map exp = let exp_is_null ids_map exp =
match exp with match exp with
| Exp.Var id -> ( | Exp.Var id -> (
try try
let exp = Ident.IdentHash.find ids_map id in let exp = Ident.Hash.find ids_map id in
Exp.is_null_literal exp Exp.is_null_literal exp
with Not_found -> false ) with Not_found -> false )
| _ -> | _ ->
@ -37,14 +37,14 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
let is_self ids_map id = 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 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 match instr with
| Sil.Load (id, exp, _, _) -> | Sil.Load (id, exp, _, _) ->
Ident.IdentHash.add proc_data.extras id exp ; Ident.Hash.add proc_data.extras id exp ;
astate astate
| Sil.Store (Exp.Lfield (Exp.Var lhs_id, name, typ), exp_typ, rhs, _) -> ( | Sil.Store (Exp.Lfield (Exp.Var lhs_id, name, typ), exp_typ, rhs, _) -> (
match exp_typ.Typ.desc with 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 if Procdesc.is_defined pdesc && Typ.Procname.is_constructor proc_name then
match match
FieldsAssignedInConstructorsChecker.compute_post FieldsAssignedInConstructorsChecker.compute_post
(ProcData.make pdesc tenv (Ident.IdentHash.create 10)) (ProcData.make pdesc tenv (Ident.Hash.create 10))
~initial ~initial
with with
| Some new_domain -> | Some new_domain ->

@ -12,11 +12,11 @@ open! IStd
(** Environment for temporary identifiers used in instructions. (** Environment for temporary identifiers used in instructions.
Lazy implementation: only created when actually used. *) 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 create_ proc_desc =
let map = Ident.IdentHash.create 1 in let map = Ident.Hash.create 1 in
let do_instr _ = function Sil.Load (id, e, _, _) -> Ident.IdentHash.add map id e | _ -> () in let do_instr _ = function Sil.Load (id, e, _, _) -> Ident.Hash.add map id e | _ -> () in
Procdesc.iter_instrs do_instr proc_desc ; Procdesc.iter_instrs do_instr proc_desc ;
map map
@ -29,7 +29,7 @@ let create proc_desc =
let lookup map_ id = let lookup map_ id =
let map = Lazy.force map_ in 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 = let expand_expr idenv e =

Loading…
Cancel
Save