Skip to content

Commit

Permalink
[inferpython][capture][refactor] unifiying call_function with/without…
Browse files Browse the repository at this point in the history
… named args

Summary: there was room for simplification and factorization here.

Reviewed By: ngorogiannis

Differential Revision:
D69591092

Privacy Context Container: L1208441

fbshipit-source-id: 2efabbe5ef7c6ec088d8748344d1bb7330073886
  • Loading branch information
davidpichardie authored and facebook-github-bot committed Feb 13, 2025
1 parent fa4fa77 commit 4256d73
Showing 1 changed file with 7 additions and 35 deletions.
42 changes: 7 additions & 35 deletions infer/src/python/PyIR.ml
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,6 @@ type 'a pyresult = ('a, Error.t) result
module Stmt = struct
let pp_call_arg fmt value = Exp.pp fmt value

let unnamed_call_arg value = value

let unnamed_call_args args = List.map ~f:unnamed_call_arg args

type gen_kind = Generator | Coroutine | AsyncGenerator

type t =
Expand Down Expand Up @@ -1208,13 +1204,14 @@ let read_code_qual_name st c =
internal_error st (Error.CodeWithoutQualifiedName c)


let call_function_with_unnamed_args st ?arg_names exp args =
let call_function st ?arg_names arg =
let open IResult.Let_syntax in
let args = Stmt.unnamed_call_args args in
let* args, st = State.pop_n_and_cast st arg in
let* fun_exp, st = State.pop st in
let lhs, st = State.fresh_id st in
let arg_names = Option.value arg_names ~default:Exp.none in
let* stmt =
match exp with
match fun_exp with
| Exp.BuiltinCaller call ->
Ok (Stmt.BuiltinCall {lhs; call; args; arg_names})
| Exp.ContextManagerExit self_if_needed ->
Expand All @@ -1225,12 +1222,12 @@ let call_function_with_unnamed_args st ?arg_names exp args =
Stmt.Call {lhs; exp; args; arg_names}
in
let st = State.push_stmt st stmt in
Ok (lhs, st)
let st = State.push st (Exp.Temp lhs) in
Ok (st, None)


let call_builtin_function st ?arg_names call args =
let lhs, st = State.fresh_id st in
let args = Stmt.unnamed_call_args args in
let arg_names = Option.value arg_names ~default:Exp.none in
let stmt = Stmt.BuiltinCall {lhs; call; args; arg_names} in
let st = State.push_stmt st stmt in
Expand Down Expand Up @@ -1289,35 +1286,10 @@ let make_function st flags =
Ok (st, None)


let call_function st arg =
let open IResult.Let_syntax in
let* args, st = State.pop_n_and_cast st arg in
let* fun_exp, st = State.pop st in
let* id, st = call_function_with_unnamed_args st fun_exp args in
let st = State.push st (Exp.Temp id) in
Ok (st, None)


let call_function_kw st argc =
let open IResult.Let_syntax in
let* arg_names, st = State.pop_and_cast st in
let arg_names = Some arg_names in
(* a tuple containing the arguments names *)
let* args, st = State.pop_n_and_cast st argc in
let* exp, st = State.pop st in
let lhs, st = State.fresh_id st in
let arg_names = Option.value arg_names ~default:Exp.none in
let* stmt =
match exp with
| Exp.BuiltinCaller call ->
Ok (Stmt.BuiltinCall {lhs; call; args; arg_names})
| exp ->
let+ exp = State.cast_exp st exp in
Stmt.Call {lhs; exp; args; arg_names}
in
let st = State.push_stmt st stmt in
let st = State.push st (Exp.Temp lhs) in
Ok (st, None)
call_function st ~arg_names argc


let call_function_ex st flags =
Expand Down

0 comments on commit 4256d73

Please sign in to comment.