Revert "[Refactoring] Use pvar instead of mangled in CapturedVar"

Reviewed By: jvillard

Differential Revision: D25337049

fbshipit-source-id: ba9d85193
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent ab2813e355
commit 2d8f404a5f

@ -8,8 +8,8 @@
open! IStd open! IStd
module F = Format module F = Format
type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare]
let pp fmt {name; typ; capture_mode} = let pp fmt {name; typ; capture_mode} =
F.fprintf fmt "(%a,@,%a,@,%s)" (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ F.fprintf fmt "(%a,@,%a,@,%s)" Mangled.pp name (Typ.pp_full Pp.text) typ
(Pvar.string_of_capture_mode capture_mode) (Pvar.string_of_capture_mode capture_mode)

@ -7,6 +7,6 @@
open! IStd open! IStd
type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare]
val pp : Format.formatter -> t -> unit 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} -> List.iter etl ~f:(fun {CapturedVar.name; typ; capture_mode} ->
Format.fprintf fmt " [%s]%a:%a" Format.fprintf fmt " [%s]%a:%a"
(Pvar.string_of_capture_mode capture_mode) (Pvar.string_of_capture_mode capture_mode)
(Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) Mangled.pp name (Typ.pp_full Pp.text) typ )
let pp_local_list fmt etl = List.iter ~f:(Procdesc.pp_local fmt) etl 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} -> ~f:(fun {CapturedVar.name; typ; capture_mode} ->
Format.fprintf fmt " [%s] %a:%a" Format.fprintf fmt " [%s] %a:%a"
(Pvar.string_of_capture_mode capture_mode) (Pvar.string_of_capture_mode capture_mode)
(Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) Mangled.pp name (Typ.pp_full Pp.text) typ )
etl etl
@ -847,7 +847,7 @@ let is_captured_pvar procdesc pvar =
| _ -> | _ ->
false false
in in
let pvar_matches_in_captured {CapturedVar.name} = Pvar.equal name pvar in let pvar_matches_in_captured {CapturedVar.name} = Mangled.equal name pvar_name in
let is_captured_var_objc_block = let is_captured_var_objc_block =
(* var is captured if the procedure is a objc block and the var is in the captured *) (* var is captured if the procedure is a objc block and the var is in the captured *)
Procname.is_objc_block procname Procname.is_objc_block procname

@ -1288,8 +1288,9 @@ let check_call_to_objc_block_error tenv pdesc prop fun_exp loc =
match get_exp_called () with match get_exp_called () with
| Some (_, Exp.Lvar pvar) -> | Some (_, Exp.Lvar pvar) ->
(* pvar is the block *) (* pvar is the block *)
let name = Pvar.get_name pvar in
List.exists List.exists
~f:(fun {CapturedVar.name= cn} -> Pvar.equal pvar cn) ~f:(fun {CapturedVar.name= cn} -> Mangled.equal name cn)
(Procdesc.get_captured pdesc) (Procdesc.get_captured pdesc)
| _ -> | _ ->
false false

@ -148,10 +148,11 @@ module TransferFunctions = struct
let pp_session_name _node fmt = F.pp_print_string fmt "SelfCapturedInBlock" let pp_session_name _node fmt = F.pp_print_string fmt "SelfCapturedInBlock"
let is_captured_self attributes pvar = let is_captured_self attributes pvar =
let pvar_name = Pvar.get_name pvar in
Pvar.is_self pvar Pvar.is_self pvar
&& List.exists && List.exists
~f:(fun {CapturedVar.name= captured; typ} -> ~f:(fun {CapturedVar.name= captured; typ} ->
Pvar.equal captured pvar && Typ.is_strong_pointer typ ) Mangled.equal captured pvar_name && Typ.is_strong_pointer typ )
attributes.ProcAttributes.captured attributes.ProcAttributes.captured
@ -160,16 +161,17 @@ module TransferFunctions = struct
(not (Pvar.is_self pvar)) (not (Pvar.is_self pvar))
&& List.exists && List.exists
~f:(fun {CapturedVar.name= captured; typ} -> ~f:(fun {CapturedVar.name= captured; typ} ->
Typ.is_strong_pointer typ && Pvar.equal captured pvar Typ.is_strong_pointer typ
&& String.is_suffix ~suffix:"self" (String.lowercase (Pvar.to_string captured)) ) && Mangled.equal captured (Pvar.get_name pvar)
&& String.is_suffix ~suffix:"self" (String.lowercase (Mangled.to_string captured)) )
attributes.ProcAttributes.captured attributes.ProcAttributes.captured
let is_captured_weak_self attributes pvar = let is_captured_weak_self attributes pvar =
List.exists List.exists
~f:(fun {CapturedVar.name= captured; typ} -> ~f:(fun {CapturedVar.name= captured; typ} ->
Pvar.equal captured pvar Mangled.equal captured (Pvar.get_name pvar)
&& String.is_substring ~substring:"self" (String.lowercase (Pvar.to_string captured)) && String.is_substring ~substring:"self" (String.lowercase (Mangled.to_string captured))
&& Typ.is_weak_pointer typ ) && Typ.is_weak_pointer typ )
attributes.ProcAttributes.captured attributes.ProcAttributes.captured

@ -207,7 +207,7 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) ?(record_lambda_capt
in in
let captured_mangled = let captured_mangled =
List.map List.map
~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= var; typ; capture_mode}) ~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= Pvar.get_name var; typ; capture_mode})
captured captured
in in
(* Retrieve captured variables from procdesc created when translating captured variables in lambda expression *) (* 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 *) (* Captured variables for blocks are treated as parameters, but not for cpp lambdas *)
let captured_as_formals = let captured_as_formals =
if is_cpp_lambda_call_operator then [] if is_cpp_lambda_call_operator then []
else List.map ~f:(fun {CapturedVar.name; typ} -> (Pvar.get_name name, typ)) captured_mangled else List.map ~f:(fun {CapturedVar.name; typ} -> (name, typ)) captured_mangled
in in
let formals = captured_as_formals @ formals in let formals = captured_as_formals @ formals in
let const_formals = let const_formals =

@ -828,8 +828,9 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let typ = let typ =
match procname with match procname with
| Procname.ObjC_Cpp cpp_pname when Procname.ObjC_Cpp.is_cpp_lambda cpp_pname -> | 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) List.find (Procdesc.get_captured context.procdesc)
~f:(fun {CapturedVar.name= captured_var} -> Pvar.equal captured_var pvar) ~f:(fun {CapturedVar.name= captured_var} -> Mangled.equal captured_var pvar_name)
|> Option.value_map ~f:(fun {CapturedVar.typ} -> typ) ~default:typ |> Option.value_map ~f:(fun {CapturedVar.typ} -> typ) ~default:typ
| _ -> | _ ->
typ typ

@ -305,12 +305,12 @@ let mk_initial proc_desc =
let formals_and_captured = let formals_and_captured =
let proc_name = Procdesc.get_proc_name proc_desc in let proc_name = Procdesc.get_proc_name proc_desc in
let location = Procdesc.get_loc proc_desc in let location = Procdesc.get_loc proc_desc in
let init_var pvar = let init_var mangled =
let pvar = Pvar.mk mangled proc_name in
(Var.of_pvar pvar, (AbstractValue.mk_fresh (), [ValueHistory.FormalDeclared (pvar, location)])) (Var.of_pvar pvar, (AbstractValue.mk_fresh (), [ValueHistory.FormalDeclared (pvar, location)]))
in in
let init_mangled mangled = init_var (Pvar.mk mangled proc_name) in
let formals = let formals =
Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_mangled mangled) Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_var mangled)
in in
let captured = let captured =
Procdesc.get_captured proc_desc |> List.map ~f:(fun {CapturedVar.name} -> init_var name) Procdesc.get_captured proc_desc |> List.map ~f:(fun {CapturedVar.name} -> init_var name)

@ -520,7 +520,9 @@ let call ~caller_proc_desc err_log ~(callee_data : (Procdesc.t * PulseSummary.t)
in in
let captured_vars = let captured_vars =
Procdesc.get_captured callee_proc_desc Procdesc.get_captured callee_proc_desc
|> List.map ~f:(fun {CapturedVar.name; capture_mode} -> (Var.of_pvar name, capture_mode)) |> List.map ~f:(fun {CapturedVar.name; capture_mode} ->
let pvar = Pvar.mk name callee_pname in
(Var.of_pvar pvar, capture_mode) )
in in
let+ astate, captured_vars_with_actuals = let+ astate, captured_vars_with_actuals =
match actuals with match actuals with

Loading…
Cancel
Save