From 49bfd206a0aa6e9dd92a1378010e5759fbca48d9 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Fri, 4 Dec 2020 05:47:38 -0800 Subject: [PATCH] [Refactoring] Use pvar instead of mangled in CapturedVar Summary: This diff uses Pvar.t in CapturedVar.t, so that * it can include additional info in Pvar.t * it can avoid some `Pvar.mk` calls when using the captured variables Reviewed By: jvillard Differential Revision: D25331763 fbshipit-source-id: 4e0c2ab4a --- infer/src/IR/CapturedVar.ml | 4 ++-- infer/src/IR/CapturedVar.mli | 2 +- infer/src/IR/DotCfg.ml | 2 +- infer/src/IR/Procdesc.ml | 4 ++-- infer/src/biabduction/Rearrange.ml | 3 +-- infer/src/checkers/SelfInBlock.ml | 12 +++++------- infer/src/clang/cMethod_trans.ml | 4 ++-- infer/src/clang/cTrans.ml | 3 +-- infer/src/pulse/PulseAbductiveDomain.ml | 6 +++--- infer/src/pulse/PulseOperations.ml | 4 +--- 10 files changed, 19 insertions(+), 25 deletions(-) diff --git a/infer/src/IR/CapturedVar.ml b/infer/src/IR/CapturedVar.ml index 26125f6e3..7039bf316 100644 --- a/infer/src/IR/CapturedVar.ml +++ b/infer/src/IR/CapturedVar.ml @@ -8,8 +8,8 @@ open! IStd module F = Format -type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] +type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] let pp fmt {name; typ; capture_mode} = - F.fprintf fmt "(%a,@,%a,@,%s)" Mangled.pp name (Typ.pp_full Pp.text) typ + F.fprintf fmt "(%a,@,%a,@,%s)" (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ (Pvar.string_of_capture_mode capture_mode) diff --git a/infer/src/IR/CapturedVar.mli b/infer/src/IR/CapturedVar.mli index 0603bcb0d..dea404e68 100644 --- a/infer/src/IR/CapturedVar.mli +++ b/infer/src/IR/CapturedVar.mli @@ -7,6 +7,6 @@ open! IStd -type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] +type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] val pp : Format.formatter -> t -> unit diff --git a/infer/src/IR/DotCfg.ml b/infer/src/IR/DotCfg.ml index 2118c0868..8a38b6837 100644 --- a/infer/src/IR/DotCfg.ml +++ b/infer/src/IR/DotCfg.ml @@ -24,7 +24,7 @@ let pp_var_list fmt etl = List.iter etl ~f:(fun {CapturedVar.name; typ; capture_mode} -> Format.fprintf fmt " [%s]%a:%a" (Pvar.string_of_capture_mode capture_mode) - Mangled.pp name (Typ.pp_full Pp.text) typ ) + (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) let pp_local_list fmt etl = List.iter ~f:(Procdesc.pp_local fmt) etl diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 07f6735a8..e34703876 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -792,7 +792,7 @@ let pp_captured_list fmt etl = ~f:(fun {CapturedVar.name; typ; capture_mode} -> Format.fprintf fmt " [%s] %a:%a" (Pvar.string_of_capture_mode capture_mode) - Mangled.pp name (Typ.pp_full Pp.text) typ ) + (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) etl @@ -847,7 +847,7 @@ let is_captured_pvar procdesc pvar = | _ -> false in - let pvar_matches_in_captured {CapturedVar.name} = Mangled.equal name pvar_name in + let pvar_matches_in_captured {CapturedVar.name} = Pvar.equal name pvar in let is_captured_var_objc_block = (* var is captured if the procedure is a objc block and the var is in the captured *) Procname.is_objc_block procname diff --git a/infer/src/biabduction/Rearrange.ml b/infer/src/biabduction/Rearrange.ml index 9b2a4fcc5..324f273f7 100644 --- a/infer/src/biabduction/Rearrange.ml +++ b/infer/src/biabduction/Rearrange.ml @@ -1288,9 +1288,8 @@ let check_call_to_objc_block_error tenv pdesc prop fun_exp loc = match get_exp_called () with | Some (_, Exp.Lvar pvar) -> (* pvar is the block *) - let name = Pvar.get_name pvar in List.exists - ~f:(fun {CapturedVar.name= cn} -> Mangled.equal name cn) + ~f:(fun {CapturedVar.name= cn} -> Pvar.equal pvar cn) (Procdesc.get_captured pdesc) | _ -> false diff --git a/infer/src/checkers/SelfInBlock.ml b/infer/src/checkers/SelfInBlock.ml index f7eac8536..7ba53bd55 100644 --- a/infer/src/checkers/SelfInBlock.ml +++ b/infer/src/checkers/SelfInBlock.ml @@ -148,11 +148,10 @@ module TransferFunctions = struct let pp_session_name _node fmt = F.pp_print_string fmt "SelfCapturedInBlock" let is_captured_self attributes pvar = - let pvar_name = Pvar.get_name pvar in Pvar.is_self pvar && List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Mangled.equal captured pvar_name && Typ.is_strong_pointer typ ) + Pvar.equal captured pvar && Typ.is_strong_pointer typ ) attributes.ProcAttributes.captured @@ -161,17 +160,16 @@ module TransferFunctions = struct (not (Pvar.is_self pvar)) && List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Typ.is_strong_pointer typ - && Mangled.equal captured (Pvar.get_name pvar) - && String.is_suffix ~suffix:"self" (String.lowercase (Mangled.to_string captured)) ) + Typ.is_strong_pointer typ && Pvar.equal captured pvar + && String.is_suffix ~suffix:"self" (String.lowercase (Pvar.to_string captured)) ) attributes.ProcAttributes.captured let is_captured_weak_self attributes pvar = List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Mangled.equal captured (Pvar.get_name pvar) - && String.is_substring ~substring:"self" (String.lowercase (Mangled.to_string captured)) + Pvar.equal captured pvar + && String.is_substring ~substring:"self" (String.lowercase (Pvar.to_string captured)) && Typ.is_weak_pointer typ ) attributes.ProcAttributes.captured diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index e7fc86297..d967cc4a9 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -207,7 +207,7 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) ?(record_lambda_capt in let captured_mangled = List.map - ~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= Pvar.get_name var; typ; capture_mode}) + ~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= var; typ; capture_mode}) captured in (* Retrieve captured variables from procdesc created when translating captured variables in lambda expression *) @@ -235,7 +235,7 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) ?(record_lambda_capt (* Captured variables for blocks are treated as parameters, but not for cpp lambdas *) let captured_as_formals = if is_cpp_lambda_call_operator then [] - else List.map ~f:(fun {CapturedVar.name; typ} -> (name, typ)) captured_mangled + else List.map ~f:(fun {CapturedVar.name; typ} -> (Pvar.get_name name, typ)) captured_mangled in let formals = captured_as_formals @ formals in let const_formals = diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 29e4d44bf..2adf6cbbe 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -828,9 +828,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let typ = match procname with | Procname.ObjC_Cpp cpp_pname when Procname.ObjC_Cpp.is_cpp_lambda cpp_pname -> - let pvar_name = Pvar.get_name pvar in List.find (Procdesc.get_captured context.procdesc) - ~f:(fun {CapturedVar.name= captured_var} -> Mangled.equal captured_var pvar_name) + ~f:(fun {CapturedVar.name= captured_var} -> Pvar.equal captured_var pvar) |> Option.value_map ~f:(fun {CapturedVar.typ} -> typ) ~default:typ | _ -> typ diff --git a/infer/src/pulse/PulseAbductiveDomain.ml b/infer/src/pulse/PulseAbductiveDomain.ml index 7eaa43d37..6adac2a81 100644 --- a/infer/src/pulse/PulseAbductiveDomain.ml +++ b/infer/src/pulse/PulseAbductiveDomain.ml @@ -305,12 +305,12 @@ let mk_initial proc_desc = let formals_and_captured = let proc_name = Procdesc.get_proc_name proc_desc in let location = Procdesc.get_loc proc_desc in - let init_var mangled = - let pvar = Pvar.mk mangled proc_name in + let init_var pvar = (Var.of_pvar pvar, (AbstractValue.mk_fresh (), [ValueHistory.FormalDeclared (pvar, location)])) in + let init_mangled mangled = init_var (Pvar.mk mangled proc_name) in let formals = - Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_var mangled) + Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_mangled mangled) in let captured = Procdesc.get_captured proc_desc |> List.map ~f:(fun {CapturedVar.name} -> init_var name) diff --git a/infer/src/pulse/PulseOperations.ml b/infer/src/pulse/PulseOperations.ml index e66e22707..8152e247e 100644 --- a/infer/src/pulse/PulseOperations.ml +++ b/infer/src/pulse/PulseOperations.ml @@ -521,9 +521,7 @@ let call ~caller_proc_desc err_log ~(callee_data : (Procdesc.t * PulseSummary.t) in let captured_vars = Procdesc.get_captured callee_proc_desc - |> List.map ~f:(fun {CapturedVar.name; capture_mode} -> - let pvar = Pvar.mk name callee_pname in - (Var.of_pvar pvar, capture_mode) ) + |> List.map ~f:(fun {CapturedVar.name; capture_mode} -> (Var.of_pvar name, capture_mode)) in let+ astate, captured_vars_with_actuals = match actuals with