Skip to content

jl_method_lookup_by_tt with overlay MT doesn't always always respect redefinitions #60712

@maleadt

Description

@maleadt

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions