From 23cda11fda355d8d1a4fbf25a57ef01d2f51f59b Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 9 Dec 2016 16:33:19 -0800 Subject: [PATCH] Core.Std.Int.Set Reviewed By: cristianoc Differential Revision: D4232448 fbshipit-source-id: 83d9a98 --- infer/src/backend/InferPrint.re | 6 +++--- infer/src/backend/specs.ml | 6 +++--- infer/src/base/Utils.ml | 12 ++---------- infer/src/base/Utils.mli | 13 ++----------- infer/src/clang/cTrans.ml | 2 +- infer/src/java/jTrans.ml | 6 +++--- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index f95519ba7..3a5801c7c 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -155,11 +155,11 @@ let summary_values top_proc_set summary => { let visited = ref Specs.Visitedset.empty; let do_spec spec => visited := Specs.Visitedset.union spec.Specs.visited !visited; IList.iter do_spec specs; - let visited_lines = ref IntSet.empty; + let visited_lines = ref Int.Set.empty; Specs.Visitedset.iter - (fun (_, ls) => IList.iter (fun l => visited_lines := IntSet.add l !visited_lines) ls) + (fun (_, ls) => IList.iter (fun l => visited_lines := Int.Set.add !visited_lines l) ls) !visited; - (Specs.Visitedset.cardinal !visited, IntSet.elements !visited_lines) + (Specs.Visitedset.cardinal !visited, Int.Set.elements !visited_lines) }; let proof_trace = { let pp_line fmt l => F.fprintf fmt "%d" l; diff --git a/infer/src/backend/specs.ml b/infer/src/backend/specs.ml index c956e5cc6..c74120fda 100644 --- a/infer/src/backend/specs.ml +++ b/infer/src/backend/specs.ml @@ -144,7 +144,7 @@ module Visitedset = let visited_str vis = let s = ref "" in - let lines = ref IntSet.empty in + let lines = ref Int.Set.empty in let do_one (_, ns) = (* if IList.length ns > 1 then begin @@ -152,9 +152,9 @@ let visited_str vis = IList.iter (fun n -> ss := !ss ^ " " ^ string_of_int n) ns; L.err "Node %d has lines %s@." node !ss end; *) - IList.iter (fun n -> lines := IntSet.add n !lines) ns in + IList.iter (fun n -> lines := Int.Set.add !lines n) ns in Visitedset.iter do_one vis; - IntSet.iter (fun n -> s := !s ^ " " ^ string_of_int n) !lines; + Int.Set.iter ~f:(fun n -> s := !s ^ " " ^ string_of_int n) !lines; !s (** A spec consists of: diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index bbbed1c50..4d5de9866 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -55,6 +55,8 @@ module Sys = struct end module Unix = Core.Std.Unix +module IntSet = Caml.Set.Make(Int) + module F = Format (** List police: don't use the list module to avoid non-tail recursive @@ -80,16 +82,6 @@ let fst3 (x,_,_) = x let snd3 (_,x,_) = x let trd3 (_,_,x) = x -let int_of_bool b = if b then 1 else 0 - -(** {2 Useful Modules} *) - -(** Set of integers *) -module IntSet = Set.Make(Int) - -(** Maps from integers *) -module IntMap = Map.Make (Int) - (** {2 Printing} *) (** Kind of simple printing: default or with full types *) diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index 43ab61b89..82840ae71 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -39,6 +39,8 @@ module String = Core.Std.String module Sys : module type of Core.Std.Sys module Unix = Core.Std.Unix +module IntSet : Caml.Set.S with type elt = int + (** {2 Generic Utility Functions} *) (** List police: don't use the list module to avoid non-tail recursive @@ -67,17 +69,6 @@ val snd3 : 'a * 'b * 'c -> 'b (** Return the third component of a triple. *) val trd3 : 'a * 'b * 'c -> 'c -(** Convert a bool into an int *) -val int_of_bool : bool -> int - -(** {2 Useful Modules} *) - -(** Set of integers *) -module IntSet : Set.S with type elt = int - -(** Maps from integers *) -module IntMap : Map.S with type key = int - (** {2 Printing} *) (** Colors supported in printing *) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 307fd8610..e8ece5e38 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -350,7 +350,7 @@ struct { empty_res_trans with exps = [(exp, typ)]} let booleanValue_trans trans_state expr_info b = - characterLiteral_trans trans_state expr_info (Utils.int_of_bool b) + characterLiteral_trans trans_state expr_info (if b then 1 else 0) let floatingLiteral_trans trans_state expr_info float_string = let typ = CType_decl.get_type_from_expr_info expr_info trans_state.context.CContext.tenv in diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 2db8c44ff..c1a9a95a5 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -628,13 +628,13 @@ let get_array_length context pc expr_list content_type = let detect_loop entry_pc impl = let code = (JBir.code impl) in let pc_bound = Array.length code in - let empty = IntSet.empty in + let empty = Int.Set.empty in let rec loop visited pc = - if (IntSet.mem pc visited) || pc >= pc_bound then + if (Int.Set.mem visited pc) || pc >= pc_bound then (false, visited) else begin - let visited_updated = IntSet.add pc visited in + let visited_updated = Int.Set.add visited pc in match code.(pc) with | JBir.Goto goto_pc when goto_pc = entry_pc -> (true, empty) | JBir.Goto goto_pc -> loop visited_updated goto_pc