Skip to content

Commit 056e68b

Browse files
authored
bpart: Skip inserting image backedges while we're generating a pkgimage (#58843)
Should speed up deeply nested precompiles by skipping unnecessary work here. PR is against #58830 to avoid conflicts, but semantically independent.
1 parent 0ea036b commit 056e68b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

base/invalidation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ function scan_new_method!(method::Method, image_backedges_only::Bool)
206206
end
207207

208208
function scan_new_methods!(extext_methods::Vector{Any}, internal_methods::Vector{Any}, image_backedges_only::Bool)
209+
if image_backedges_only && Base.generating_output(true)
210+
# Replacing image bindings is forbidden during incremental precompilation - skip backedge insertion
211+
return
212+
end
209213
for method in internal_methods
210214
if isa(method, Method)
211215
scan_new_method!(method, image_backedges_only)

src/module.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,14 @@ JL_DLLEXPORT jl_binding_partition_t *jl_replace_binding_locked2(jl_binding_t *b,
16691669
// Until the first such replacement, we can fast-path validation.
16701670
// For these purposes, we consider the `Main` module to be a non-sysimg module.
16711671
// This is legal, because we special case the `Main` in check_safe_import_from.
1672-
if (jl_object_in_image((jl_value_t*)b) && b->globalref->mod != jl_main_module && jl_atomic_load_relaxed(&jl_first_image_replacement_world) == ~(size_t)0)
1672+
if (jl_object_in_image((jl_value_t*)b) && b->globalref->mod != jl_main_module && jl_atomic_load_relaxed(&jl_first_image_replacement_world) == ~(size_t)0) {
1673+
// During incremental compilation replacement of image bindings is forbidden;
1674+
// We use this to avoid inserting backedges while loading pkgimages.
1675+
// `check_safe_newbinding` checks an equivalent condition on `b->globalref->mod`,
1676+
// but doesn't quite query `jl_object_in_image`, so assert here to be extra sure.
1677+
assert(!(jl_options.incremental && jl_generating_output()));
16731678
jl_atomic_store_relaxed(&jl_first_image_replacement_world, new_world);
1679+
}
16741680

16751681
assert(jl_atomic_load_relaxed(&b->partitions) == old_bpart);
16761682
jl_binding_partition_t *new_bpart = new_binding_partition();

0 commit comments

Comments
 (0)