[nullsafe][EASY] Log callee annotated signature when typechecking SIL call instruction

Summary:
This was needed countless of times. We log current signature, but not
callees.

Reviewed By: dulmarod

Differential Revision: D20765107

fbshipit-source-id: 399926c65
master
Mitya Lyubarskiy 5 years ago committed by Facebook GitHub Bot
parent 869ba0f966
commit d51a688a1b

@ -1027,72 +1027,76 @@ let calc_typestate_after_call find_canonical_duplicate calls_this checks tenv id
let typecheck_sil_call_function find_canonical_duplicate checks tenv instr_ref typestate idenv let typecheck_sil_call_function find_canonical_duplicate checks tenv instr_ref typestate idenv
~callee_pname ~curr_pname curr_pdesc curr_annotated_signature calls_this ~nullsafe_mode ~callee_pname ~curr_pname curr_pdesc curr_annotated_signature calls_this ~nullsafe_mode
ret_id_typ etl_ loc callee_pname_java cflags node = ret_id_typ etl_ loc callee_pname_java cflags node =
let callee_attributes = L.d_with_indent ~name:"typecheck_sil_call_function" (fun () ->
match PatternMatch.lookup_attributes tenv callee_pname with let callee_attributes =
| Some proc_attributes -> match PatternMatch.lookup_attributes tenv callee_pname with
proc_attributes | Some proc_attributes ->
| None -> proc_attributes
let formals = | None ->
List.mapi let formals =
~f:(fun i (_, typ) -> List.mapi
let arg = ~f:(fun i (_, typ) ->
if Int.equal i 0 && not (Procname.Java.is_static callee_pname_java) then let arg =
Mangled.this if Int.equal i 0 && not (Procname.Java.is_static callee_pname_java) then
else Printf.sprintf "arg%d" i |> Mangled.from_string Mangled.this
in else Printf.sprintf "arg%d" i |> Mangled.from_string
(arg, typ) ) in
etl_ (arg, typ) )
in etl_
let ret_type = Procname.Java.get_return_typ callee_pname_java in in
let proc_attributes = let ret_type = Procname.Java.get_return_typ callee_pname_java in
{ (ProcAttributes.default (SourceFile.invalid __FILE__) callee_pname) with let proc_attributes =
ProcAttributes.formals { (ProcAttributes.default (SourceFile.invalid __FILE__) callee_pname) with
; ret_type } ProcAttributes.formals
; ret_type }
in
proc_attributes
in
let etl = drop_unchecked_params calls_this curr_pname callee_attributes etl_ in
let call_params, typestate1 =
let handle_et (e1, t1) (etl1, typestate1) =
typecheck_expr_for_errors ~nullsafe_mode find_canonical_duplicate curr_pdesc calls_this
checks tenv node instr_ref typestate e1 loc ;
let e2 =
convert_complex_exp_to_pvar tenv idenv curr_pname curr_annotated_signature
~is_assignment:false ~node ~original_node:node e1 typestate1 loc
in
(((e1, e2), t1) :: etl1, typestate1)
in in
proc_attributes List.fold_right ~f:handle_et etl ~init:([], typestate)
in
let etl = drop_unchecked_params calls_this curr_pname callee_attributes etl_ in
let call_params, typestate1 =
let handle_et (e1, t1) (etl1, typestate1) =
typecheck_expr_for_errors ~nullsafe_mode find_canonical_duplicate curr_pdesc calls_this checks
tenv node instr_ref typestate e1 loc ;
let e2 =
convert_complex_exp_to_pvar tenv idenv curr_pname curr_annotated_signature
~is_assignment:false ~node ~original_node:node e1 typestate1 loc
in in
(((e1, e2), t1) :: etl1, typestate1) let pname = callee_attributes.ProcAttributes.proc_name in
in let is_trusted_callee =
List.fold_right ~f:handle_et etl ~init:([], typestate) let caller_nullsafe_mode = NullsafeMode.of_procname tenv curr_pname in
in let callee_class = Procname.get_class_type_name pname in
let pname = callee_attributes.ProcAttributes.proc_name in Option.value_map callee_class
let is_trusted_callee = ~f:(NullsafeMode.is_trusted_name caller_nullsafe_mode)
let caller_nullsafe_mode = NullsafeMode.of_procname tenv curr_pname in ~default:false
let callee_class = Procname.get_class_type_name pname in in
Option.value_map callee_class let callee_annotated_signature =
~f:(NullsafeMode.is_trusted_name caller_nullsafe_mode) Models.get_modelled_annotated_signature ~is_trusted_callee tenv callee_attributes
~default:false in
in if Config.write_html then
let callee_annotated_signature = L.d_printfln "Callee signature: %a" (AnnotatedSignature.pp pname) callee_annotated_signature ;
Models.get_modelled_annotated_signature ~is_trusted_callee tenv callee_attributes let signature_params =
in drop_unchecked_signature_params callee_attributes callee_annotated_signature
let signature_params = in
drop_unchecked_signature_params callee_attributes callee_annotated_signature let is_anonymous_inner_class_constructor =
in Procname.Java.is_anonymous_inner_class_constructor_exn callee_pname_java
let is_anonymous_inner_class_constructor = in
Procname.Java.is_anonymous_inner_class_constructor_exn callee_pname_java let do_return (ret_ta, ret_typ) typestate' =
in let mk_return_range () = (ret_typ, ret_ta) in
let do_return (ret_ta, ret_typ) typestate' = let id = fst ret_id_typ in
let mk_return_range () = (ret_typ, ret_ta) in TypeState.add_id id (mk_return_range ()) typestate' ~descr:"typecheck_sil_call_function"
let id = fst ret_id_typ in in
TypeState.add_id id (mk_return_range ()) typestate' ~descr:"typecheck_sil_call_function" let typestate_after_call, finally_resolved_ret =
in calc_typestate_after_call find_canonical_duplicate calls_this checks tenv idenv instr_ref
let typestate_after_call, finally_resolved_ret = signature_params cflags call_params ~is_anonymous_inner_class_constructor
calc_typestate_after_call find_canonical_duplicate calls_this checks tenv idenv instr_ref ~callee_annotated_signature ~callee_attributes ~callee_pname ~callee_pname_java
signature_params cflags call_params ~is_anonymous_inner_class_constructor ~curr_pname ~curr_pdesc ~curr_annotated_signature ~nullsafe_mode ~typestate ~typestate1
~callee_annotated_signature ~callee_attributes ~callee_pname ~callee_pname_java ~curr_pname loc node
~curr_pdesc ~curr_annotated_signature ~nullsafe_mode ~typestate ~typestate1 loc node in
in do_return finally_resolved_ret typestate_after_call )
do_return finally_resolved_ret typestate_after_call
(** Typecheck an instruction. *) (** Typecheck an instruction. *)

Loading…
Cancel
Save