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

Avoid unnecessary invalidations for invoked fallbacks #45001

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,21 @@ static void jl_insert_method_instances(jl_array_t *list)
jl_typemap_entry_t *entry = jl_typemap_assoc_by_type(mt->defs, &search, /*offs*/0, /*subtype*/1);
if (entry) {
jl_value_t *mworld = entry->func.value;
if (jl_is_method(mworld) && mi->def.method != (jl_method_t*)mworld && jl_type_morespecific(((jl_method_t*)mworld)->sig, mi->def.method->sig)) {
// If a newer method would now be selected by dispatch, we need to
// invalidate.
//
// Note: the check of the module primary_world is a hack to prevent
// invoke(f, Tuple{AbstractType, ...}, args...)
// calls from a more specific method of `f` being spuriously invalidated.
// (An example is `copyto!(::BitArray, ::Broadcasted)` which calls the
// fallback `copyto!(::AbstractArray, ::Broadcasted)` for small outputs.)
// But this only works if the caller is from the same module as the
// fallback method. To do better we need the ability to mark specific
// MethodInstances as having been called from `invoke`.
if (jl_is_method(mworld) &&
mi->def.method != (jl_method_t*)mworld &&
mi->def.method->module->primary_world < ((jl_method_t*)mworld)->module->primary_world &&
jl_type_morespecific(((jl_method_t*)mworld)->sig, mi->def.method->sig)) {
jl_array_uint8_set(valids, i, 0);
invalidate_backedges(&remove_code_instance_from_validation, mi, world, "jl_insert_method_instance");
// The codeinst of this mi haven't yet been removed
Expand Down