From 7b502d863c816f31e241513715e097a66b41512b Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Fri, 7 Feb 2020 02:17:20 -0800 Subject: [PATCH] [nullsafe][refactor] Simplify and rename a function. Summary: This diff is part of cleaning up of Typestate.ml mess to make it somewhat maintainable. This method is always called with `default` equivalent to (exp, typestate); also there is no semantical need to return typestate because it never gets changed. Reviewed By: ngorogiannis Differential Revision: D19767366 fbshipit-source-id: 173dcbbca --- infer/src/nullsafe/typeCheck.ml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/infer/src/nullsafe/typeCheck.ml b/infer/src/nullsafe/typeCheck.ml index 8b3d40965..26934c479 100644 --- a/infer/src/nullsafe/typeCheck.ml +++ b/infer/src/nullsafe/typeCheck.ml @@ -213,14 +213,15 @@ let handle_field_access_via_temporary idenv curr_pname typestate exp = exp -(* Convert a function call to a pvar. *) -let handle_function_call tenv curr_pname typestate exp default ~is_assignment ~call_node ~node id = +(* Try to convert a function call to a pvar that originated it; fallback to an original expression in case of failure *) +let funcall_exp_to_original_pvar_exp tenv curr_pname typestate exp ~is_assignment ~call_node ~node + id = match Errdesc.find_normal_variable_funcall call_node id with | Some (Exp.Const (Const.Cfun pn), _, _, _) when not (ComplexExpressions.procname_used_in_condition pn) -> ( match ComplexExpressions.exp_to_string tenv node exp with | None -> - default + exp | Some exp_str -> let pvar = Pvar.mk (Mangled.from_string exp_str) curr_pname in let already_defined_in_typestate = @@ -232,11 +233,11 @@ let handle_function_call tenv curr_pname typestate exp default ~is_assignment ~c | None -> false in - if is_assignment && already_defined_in_typestate then default + if is_assignment && already_defined_in_typestate then exp (* Don't overwrite pvar representing result of function call. *) - else (Exp.Lvar pvar, typestate) ) + else Exp.Lvar pvar ) | _ -> - default + exp (* If this is an assignment, update the typestate for a field access pvar. *) @@ -270,16 +271,18 @@ let convert_complex_exp_to_pvar tenv idenv curr_pname let default = (exp, typestate) in match exp with | Exp.Var id when Errdesc.find_normal_variable_funcall node id <> None -> - handle_function_call tenv curr_pname typestate exp default ~is_assignment ~call_node:node - ~node id + ( funcall_exp_to_original_pvar_exp tenv curr_pname typestate exp ~is_assignment + ~call_node:node ~node id + , typestate ) | Exp.Lvar pvar when Pvar.is_frontend_tmp pvar -> ( let frontend_variable_assignment = Errdesc.find_program_variable_assignment original_node pvar in match frontend_variable_assignment with | Some (call_node, id) -> - handle_function_call tenv curr_pname typestate exp default ~is_assignment ~call_node ~node - id + ( funcall_exp_to_original_pvar_exp tenv curr_pname typestate exp ~is_assignment ~call_node + ~node id + , typestate ) | _ -> default ) | Exp.Lvar _ ->