[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
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent 6972d9cb91
commit 49bfd206a0

@ -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)

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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 =

@ -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

@ -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)

@ -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

Loading…
Cancel
Save