Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialize MI if necessary #553

Merged
merged 10 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tls_world_age() = ccall(:jl_get_tls_world_age, UInt, ())
export methodinstance

@inline function signature_type_by_tt(ft::Type, tt::Type)
u = Base.unwrap_unionall(tt)
u = Base.unwrap_unionall(tt)::DataType
return Base.rewrap_unionall(Tuple{ft, u.parameters...}, tt)
end

Expand Down Expand Up @@ -62,15 +62,21 @@ methodinstance
if VERSION >= v"1.11.0-DEV.1552"

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

mi = ccall(:jl_method_lookup_by_tt, Any,
(Any, Csize_t, Any),
sig, world, #=method_table=# nothing)
mi === nothing && throw(MethodError(ft, tt, world))
mi = mi::MethodInstance

return mi::MethodInstance
# `jl_method_lookup_by_tt` and `jl_method_lookup` can return a unspecialized mi
if !Base.isdispatchtuple(mi.specTypes)
mi = CC.specialize_method(mi.def, sig, mi.sparam_vals)::MethodInstance
end

return mi
end

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