diff --git a/base/loading.jl b/base/loading.jl index fb056f5f61c7c..5d5b6e6944924 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2501,6 +2501,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o:: # write data over stdin to avoid the (unlikely) case of exceeding max command line size write(io.in, """ empty!(Base.EXT_DORMITORY) # If we have a custom sysimage with `EXT_DORMITORY` prepopulated + Base.track_nested_precomp($(repr(vcat(Base.precompilation_stack, pkg.name)))) Base.precompiling_extension = $(loading_extension) Base.include_package_for_output($(pkg_str(pkg)), $(repr(abspath(input))), $(repr(depot_path)), $(repr(dl_load_path)), $(repr(load_path)), $deps, $(repr(source_path(nothing)))) @@ -2509,6 +2510,17 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o:: return io end +const precompilation_stack = Vector{String}() +# Helpful for debugging when precompilation is unexpectedly nested. +# Enable with `JULIA_DEBUG=nested_precomp`. Note that it expected to be nested in classical code-load precompilation +# TODO: Add detection if extension precompilation is nested and error / return early? +function track_nested_precomp(pkg_names::Vector{String}) + append!(Base.precompilation_stack, pkg_names) + if length(Base.precompilation_stack) > 1 + @debug "Nested precompilation: $(join(Base.precompilation_stack, " > "))" _group=:nested_precomp + end +end + function compilecache_dir(pkg::PkgId) entrypath, entryfile = cache_file_entry(pkg) return joinpath(DEPOT_PATH[1], entrypath) diff --git a/pkgimage.mk b/pkgimage.mk index 4fd23fbe8fa2c..fcf50e6427e45 100644 --- a/pkgimage.mk +++ b/pkgimage.mk @@ -56,6 +56,9 @@ cache-debug-$1: $$(BUILDDIR)/stdlib/$1.debug.image .SECONDARY: $$(BUILDDIR)/stdlib/$1.release.image $$(BUILDDIR)/stdlib/$1.debug.image endef +# Note: you can check for the correctness of this tree by running `JULIA_DEBUG=nested_precomp make` and looking +# out for `Debug: Nested precompilation` logs. + # no dependencies $(eval $(call stdlib_builder,MozillaCACerts_jll,)) $(eval $(call stdlib_builder,ArgTools,))