Skip to content

Commit 1baffbb

Browse files
authored
Merge pull request #871 from JuliaGPU/tb/typeegal-dispatch-keys
Use upcoming TypeEgal dispatch keys for type callees
2 parents 1a9099b + 93d7009 commit 1baffbb

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/jlgen.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,27 @@ end
1414

1515
export methodinstance, generic_methodinstance
1616

17-
@inline function signature_type_by_tt(ft::Type, tt::Type)
18-
u = Base.unwrap_unionall(tt)::DataType
19-
return Base.rewrap_unionall(Tuple{ft, u.parameters...}, tt)
17+
# JuliaLang/julia#62001 specializes closed type-valued callees and arguments on
18+
# `Core.TypeEgal` dispatch keys, making `Type{T}` elements non-dispatchable, so
19+
# normalize them when constructing signature types.
20+
@static if isdefined(Core, :TypeEgal)
21+
@inline function dispatch_key(@nospecialize(t))
22+
if Base.isType(t)
23+
u = Base.type_parameter(t)
24+
!Base.has_free_typevars(u) && return Core.TypeEgal{u}
25+
end
26+
return t
27+
end
28+
29+
@inline function signature_type_by_tt(ft::Type, tt::Type)
30+
u = Base.unwrap_unionall(tt)::DataType
31+
return Base.rewrap_unionall(Tuple{dispatch_key(ft), map(dispatch_key, u.parameters)...}, tt)
32+
end
33+
else
34+
@inline function signature_type_by_tt(ft::Type, tt::Type)
35+
u = Base.unwrap_unionall(tt)::DataType
36+
return Base.rewrap_unionall(Tuple{ft, u.parameters...}, tt)
37+
end
2038
end
2139

2240
# create a MethodError from a function type

test/native.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
end
2626
end
2727

28+
@testset "method instances for type-valued callees and arguments" begin
29+
# JuliaLang/julia#62001: closed type-valued callees and arguments
30+
# dispatch on Core.TypeEgal keys instead of Type{T}
31+
mi = GPUCompiler.methodinstance(Base._stable_typeof(Vector{Int}), Tuple{typeof(undef), Int})
32+
@test mi isa Core.MethodInstance
33+
@test Base.isdispatchtuple(mi.specTypes)
34+
35+
mi = GPUCompiler.methodinstance(typeof(identity), Tuple{Type{Int}})
36+
@test mi isa Core.MethodInstance
37+
@test Base.isdispatchtuple(mi.specTypes)
38+
end
39+
2840
@testset "compilation" begin
2941
@testset "callable structs" begin
3042
mod = @eval module $(gensym())

0 commit comments

Comments
 (0)