diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index fec8314af..e2b190562 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -93,7 +93,7 @@ module Node = struct ; kind: nodekind (** kind of node *) ; loc: Location.t (** location in the source code *) ; mutable preds: t list (** predecessor nodes in the cfg *) - ; pname_opt: Typ.Procname.t option (** name of the procedure the node belongs to *) + ; pname: Typ.Procname.t (** name of the procedure the node belongs to *) ; mutable succs: t list (** successor nodes in the cfg *) } let exn_handler_kind = Stmt_node ExceptionHandler @@ -102,13 +102,13 @@ module Node = struct let throw_kind = Stmt_node Throw - let dummy pname_opt = + let dummy pname = { id= 0 ; dist_exit= None ; instrs= Instrs.empty ; kind= Skip_node "dummy" ; loc= Location.dummy - ; pname_opt + ; pname ; succs= [] ; preds= [] ; exn= [] } @@ -142,14 +142,7 @@ module Node = struct let get_exn node = node.exn (** Get the name of the procedure the node belongs to *) - let get_proc_name node = - match node.pname_opt with - | None -> - L.internal_error "get_proc_name: at node %d@\n" node.id ; - assert false - | Some pname -> - pname - + let get_proc_name node = node.pname (** Get the predecessors of the node *) let get_preds node = node.preds @@ -408,9 +401,9 @@ type t = ; mutable loop_heads: NodeSet.t option (** loop head nodes of this procedure *) } let from_proc_attributes attributes = - let pname_opt = Some attributes.ProcAttributes.proc_name in - let start_node = Node.dummy pname_opt in - let exit_node = Node.dummy pname_opt in + let pname = attributes.ProcAttributes.proc_name in + let start_node = Node.dummy pname in + let exit_node = Node.dummy pname in {attributes; nodes= []; nodes_num= 0; start_node; exit_node; loop_heads= None} @@ -549,7 +542,7 @@ let create_node_internal pdesc loc kind instrs = ; kind ; loc ; preds= [] - ; pname_opt= Some pdesc.attributes.proc_name + ; pname= pdesc.attributes.proc_name ; succs= [] ; exn= [] } in diff --git a/infer/src/IR/Procdesc.mli b/infer/src/IR/Procdesc.mli index b234a961b..a327950bc 100644 --- a/infer/src/IR/Procdesc.mli +++ b/infer/src/IR/Procdesc.mli @@ -94,7 +94,7 @@ module Node : sig val d_instrs : sub_instrs:bool -> Sil.instr option -> t -> unit (** Dump extended instructions for the node *) - val dummy : Typ.Procname.t option -> t + val dummy : Typ.Procname.t -> t (** Create a dummy node *) val equal : t -> t -> bool diff --git a/infer/src/backend/preanal.ml b/infer/src/backend/preanal.ml index c1833ece6..f3d411dd1 100644 --- a/infer/src/backend/preanal.ml +++ b/infer/src/backend/preanal.ml @@ -65,7 +65,7 @@ module NullifyTransferFunctions = struct astate - let cache_node = ref (Procdesc.Node.dummy None) + let cache_node = ref (Procdesc.Node.dummy Typ.Procname.Linters_dummy_method) let cache_instr = ref Sil.skip_instr diff --git a/infer/src/biabduction/Paths.ml b/infer/src/biabduction/Paths.ml index 90857336d..ae6b1a453 100644 --- a/infer/src/biabduction/Paths.ml +++ b/infer/src/biabduction/Paths.ml @@ -371,20 +371,19 @@ end = struct () in iter_shortest_sequence (fun _ p _ _ -> add_node (curr_node p)) None path ; - let max_rep_node = ref (Procdesc.Node.dummy None) in - let max_rep_num = ref 0 in - Procdesc.NodeMap.iter - (fun node num -> - if num > !max_rep_num then ( - max_rep_node := node ; - max_rep_num := num ) ) - !map ; - (!max_rep_node, !max_rep_num) + let max_rep_opt = + Procdesc.NodeMap.fold + (fun node num max_rep_opt -> + if num > Option.value_map max_rep_opt ~default:0 ~f:fst then Some (num, node) + else max_rep_opt ) + !map None + in + Option.value_exn max_rep_opt let stats_string path = Invariant.compute_stats true (fun _ -> true) path ; - let node, repetitions = repetitions path in + let repetitions, node = repetitions path in let str = "linear paths: " ^ string_of_float (Invariant.get_stats path).linear_num