Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow redefinition of invoked methods with new signatures #46538

Merged
merged 1 commit into from
Aug 30, 2022
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
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