Skip to content

Commit

Permalink
ppx_compare ProcCfg
Browse files Browse the repository at this point in the history
Reviewed By: sblackshear

Differential Revision: D4232404

fbshipit-source-id: 7f0e191
jberdine authored and Facebook Github Bot committed Nov 30, 2016
1 parent 85d15bc commit bbd5ef3
Showing 3 changed files with 13 additions and 17 deletions.
20 changes: 8 additions & 12 deletions infer/src/checkers/procCfg.ml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ module F = Format
file). Defines useful wrappers that allows us to do tricks like turn a forward cfg into a
backward one, or view a cfg as having a single instruction per node. *)

type index = Node_index | Instr_index of int
type index = Node_index | Instr_index of int [@@deriving compare]

module type Node = sig
type t
@@ -25,7 +25,7 @@ module type Node = sig
val id : t -> id
val loc : t -> Location.t
val underlying_id : t -> Procdesc.Node.id
val id_compare : id -> id -> int
val compare_id : id -> id -> int
val pp_id : F.formatter -> id -> unit
end

@@ -37,7 +37,7 @@ module DefaultNode = struct
let id = Procdesc.Node.get_id
let loc = Procdesc.Node.get_loc
let underlying_id = id
let id_compare = Procdesc.Node.compare_id
let compare_id = Procdesc.Node.compare_id
let pp_id = Procdesc.Node.pp_id
end

@@ -53,16 +53,12 @@ module InstrNode = struct

let loc t = Procdesc.Node.get_loc t

let index_compare index1 index2 = match index1, index2 with
| Node_index, Node_index -> 0
| Instr_index i1, Instr_index i2 -> int_compare i1 i2
| Node_index, Instr_index _ -> 1
| Instr_index _, Node_index -> -1
let compare_index = compare_index

let id_compare (id1, index1) (id2, index2) =
let compare_id (id1, index1) (id2, index2) =
let n = Procdesc.Node.compare_id id1 id2 in
if n <> 0 then n
else index_compare index1 index2
else compare_index index1 index2

let pp_id fmt (id, index) = match index with
| Node_index -> Procdesc.Node.pp_id fmt id
@@ -234,10 +230,10 @@ end

module NodeIdMap (CFG : S) = Map.Make(struct
type t = CFG.id
let compare = CFG.id_compare
let compare = CFG.compare_id
end)

module NodeIdSet (CFG : S) = Set.Make(struct
type t = CFG.id
let compare = CFG.id_compare
let compare = CFG.compare_id
end)
2 changes: 1 addition & 1 deletion infer/src/checkers/procCfg.mli
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ module type Node = sig
val id : t -> id
val loc : t -> Location.t
val underlying_id : t -> Procdesc.Node.id
val id_compare : id -> id -> int
val compare_id : id -> id -> int
val pp_id : Format.formatter -> id -> unit
end

8 changes: 4 additions & 4 deletions infer/src/unit/schedulerTests.ml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ module MockNode = struct
let loc _ = assert false
let underlying_id _ = assert false
let kind _ = Procdesc.Node.Stmt_node ""
let id_compare = int_compare
let compare_id = int_compare
let pp_id fmt i =
F.fprintf fmt "%i" i
end
@@ -35,13 +35,13 @@ module MockProcCfg = struct
include (MockNode : module type of MockNode with type t := node)
type t = (node * node list) list

let id_compare = int_compare
let compare_id = int_compare

let succs t n =
try
let node_id = id n in
IList.find
(fun (node, _) -> id_compare (id node) node_id = 0)
(fun (node, _) -> compare_id (id node) node_id = 0)
t
|> snd
with Not_found -> []
@@ -51,7 +51,7 @@ module MockProcCfg = struct
let node_id = id n in
IList.filter
(fun (_, succs) ->
IList.exists (fun node -> id_compare (id node) node_id = 0) succs)
IList.exists (fun node -> compare_id (id node) node_id = 0) succs)
t
|> IList.map fst
with Not_found -> []

0 comments on commit bbd5ef3

Please sign in to comment.