MCPcopy Index your code
hub / github.com/python/mypy / gen_calls_to_correct_impl

Function gen_calls_to_correct_impl

mypyc/irbuild/function.py:1000–1045  ·  view source on GitHub ↗
(
    builder: IRBuilder, impl_to_use: Value, arg_info: ArgInfo, fitem: FuncDef, line: int
)

Source from the content-addressed store, hash-verified

998
999
1000def gen_calls_to_correct_impl(
1001 builder: IRBuilder, impl_to_use: Value, arg_info: ArgInfo, fitem: FuncDef, line: int
1002) -> None:
1003 current_func_decl = builder.mapper.func_to_decl[fitem]
1004
1005 def gen_native_func_call_and_return(fdef: FuncDef) -> None:
1006 func_decl = builder.mapper.func_to_decl[fdef]
1007 ret_val = builder.builder.call(
1008 func_decl, arg_info.args, arg_info.arg_kinds, arg_info.arg_names, line
1009 )
1010 coerced = builder.coerce(ret_val, current_func_decl.sig.ret_type, line)
1011 builder.add(Return(coerced))
1012
1013 int_type_obj = builder.load_builtin("builtins.int", line)
1014 assert int_type_obj
1015 is_int = builder.builder.type_is_op(impl_to_use, int_type_obj, line)
1016
1017 native_call, non_native_call = BasicBlock(), BasicBlock()
1018 builder.add_bool_branch(is_int, native_call, non_native_call)
1019 builder.activate_block(native_call)
1020
1021 passed_id = builder.add(Unbox(impl_to_use, int_rprimitive, line))
1022
1023 native_ids = get_native_impl_ids(builder, fitem)
1024 for impl, i in native_ids.items():
1025 call_impl, next_impl = BasicBlock(), BasicBlock()
1026
1027 current_id = builder.load_int(i)
1028 cond = builder.binary_op(passed_id, current_id, "==", line)
1029 builder.add_bool_branch(cond, call_impl, next_impl)
1030
1031 # Call the registered implementation
1032 builder.activate_block(call_impl)
1033
1034 gen_native_func_call_and_return(impl)
1035 builder.activate_block(next_impl)
1036
1037 # We've already handled all the possible integer IDs, so we should never get here
1038 builder.add(Unreachable())
1039
1040 builder.activate_block(non_native_call)
1041 ret_val = builder.py_call(
1042 impl_to_use, arg_info.args, line, arg_info.arg_kinds, arg_info.arg_names
1043 )
1044 coerced = builder.coerce(ret_val, current_func_decl.sig.ret_type, line)
1045 builder.add(Return(coerced))
1046
1047
1048def gen_dispatch_func_ir(

Calls 15

BasicBlockClass · 0.90
UnboxClass · 0.90
UnreachableClass · 0.90
ReturnClass · 0.90
get_native_impl_idsFunction · 0.85
type_is_opMethod · 0.80
load_builtinMethod · 0.45
add_bool_branchMethod · 0.45
activate_blockMethod · 0.45
addMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…