Specifically, when using an overlay method table, redefining non-overlay methods return a stale MethodInstance:
using Base.Experimental: @MethodTable
@MethodTable CUSTOM_MT
parent(x) = x + 1
# First lookup
mi1 = ccall(:jl_method_lookup_by_tt, Any, (Any, Csize_t, Any),
Tuple{typeof(parent), Int}, Base.get_world_counter(), CUSTOM_MT)
# Redefine
@eval parent(x) = x + 100
# Second lookup - should return different mi
mi2 = ccall(:jl_method_lookup_by_tt, Any, (Any, Csize_t, Any),
Tuple{typeof(parent), Int}, Base.get_world_counter(), CUSTOM_MT)
@assert mi1 !== mi2
The above works fine when passing nothing as method table. So that's also the workaround; overlays are also used by inference anyways. But it does break the case when calling an overlay method directly, in which case we need to look in the overlay method table (x-ref JuliaGPU/GPUCompiler.jl#208).
Specifically, when using an overlay method table, redefining non-overlay methods return a stale MethodInstance:
The above works fine when passing
nothingas method table. So that's also the workaround; overlays are also used by inference anyways. But it does break the case when calling an overlay method directly, in which case we need to look in the overlay method table (x-ref JuliaGPU/GPUCompiler.jl#208).