diff --git a/src/compiler.jl b/src/compiler.jl index 6a1f329c8b..3d2bf46238 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -29,7 +29,9 @@ import Enzyme: allocatedinline, ismutabletype, create_fresh_codeinfo, - add_edge! + add_edge!, + LookupError + using Enzyme import EnzymeCore @@ -6270,7 +6272,7 @@ function thunk_generator(world::UInt, source::Union{Method, LineNumberNode}, @no mi = my_methodinstance(Mode == API.DEM_ForwardMode ? Forward : Reverse, ft, primal_tt, world, min_world, max_world) - mi === nothing && return stub(world, source, :(throw(MethodError($ft, $primal_tt, $world)))) + mi === nothing && return stub(world, source, :(throw(LookupError($ft, $primal_tt, $world)))) check_activity_cache_invalidations(world) @@ -6389,7 +6391,7 @@ function deferred_id_generator(world::UInt, source::Union{Method, LineNumberNode mi = my_methodinstance(Mode == API.DEM_ForwardMode ? Forward : Reverse, ft, primal_tt, world, min_world, max_world) - mi === nothing && return stub(world, source, :(throw(MethodError($ft, $primal_tt, $world)))) + mi === nothing && return stub(world, source, :(throw(LookupError($ft, $primal_tt, $world)))) target = EnzymeTarget() rt2 = if A isa UnionAll diff --git a/src/typeutils/inference.jl b/src/typeutils/inference.jl index 9939bb8e5b..979cbd8335 100644 --- a/src/typeutils/inference.jl +++ b/src/typeutils/inference.jl @@ -115,7 +115,7 @@ function primal_return_type_generator(world::UInt, source, self, @nospecialize(m slotnames, Core.svec(), ) - mi === nothing && return stub(world, source, :(throw(MethodError(ft, tt, $world)))) + mi === nothing && return stub(world, source, :(throw(LookupError(ft, tt, $world)))) result = primal_return_type_world(mode, world, mi) code = Any[Core.Compiler.ReturnNode(result)] diff --git a/src/utils.jl b/src/utils.jl index cde33d6baa..c2dc83e995 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -264,6 +264,22 @@ end end +struct LookupError <: Exception + ft::Type + tt::Type + world::UInt +end + +function Base.showerror(io::IO, e::LookupError) + print(io, "no method matching ") + Base.show_signature_function(io, e.ft) + Base.show_tuple_as_call(io, :function, e.tt; hasfirst=false, kwargs=nothing) + if Core._hasmethod(GPUCompiler.signature_type_by_tt(e.ft, e.tt)) + print(io, "\n(method exists but is not available in world age $(e.world))") + end +end + + """ create_fresh_codeinfo(fn, source, world) @@ -378,9 +394,9 @@ function methodinstance_generator(world::UInt, source, self, @nospecialize(mode: min_world = Ref{UInt}(typemin(UInt)) max_world = Ref{UInt}(typemax(UInt)) mi = my_methodinstance(mode.instance, ft, tt, world, min_world, max_world) - - mi === nothing && return stub(world, source, :(throw(MethodError(ft, tt, $world)))) - + + mi === nothing && return stub(world, source, :(throw(LookupError($ft, $tt, $world)))) + code = Any[Core.Compiler.ReturnNode(mi)] ci = create_fresh_codeinfo(prevmethodinstance, source, world, slotnames, code)