Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 21 additions & 3 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,27 @@ end

export methodinstance, generic_methodinstance

@inline function signature_type_by_tt(ft::Type, tt::Type)
u = Base.unwrap_unionall(tt)::DataType
return Base.rewrap_unionall(Tuple{ft, u.parameters...}, tt)
# JuliaLang/julia#62001 specializes closed type-valued callees and arguments on
# `Core.TypeEgal` dispatch keys, making `Type{T}` elements non-dispatchable, so
# normalize them when constructing signature types.
@static if isdefined(Core, :TypeEgal)
@inline function dispatch_key(@nospecialize(t))
if Base.isType(t)
u = Base.type_parameter(t)
!Base.has_free_typevars(u) && return Core.TypeEgal{u}
end
return t
end

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

# create a MethodError from a function type
Expand Down
12 changes: 12 additions & 0 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
end
end

@testset "method instances for type-valued callees and arguments" begin
# JuliaLang/julia#62001: closed type-valued callees and arguments
# dispatch on Core.TypeEgal keys instead of Type{T}
mi = GPUCompiler.methodinstance(Base._stable_typeof(Vector{Int}), Tuple{typeof(undef), Int})
@test mi isa Core.MethodInstance
@test Base.isdispatchtuple(mi.specTypes)

mi = GPUCompiler.methodinstance(typeof(identity), Tuple{Type{Int}})
@test mi isa Core.MethodInstance
@test Base.isdispatchtuple(mi.specTypes)
end

@testset "compilation" begin
@testset "callable structs" begin
mod = @eval module $(gensym())
Expand Down