diff --git a/infer/src/checkers/impurity.ml b/infer/src/checkers/impurity.ml index 8d6a8a837..1f7ab8509 100644 --- a/infer/src/checkers/impurity.ml +++ b/infer/src/checkers/impurity.ml @@ -138,7 +138,7 @@ let is_modeled_pure tenv pname = (** Given Pulse summary, extract impurity info, i.e. parameters and global variables that are modified by the function and skipped functions. *) -let extract_impurity tenv pdesc (exec_state : PulseExecutionState.t) : ImpurityDomain.t = +let extract_impurity tenv pdesc (exec_state : ExecutionDomain.t) : ImpurityDomain.t = let astate, exited = match exec_state with | ExitProgram astate -> @@ -146,8 +146,8 @@ let extract_impurity tenv pdesc (exec_state : PulseExecutionState.t) : ImpurityD | AbortProgram astate | ContinueProgram astate -> (astate, false) in - let pre_heap = (PulseAbductiveDomain.get_pre astate).BaseDomain.heap in - let post = PulseAbductiveDomain.get_post astate in + let pre_heap = (AbductiveDomain.get_pre astate).BaseDomain.heap in + let post = AbductiveDomain.get_post astate in let post_stack = post.BaseDomain.stack in let pname = Procdesc.get_proc_name pdesc in let modified_params = @@ -155,7 +155,7 @@ let extract_impurity tenv pdesc (exec_state : PulseExecutionState.t) : ImpurityD in let modified_globals = get_modified_globals pre_heap post post_stack in let skipped_calls = - PulseAbductiveDomain.get_skipped_calls astate + AbductiveDomain.get_skipped_calls astate |> SkippedCalls.filter (fun proc_name _ -> Purity.should_report proc_name && not (is_modeled_pure tenv proc_name) ) in diff --git a/infer/src/pulse/Pulse.ml b/infer/src/pulse/Pulse.ml index 16111c691..bb6ba6f76 100644 --- a/infer/src/pulse/Pulse.ml +++ b/infer/src/pulse/Pulse.ml @@ -10,6 +10,7 @@ module F = Format module L = Logging open IResult.Let_syntax open PulseBasicInterface +open PulseDomainInterface let report summary diagnostic = let open Diagnostic in @@ -22,13 +23,11 @@ let check_error_transform summary ~f = function f astate | Error (diagnostic, astate) -> report summary diagnostic ; - [PulseExecutionState.AbortProgram astate] + [ExecutionDomain.AbortProgram astate] let check_error_continue summary result = - check_error_transform summary - ~f:(fun astate -> [PulseExecutionState.ContinueProgram astate]) - result + check_error_transform summary ~f:(fun astate -> [ExecutionDomain.ContinueProgram astate]) result let proc_name_of_call call_exp = @@ -43,7 +42,7 @@ type get_formals = Procname.t -> (Pvar.t * Typ.t) list option module PulseTransferFunctions = struct module CFG = ProcCfg.Normal - module Domain = PulseExecutionState + module Domain = ExecutionDomain type extras = get_formals @@ -76,13 +75,13 @@ module PulseTransferFunctions = struct (** [out_of_scope_access_expr] has just gone out of scope and in now invalid *) let exec_object_out_of_scope call_loc (pvar, typ) exec_state = match exec_state with - | PulseExecutionState.ContinueProgram astate -> + | ExecutionDomain.ContinueProgram astate -> let gone_out_of_scope = Invalidation.GoneOutOfScope (pvar, typ) in let* astate, out_of_scope_base = PulseOperations.eval call_loc (Exp.Lvar pvar) astate in (* invalidate [&x] *) PulseOperations.invalidate call_loc gone_out_of_scope out_of_scope_base astate - >>| PulseExecutionState.continue - | PulseExecutionState.AbortProgram _ | PulseExecutionState.ExitProgram _ -> + >>| ExecutionDomain.continue + | ExecutionDomain.AbortProgram _ | ExecutionDomain.ExitProgram _ -> Ok exec_state @@ -217,7 +216,7 @@ let checker {Callbacks.exe_env; summary} = AbstractValue.init () ; let pdesc = Summary.get_proc_desc summary in let initial = - DisjunctiveTransferFunctions.Disjuncts.singleton (PulseExecutionState.mk_initial pdesc) + DisjunctiveTransferFunctions.Disjuncts.singleton (ExecutionDomain.mk_initial pdesc) in let get_formals callee_pname = Ondemand.get_proc_desc callee_pname |> Option.map ~f:Procdesc.get_pvar_formals diff --git a/infer/src/pulse/PulseDomainInterface.ml b/infer/src/pulse/PulseDomainInterface.ml index bb7842ba1..9c6014c87 100644 --- a/infer/src/pulse/PulseDomainInterface.ml +++ b/infer/src/pulse/PulseDomainInterface.ml @@ -4,7 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) + open! IStd +module ExecutionDomain = PulseExecutionDomain module AbductiveDomain = PulseAbductiveDomain (** if you do any mutations of the state in pulse you probably want this module *) @@ -19,3 +21,19 @@ module BaseDomain = PulseBaseDomain module BaseStack = PulseBaseStack module BaseMemory = PulseBaseMemory module BaseAddressAttributes = PulseBaseAddressAttributes + +(** {2 Enforce short form usage} *) + +include struct + [@@@warning "-60"] + + module PulseAbductiveDomain = PulseAbductiveDomain + [@@deprecated "use the short form AbductiveDomain instead"] + module PulseBaseDomain = PulseBaseDomain [@@deprecated "use the short form BaseDomain instead"] + module PulseBaseStack = PulseBaseStack [@@deprecated "use the short form BaseStack instead"] + module PulseBaseMemory = PulseBaseMemory [@@deprecated "use the short form BaseMemory instead"] + module PulseBaseAddressAttributes = PulseBaseAddressAttributes + [@@deprecated "use the short form BaseAddressAttributes instead"] + module PulseExecutionDomain = PulseExecutionDomain + [@@deprecated "use the short form ExecutionDomain instead"] +end diff --git a/infer/src/pulse/PulseExecutionState.ml b/infer/src/pulse/PulseExecutionDomain.ml similarity index 62% rename from infer/src/pulse/PulseExecutionState.ml rename to infer/src/pulse/PulseExecutionDomain.ml index 68f1ac0d0..0ad9e6547 100644 --- a/infer/src/pulse/PulseExecutionState.ml +++ b/infer/src/pulse/PulseExecutionDomain.ml @@ -4,37 +4,39 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) + open! IStd module F = Format +module AbductiveDomain = PulseAbductiveDomain type exec_state = - | AbortProgram of PulseAbductiveDomain.t - | ContinueProgram of PulseAbductiveDomain.t - | ExitProgram of PulseAbductiveDomain.t + | AbortProgram of AbductiveDomain.t + | ContinueProgram of AbductiveDomain.t + | ExitProgram of AbductiveDomain.t type t = exec_state let continue astate = ContinueProgram astate -let mk_initial pdesc = ContinueProgram (PulseAbductiveDomain.mk_initial pdesc) +let mk_initial pdesc = ContinueProgram (AbductiveDomain.mk_initial pdesc) let leq ~lhs ~rhs = match (lhs, rhs) with | AbortProgram astate1, AbortProgram astate2 | ContinueProgram astate1, ContinueProgram astate2 | ExitProgram astate1, ExitProgram astate2 -> - PulseAbductiveDomain.leq ~lhs:astate1 ~rhs:astate2 + AbductiveDomain.leq ~lhs:astate1 ~rhs:astate2 | _ -> false let pp fmt = function | ContinueProgram astate -> - PulseAbductiveDomain.pp fmt astate + AbductiveDomain.pp fmt astate | ExitProgram astate -> - F.fprintf fmt "{ExitProgram %a}" PulseAbductiveDomain.pp astate + F.fprintf fmt "{ExitProgram %a}" AbductiveDomain.pp astate | AbortProgram astate -> - F.fprintf fmt "{AbortProgram %a}" PulseAbductiveDomain.pp astate + F.fprintf fmt "{AbortProgram %a}" AbductiveDomain.pp astate let map ~f exec_state = @@ -47,4 +49,4 @@ let map ~f exec_state = ExitProgram (f astate) -let of_post pdesc = map ~f:(PulseAbductiveDomain.of_post pdesc) +let of_post pdesc = map ~f:(AbductiveDomain.of_post pdesc) diff --git a/infer/src/pulse/PulseExecutionState.mli b/infer/src/pulse/PulseExecutionDomain.mli similarity index 100% rename from infer/src/pulse/PulseExecutionState.mli rename to infer/src/pulse/PulseExecutionDomain.mli diff --git a/infer/src/pulse/PulseModels.ml b/infer/src/pulse/PulseModels.ml index 69f02943c..e58e0a8e7 100644 --- a/infer/src/pulse/PulseModels.ml +++ b/infer/src/pulse/PulseModels.ml @@ -16,8 +16,8 @@ type model = -> callee_procname:Procname.t -> Location.t -> ret:Ident.t * Typ.t - -> PulseAbductiveDomain.t - -> PulseExecutionState.t list PulseOperations.access_result + -> AbductiveDomain.t + -> ExecutionDomain.t list PulseOperations.access_result module Misc = struct let shallow_copy model_desc dest_pointer_hist src_pointer_hist : model = @@ -31,12 +31,12 @@ module Misc = struct astate in let astate = PulseOperations.havoc_id ret_id [event] astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let early_exit : model = fun ~caller_summary:_ ~callee_procname:_ _ ~ret:_ astate -> - Ok [PulseExecutionState.ExitProgram astate] + Ok [ExecutionDomain.ExitProgram astate] let return_int : Int64.t -> model = @@ -91,7 +91,7 @@ module C = struct PulseOperations.ok_continue astate else let+ astate = PulseOperations.invalidate location Invalidation.CFree deleted_access astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let malloc _ : model = @@ -107,7 +107,7 @@ module C = struct PulseOperations.allocate callee_procname location ret_value astate |> AddressAttributes.add_one ret_addr (BoItv Itv.ItvPure.pos) |> AddressAttributes.add_one ret_addr (CItv (CItv.ge_to IntLit.one, immediate_hist)) - |> PulseExecutionState.continue + |> ExecutionDomain.continue in let+ astate_null = AddressAttributes.add_one ret_addr (BoItv (Itv.ItvPure.of_int_lit IntLit.zero)) astate @@ -115,7 +115,7 @@ module C = struct |> PulseOperations.invalidate location (Invalidation.ConstantDereference IntLit.zero) ret_value in - [astate_alloc; PulseExecutionState.ContinueProgram astate_null] + [astate_alloc; ExecutionDomain.ContinueProgram astate_null] end module Cplusplus = struct @@ -124,7 +124,7 @@ module Cplusplus = struct let+ astate = PulseOperations.invalidate location Invalidation.CppDelete deleted_access astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let placement_new actuals : model = @@ -163,7 +163,7 @@ module StdAtomicInteger = struct in let* astate = PulseOperations.write_deref location ~ref:int_field ~obj:init_value astate in let+ astate = PulseOperations.write_deref location ~ref:this_address ~obj:this astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let arith_bop prepost location event ret_id bop this operand astate = @@ -186,7 +186,7 @@ module StdAtomicInteger = struct arith_bop `Post location event ret_id (PlusA None) this (AbstractValueOperand increment) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let fetch_sub this (increment, _) _memory_ordering : model = @@ -196,7 +196,7 @@ module StdAtomicInteger = struct arith_bop `Post location event ret_id (MinusA None) this (AbstractValueOperand increment) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let operator_plus_plus_pre this : model = @@ -205,7 +205,7 @@ module StdAtomicInteger = struct let+ astate = arith_bop `Pre location event ret_id (PlusA None) this (LiteralOperand IntLit.one) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let operator_plus_plus_post this _int : model = @@ -216,7 +216,7 @@ module StdAtomicInteger = struct let+ astate = arith_bop `Post location event ret_id (PlusA None) this (LiteralOperand IntLit.one) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let operator_minus_minus_pre this : model = @@ -225,7 +225,7 @@ module StdAtomicInteger = struct let+ astate = arith_bop `Pre location event ret_id (MinusA None) this (LiteralOperand IntLit.one) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let operator_minus_minus_post this _int : model = @@ -236,7 +236,7 @@ module StdAtomicInteger = struct let+ astate = arith_bop `Post location event ret_id (MinusA None) this (LiteralOperand IntLit.one) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let load_instr model_desc this _memory_ordering_opt : model = @@ -244,7 +244,7 @@ module StdAtomicInteger = struct let event = ValueHistory.Call {f= Model model_desc; location; in_call= []} in let+ astate, _int_addr, (int, hist) = load_backing_int location this astate in let astate = PulseOperations.write_id ret_id (int, event :: hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let load = load_instr "std::atomic::load()" @@ -263,7 +263,7 @@ module StdAtomicInteger = struct fun ~caller_summary:_ ~callee_procname:_ location ~ret:_ astate -> let event = ValueHistory.Call {f= Model "std::atomic::store()"; location; in_call= []} in let+ astate = store_backing_int location this_address (new_value, event :: new_hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let exchange this_address (new_value, new_hist) _memory_ordering : model = @@ -272,7 +272,7 @@ module StdAtomicInteger = struct let* astate, _int_addr, (old_int, old_hist) = load_backing_int location this_address astate in let+ astate = store_backing_int location this_address (new_value, event :: new_hist) astate in let astate = PulseOperations.write_id ret_id (old_int, event :: old_hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] end module JavaObject = struct @@ -283,7 +283,7 @@ module JavaObject = struct let* astate, obj = PulseOperations.eval_access location src_pointer_hist Dereference astate in let+ astate, obj_copy = PulseOperations.shallow_copy location obj astate in let astate = PulseOperations.write_id ret_id (fst obj_copy, event :: snd obj_copy) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] end module StdBasicString = struct @@ -307,7 +307,7 @@ module StdBasicString = struct PulseOperations.eval_access location string_addr_hist Dereference astate in let astate = PulseOperations.write_id ret_id (string, event :: hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let destructor this_hist : model = @@ -318,7 +318,7 @@ module StdBasicString = struct let string_addr_hist = (string_addr, call_event :: string_hist) in let* astate = PulseOperations.invalidate_deref location CppDelete string_addr_hist astate in let+ astate = PulseOperations.invalidate location CppDelete string_addr_hist astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] end module StdFunction = struct @@ -335,7 +335,7 @@ module StdFunction = struct match AddressAttributes.get_closure_proc_name lambda astate with | None -> (* we don't know what proc name this lambda resolves to *) - Ok (havoc_ret ret astate |> List.map ~f:PulseExecutionState.continue) + Ok (havoc_ret ret astate |> List.map ~f:ExecutionDomain.continue) | Some callee_proc_name -> let actuals = List.map actuals ~f:(fun ProcnameDispatcher.Call.FuncArg.{arg_payload; typ} -> @@ -381,7 +381,7 @@ module StdVector = struct ; in_call= [] } in reallocate_internal_array [crumb] vector vector_f location astate - >>| PulseExecutionState.continue >>| List.return + >>| ExecutionDomain.continue >>| List.return let at ~desc vector index : model = @@ -389,7 +389,7 @@ module StdVector = struct let event = ValueHistory.Call {f= Model desc; location; in_call= []} in let+ astate, (addr, hist) = element_of_internal_array location vector (fst index) astate in let astate = PulseOperations.write_id (fst ret) (addr, event :: hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] let reserve vector : model = @@ -397,7 +397,7 @@ module StdVector = struct let crumb = ValueHistory.Call {f= Model "std::vector::reserve()"; location; in_call= []} in reallocate_internal_array [crumb] vector Reserve location astate >>| AddressAttributes.std_vector_reserve (fst vector) - >>| PulseExecutionState.continue >>| List.return + >>| ExecutionDomain.continue >>| List.return let push_back vector : model = @@ -410,7 +410,7 @@ module StdVector = struct else (* simulate a re-allocation of the underlying array every time an element is added *) reallocate_internal_array [crumb] vector PushBack location astate - >>| PulseExecutionState.continue >>| List.return + >>| ExecutionDomain.continue >>| List.return end module JavaCollection = struct @@ -427,7 +427,7 @@ module JavaCollection = struct >>= PulseOperations.invalidate_deref location (StdVector Assign) old_elem in let astate = PulseOperations.write_id (fst ret) (old_addr, event :: old_hist) astate in - [PulseExecutionState.ContinueProgram astate] + [ExecutionDomain.ContinueProgram astate] end module StringSet = Caml.Set.Make (String) diff --git a/infer/src/pulse/PulseModels.mli b/infer/src/pulse/PulseModels.mli index c4224148d..dac286a70 100644 --- a/infer/src/pulse/PulseModels.mli +++ b/infer/src/pulse/PulseModels.mli @@ -6,14 +6,15 @@ *) open! IStd open PulseBasicInterface +open PulseDomainInterface type model = caller_summary:Summary.t -> callee_procname:Procname.t -> Location.t -> ret:Ident.t * Typ.t - -> PulseAbductiveDomain.t - -> PulseExecutionState.t list PulseOperations.access_result + -> AbductiveDomain.t + -> ExecutionDomain.t list PulseOperations.access_result val dispatch : Tenv.t diff --git a/infer/src/pulse/PulseOperations.ml b/infer/src/pulse/PulseOperations.ml index 0584818d1..97f561e1a 100644 --- a/infer/src/pulse/PulseOperations.ml +++ b/infer/src/pulse/PulseOperations.ml @@ -14,7 +14,7 @@ type t = AbductiveDomain.t type 'a access_result = ('a, Diagnostic.t * t) result -let ok_continue post = Ok [PulseExecutionState.ContinueProgram post] +let ok_continue post = Ok [ExecutionDomain.ContinueProgram post] (** Check that the [address] is not known to be invalid *) let check_addr_access location (address, history) astate = @@ -495,7 +495,7 @@ let check_memory_leak_unreachable unreachable_attrs location astate = | _ -> result in - PulseBaseAddressAttributes.fold check_memory_leak unreachable_attrs (Ok ()) + BaseAddressAttributes.fold check_memory_leak unreachable_attrs (Ok ()) let remove_vars vars location astate = @@ -592,7 +592,7 @@ let apply_callee callee_pname call_loc callee_exec_state ~ret ~formals ~actuals in Some (f post) in - let open PulseExecutionState in + let open ExecutionDomain in match callee_exec_state with | AbortProgram _ -> (* Callee has failed; don't propagate the failure *) @@ -604,7 +604,7 @@ let apply_callee callee_pname call_loc callee_exec_state ~ret ~formals ~actuals let call ~caller_summary call_loc callee_pname ~ret ~actuals ~formals_opt - (astate : PulseAbductiveDomain.t) : (PulseExecutionState.t list, Diagnostic.t * t) result = + (astate : AbductiveDomain.t) : (ExecutionDomain.t list, Diagnostic.t * t) result = match PulsePayload.read_full ~caller_summary ~callee_pname with | Some (callee_proc_desc, exec_states) -> let formals = diff --git a/infer/src/pulse/PulseOperations.mli b/infer/src/pulse/PulseOperations.mli index bf777ca66..44127b3f1 100644 --- a/infer/src/pulse/PulseOperations.mli +++ b/infer/src/pulse/PulseOperations.mli @@ -9,11 +9,11 @@ open! IStd open PulseBasicInterface open PulseDomainInterface -type t = PulseAbductiveDomain.t +type t = AbductiveDomain.t type 'a access_result = ('a, Diagnostic.t * t) result -val ok_continue : t -> (PulseExecutionState.exec_state list, 'a) result +val ok_continue : t -> (ExecutionDomain.exec_state list, 'a) result module Closures : sig val check_captured_addresses : Location.t -> AbstractValue.t -> t -> (t, Diagnostic.t * t) result @@ -114,7 +114,7 @@ val call : -> actuals:((AbstractValue.t * ValueHistory.t) * Typ.t) list -> formals_opt:(Pvar.t * Typ.t) list option -> t - -> PulseExecutionState.t list access_result + -> ExecutionDomain.t list access_result (** perform an interprocedural call: apply the summary for the call proc name passed as argument if it exists *) diff --git a/infer/src/pulse/PulseSummary.ml b/infer/src/pulse/PulseSummary.ml index ea7e1039e..8ee479ae5 100644 --- a/infer/src/pulse/PulseSummary.ml +++ b/infer/src/pulse/PulseSummary.ml @@ -7,14 +7,15 @@ open! IStd module F = Format +open PulseDomainInterface -type t = PulseExecutionState.t list +type t = ExecutionDomain.t list -let of_posts pdesc posts = List.map posts ~f:(PulseExecutionState.of_post pdesc) +let of_posts pdesc posts = List.map posts ~f:(ExecutionDomain.of_post pdesc) let pp fmt summary = F.open_vbox 0 ; F.fprintf fmt "%d pre/post(s)@;" (List.length summary) ; List.iteri summary ~f:(fun i pre_post -> - F.fprintf fmt "#%d: @[%a@]@;" i PulseExecutionState.pp pre_post ) ; + F.fprintf fmt "#%d: @[%a@]@;" i ExecutionDomain.pp pre_post ) ; F.close_box () diff --git a/infer/src/pulse/PulseSummary.mli b/infer/src/pulse/PulseSummary.mli index ca6c1ac67..676759217 100644 --- a/infer/src/pulse/PulseSummary.mli +++ b/infer/src/pulse/PulseSummary.mli @@ -6,9 +6,10 @@ *) open! IStd +open PulseDomainInterface -type t = PulseExecutionState.t list +type t = ExecutionDomain.t list -val of_posts : Procdesc.t -> PulseExecutionState.t list -> t +val of_posts : Procdesc.t -> ExecutionDomain.t list -> t val pp : Format.formatter -> t -> unit