Skip to content

Commit

Permalink
Allow redefinition of invoked methods with new signatures (fixes #4…
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Aug 30, 2022
1 parent ccf04c2 commit f9712f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1867,14 +1867,14 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
// invoke-dispatch, check invokeTypes for validity
struct jl_typemap_assoc search = {invokeTypes, method->primary_world, NULL, 0, ~(size_t)0};
oldentry = jl_typemap_assoc_by_type(jl_atomic_load_relaxed(&mt->defs), &search, /*offs*/0, /*subtype*/0);
assert(oldentry);
if (oldentry->func.method == mi->def.method) {
if (oldentry && oldentry->func.method == mi->def.method) {
// We can safely keep this method
jl_array_ptr_set(backedges, insb++, invokeTypes);
jl_array_ptr_set(backedges, insb++, caller);
continue;
} else {
invalidate_method_instance(&do_nothing_with_codeinst, caller, max_world, 1);
invalidated = 1;
}
invalidate_method_instance(&do_nothing_with_codeinst, caller, max_world, 1);
invalidated = 1;
}
}
jl_array_del_end(backedges, nb - insb);
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7809,6 +7809,13 @@ import .Foo45350: x45350
f45350() = (global x45350 = 2)
@test_throws ErrorException f45350()

# #46503 - redefine `invoke`d methods
foo46503(@nospecialize(a), b::Union{Vector{Any}, Float64, Nothing}) = rand()
foo46503(a::Int, b::Nothing) = @invoke foo46503(a::Any, b)
@test 0 <= foo46503(1, nothing) <= 1
foo46503(@nospecialize(a), b::Union{Nothing, Float64}) = rand() + 10
@test 10 <= foo46503(1, nothing) <= 11

@testset "effect override on Symbol(::String)" begin
@test Core.Compiler.is_foldable(Base.infer_effects(Symbol, (String,)))
end
Expand Down

0 comments on commit f9712f9

Please sign in to comment.