@@ -833,21 +833,31 @@ def generate_singledispatch_dispatch_function(
833
833
current_func_decl = builder .mapper .func_to_decl [fitem ]
834
834
arg_info = get_args (builder , current_func_decl .sig .args , line )
835
835
836
- def gen_func_call_and_return (func_name : str , fullname : Optional [str ] = None ) -> None :
837
- func = load_func (builder , func_name , fullname , line )
838
- ret_val = builder .builder .py_call (
839
- func , arg_info .args , line , arg_info .arg_kinds , arg_info .arg_names
840
- )
836
+ def gen_func_call_and_return (
837
+ func_name : str ,
838
+ fdef : FuncDef ,
839
+ fullname : Optional [str ] = None
840
+ ) -> None :
841
+ if is_decorated (builder , fdef ):
842
+ func = load_func (builder , func_name , fullname , line )
843
+ ret_val = builder .builder .py_call (
844
+ func , arg_info .args , line , arg_info .arg_kinds , arg_info .arg_names
845
+ )
846
+ else :
847
+ func_decl = builder .mapper .func_to_decl [fdef ]
848
+ ret_val = builder .builder .call (
849
+ func_decl , arg_info .args , arg_info .arg_kinds , arg_info .arg_names , line
850
+ )
841
851
coerced = builder .coerce (ret_val , current_func_decl .sig .ret_type , line )
842
852
builder .nonlocal_control [- 1 ].gen_return (builder , coerced , line )
843
853
844
854
# Add all necessary imports of other modules that have registered functions in other modules
845
855
# We're doing this in a separate pass over the implementations because that avoids the
846
856
# complexity and code size implications of generating this import before every call to a
847
857
# registered implementation that might need this imported
848
- # TODO: avoid adding imports if we use native calls for all of the registered implementations
849
- # in a module (once we add support for using native calls for registered implementations)
850
858
for _ , impl in impls :
859
+ if not is_decorated (builder , impl ):
860
+ continue
851
861
module_name = impl .fullname .rsplit ('.' )[0 ]
852
862
if module_name not in builder .imports :
853
863
# We need to generate an import here because the module needs to be imported before we
@@ -868,15 +878,15 @@ def gen_func_call_and_return(func_name: str, fullname: Optional[str] = None) ->
868
878
# The shortname of a function is just '{class}.{func_name}', and we don't support
869
879
# singledispatchmethod yet, so that is always the same as the function name
870
880
name = short_id_from_name (impl .name , impl .name , impl .line )
871
- gen_func_call_and_return (name , fullname = impl .fullname )
881
+ gen_func_call_and_return (name , impl , fullname = impl .fullname )
872
882
builder .activate_block (next_impl )
873
883
874
884
# We don't pass fullname here because getting the fullname of the main generated singledispatch
875
885
# function isn't easy, and we don't need it because the fullname is only needed for making sure
876
886
# we load the function from another module instead of the globals dict if it's defined in
877
887
# another module, which will never be true for the main singledispatch function (it's always
878
888
# generated in the same module as the dispatch function)
879
- gen_func_call_and_return (main_singledispatch_function_name )
889
+ gen_func_call_and_return (main_singledispatch_function_name , fitem )
880
890
881
891
882
892
def gen_dispatch_func_ir (
0 commit comments