Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ JL_DLLEXPORT jl_typemap_entry_t *jl_mt_find_cache_entry(jl_methcache_t *mc JL_PR
return entry;
}

static jl_method_instance_t *jl_mt_assoc_by_type(jl_methcache_t *mc JL_PROPAGATES_ROOT, jl_datatype_t *tt JL_MAYBE_UNROOTED, size_t world)
static jl_method_instance_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_methcache_t *mc JL_PROPAGATES_ROOT, jl_datatype_t *tt JL_MAYBE_UNROOTED, size_t world)
{
jl_typemap_entry_t *entry = jl_mt_find_cache_entry(mc, tt, world);
if (entry)
Expand All @@ -1943,11 +1943,11 @@ static jl_method_instance_t *jl_mt_assoc_by_type(jl_methcache_t *mc JL_PROPAGATE
if (!mi) {
size_t min_valid = 0;
size_t max_valid = ~(size_t)0;
matc = _gf_invoke_lookup((jl_value_t*)tt, jl_method_table, world, 0, &min_valid, &max_valid);
matc = _gf_invoke_lookup((jl_value_t*)tt, mt, world, 0, &min_valid, &max_valid);
if (matc) {
jl_method_t *m = matc->method;
jl_svec_t *env = matc->sparams;
mi = cache_method(jl_method_table, mc, &mc->cache, (jl_value_t*)mc, tt, m, world, min_valid, max_valid, env);
mi = cache_method(mt, mc, &mc->cache, (jl_value_t*)mc, tt, m, world, min_valid, max_valid, env);
JL_GC_POP();
return mi;
}
Expand Down Expand Up @@ -3191,7 +3191,7 @@ JL_DLLEXPORT jl_value_t *jl_method_lookup_by_tt(jl_tupletype_t *tt, size_t world
mt = (jl_methtable_t*) _mt;
}
jl_methcache_t *mc = mt->cache;
jl_method_instance_t *mi = jl_mt_assoc_by_type(mc, tt, world);
jl_method_instance_t *mi = jl_mt_assoc_by_type(mt, mc, tt, world);
if (!mi)
return jl_nothing;
return (jl_value_t*) mi;
Expand All @@ -3206,7 +3206,7 @@ JL_DLLEXPORT jl_method_instance_t *jl_method_lookup(jl_value_t **args, size_t na
if (entry)
return entry->func.linfo;
jl_tupletype_t *tt = arg_type_tuple(args[0], &args[1], nargs);
return jl_mt_assoc_by_type(mc, tt, world);
return jl_mt_assoc_by_type(jl_method_table, mc, tt, world);
}

// return a Vector{Any} of svecs, each describing a method match:
Expand Down Expand Up @@ -4280,7 +4280,7 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
assert(tt);
// cache miss case
jl_methcache_t *mc = jl_method_table->cache;
mfunc = jl_mt_assoc_by_type(mc, tt, world);
mfunc = jl_mt_assoc_by_type(jl_method_table, mc, tt, world);
if (jl_options.malloc_log)
jl_gc_sync_total_bytes(last_alloc); // discard allocation count from compilation
if (mfunc == NULL) {
Expand Down
26 changes: 26 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8443,6 +8443,32 @@ let ms = Base._methods_by_ftype(Tuple{typeof(sin), Int}, OverlayModule.mt, 1, Ba
@test isempty(ms)
end

# fresh module to ensure uncached methods
module OverlayMTTest
using Base.Experimental: @MethodTable, @overlay
@MethodTable(mt)

function overlay_only end
@overlay mt overlay_only(x::Int) = x * 2
end

# #60702 & #60716: Overlay methods must be found without prior cache population
let world = Base.get_world_counter()
mi = Base.method_instance(OverlayMTTest.overlay_only, Tuple{Int};
world, method_table=OverlayMTTest.mt)
@test mi isa Core.MethodInstance
@test mi.def.module === OverlayMTTest
end

# #60712: Global-only methods must NOT be found via custom MT
let
@eval global_only_func(x::Int) = x + 1
world = Base.get_world_counter()
mi = Base.method_instance(global_only_func, Tuple{Int};
world, method_table=OverlayMTTest.mt)
@test mi === nothing
end

# precompilation
let load_path = mktempdir()
depot_path = mkdepottempdir()
Expand Down