Skip to content

Commit c145ea3

Browse files
vchuravyvtjnashmaleadt
authored
Specialize method instance if necessary (#553)
Co-authored-by: Jameson Nash <vtjnash@gmail.com> Co-authored-by: Tim Besard <tim.besard@gmail.com>
1 parent 05be474 commit c145ea3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/jlgen.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tls_world_age() = ccall(:jl_get_tls_world_age, UInt, ())
1414
export methodinstance
1515

1616
@inline function signature_type_by_tt(ft::Type, tt::Type)
17-
u = Base.unwrap_unionall(tt)
17+
u = Base.unwrap_unionall(tt)::DataType
1818
return Base.rewrap_unionall(Tuple{ft, u.parameters...}, tt)
1919
end
2020

@@ -62,15 +62,21 @@ methodinstance
6262
if VERSION >= v"1.11.0-DEV.1552"
6363

6464
# XXX: version of Base.method_instance that uses a function type
65-
function methodinstance(ft, tt, world=tls_world_age())
65+
@inline function methodinstance(@nospecialize(ft::Type), @nospecialize(tt::Type), world::Integer=tls_world_age())
6666
sig = signature_type_by_tt(ft, tt)
6767

6868
mi = ccall(:jl_method_lookup_by_tt, Any,
6969
(Any, Csize_t, Any),
7070
sig, world, #=method_table=# nothing)
7171
mi === nothing && throw(MethodError(ft, tt, world))
72+
mi = mi::MethodInstance
7273

73-
return mi::MethodInstance
74+
# `jl_method_lookup_by_tt` and `jl_method_lookup` can return a unspecialized mi
75+
if !Base.isdispatchtuple(mi.specTypes)
76+
mi = CC.specialize_method(mi.def, sig, mi.sparam_vals)::MethodInstance
77+
end
78+
79+
return mi
7480
end
7581

7682
# on older versions of Julia, the run-time lookup is much slower, so we'll need to cache it

0 commit comments

Comments
 (0)