From e82ce2c16dd7d70a35456440ab58328053cdadf7 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 26 Jun 2026 00:11:20 +0000 Subject: [PATCH 1/2] compiler: Use upcoming TypeEgal dispatch keys for type callees The Base PR JuliaLang/julia#62001 is expected to spell exact closed type-object dispatch keys as Core.TypeEgal. When looking up method instances from a stable function type, use that upcoming dispatch spelling for closed Type{T} callee keys so constructor calls such as Memory{Int}(undef, n) remain compatible with Base.isdispatchtuple. AI disclosure: This commit was prepared with assistance from generative AI. The resulting PR should be checked carefully by a maintainer before merging. Co-authored-by: OpenAI Codex --- src/jlgen.jl | 14 +++++++++++++- test/native.jl | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index 8a6eab48..30217aa4 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -14,9 +14,21 @@ end export methodinstance, generic_methodinstance +@static if isdefined(Core, :TypeEgal) + @inline function dispatch_function_key(ft::Type) + if Base.isType(ft) + f = Base.type_parameter(ft) + !Base.has_free_typevars(f) && return Core.TypeEgal{f} + end + return ft + end +else + @inline dispatch_function_key(ft::Type) = ft +end + @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) + return Base.rewrap_unionall(Tuple{dispatch_function_key(ft), u.parameters...}, tt) end # create a MethodError from a function type diff --git a/test/native.jl b/test/native.jl index bb9abeee..4838af57 100644 --- a/test/native.jl +++ b/test/native.jl @@ -25,6 +25,12 @@ end end +@testset "method instances for type-valued callees" begin + mi = GPUCompiler.methodinstance(Base._stable_typeof(Memory{Int}), Tuple{typeof(undef), Int}) + @test mi isa Core.MethodInstance + @test Base.isdispatchtuple(mi.specTypes) +end + @testset "compilation" begin @testset "callable structs" begin mod = @eval module $(gensym()) From 93d700978fef59b146328d9afa62823966d31be6 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 10 Jul 2026 11:02:43 +0200 Subject: [PATCH 2/2] compiler: Also use TypeEgal dispatch keys for type-valued arguments After JuliaLang/julia#62001, type-valued arguments (not just callees) specialize on Core.TypeEgal keys, and Type{T} elements anywhere in the signature fail Base.isdispatchtuple. Normalize all signature elements instead of only the function type. Also make the test compatible with Julia 1.10 by constructing a Vector instead of a Memory, and cover the argument position. Co-Authored-By: Claude Fable 5 --- src/jlgen.jl | 28 +++++++++++++++++----------- test/native.jl | 10 ++++++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/jlgen.jl b/src/jlgen.jl index 30217aa4..cf234b9c 100644 --- a/src/jlgen.jl +++ b/src/jlgen.jl @@ -14,21 +14,27 @@ end export methodinstance, generic_methodinstance +# 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_function_key(ft::Type) - if Base.isType(ft) - f = Base.type_parameter(ft) - !Base.has_free_typevars(f) && return Core.TypeEgal{f} + @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 ft + return t end -else - @inline dispatch_function_key(ft::Type) = ft -end -@inline function signature_type_by_tt(ft::Type, tt::Type) - u = Base.unwrap_unionall(tt)::DataType - return Base.rewrap_unionall(Tuple{dispatch_function_key(ft), u.parameters...}, tt) + @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 diff --git a/test/native.jl b/test/native.jl index 4838af57..c7eb7f91 100644 --- a/test/native.jl +++ b/test/native.jl @@ -25,8 +25,14 @@ end end -@testset "method instances for type-valued callees" begin - mi = GPUCompiler.methodinstance(Base._stable_typeof(Memory{Int}), Tuple{typeof(undef), Int}) +@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