@@ -834,6 +834,16 @@ function _methods(@nospecialize(f), @nospecialize(t), lim::Int, world::UInt)
834
834
return _methods_by_ftype (tt, lim, world)
835
835
end
836
836
837
+ function _methods_ft (@nospecialize (ft:: Type ), @nospecialize (args), lim:: Int , world:: UInt )
838
+ if isa (args, Type)
839
+ u = unwrap_unionall (args)
840
+ tt = rewrap_unionall (Tuple{ft, u. parameters... }, args)
841
+ else
842
+ tt = Tuple{ft, args... }
843
+ end
844
+ return _methods_by_ftype (tt, lim, world)
845
+ end
846
+
837
847
function _methods_by_ftype (@nospecialize (t), lim:: Int , world:: UInt )
838
848
return _methods_by_ftype (t, lim, world, UInt[typemin (UInt)], UInt[typemax (UInt)])
839
849
end
@@ -1081,10 +1091,18 @@ function code_typed(@nospecialize(f), @nospecialize(types=Tuple);
1081
1091
debuginfo:: Symbol = :default ,
1082
1092
world = get_world_counter (),
1083
1093
interp = Core. Compiler. NativeInterpreter (world))
1084
- ccall (:jl_is_in_pure_context , Bool, ()) && error (" code reflection cannot be used from generated functions" )
1085
1094
if isa (f, Core. Builtin)
1086
1095
throw (ArgumentError (" argument is not a generic function" ))
1087
1096
end
1097
+ return code_typed_ftype (Core. Typeof (f), types; optimize, debuginfo, world, interp)
1098
+ end
1099
+
1100
+ function code_typed_ftype (@nospecialize (ft), @nospecialize (types= Tuple);
1101
+ optimize= true ,
1102
+ debuginfo:: Symbol = :default ,
1103
+ world = get_world_counter (),
1104
+ interp = Core. Compiler. NativeInterpreter (world))
1105
+ ccall (:jl_is_in_pure_context , Bool, ()) && error (" code reflection cannot be used from generated functions" )
1088
1106
if @isdefined (IRShow)
1089
1107
debuginfo = IRShow. debuginfo (debuginfo)
1090
1108
elseif debuginfo === :default
@@ -1095,7 +1113,11 @@ function code_typed(@nospecialize(f), @nospecialize(types=Tuple);
1095
1113
end
1096
1114
types = to_tuple_type (types)
1097
1115
asts = []
1098
- for x in _methods (f, types, - 1 , world)
1116
+ meths = _methods_ft (ft, types, - 1 , world)
1117
+ if meths === false
1118
+ error (" function type does not correspond to a generic function" )
1119
+ end
1120
+ for x in meths
1099
1121
meth = func_for_method_checked (x[3 ], types, x[2 ])
1100
1122
(code, ty) = Core. Compiler. typeinf_code (interp, meth, x[1 ], x[2 ], optimize)
1101
1123
code === nothing && error (" inference not successful" ) # inference disabled?
0 commit comments