@@ -2501,6 +2501,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
25012501 # write data over stdin to avoid the (unlikely) case of exceeding max command line size
25022502 write (io. in, """
25032503 empty!(Base.EXT_DORMITORY) # If we have a custom sysimage with `EXT_DORMITORY` prepopulated
2504+ Base.track_nested_precomp($(repr (vcat (Base. precompilation_stack, pkg. name))) )
25042505 Base.precompiling_extension = $(loading_extension)
25052506 Base.include_package_for_output($(pkg_str (pkg)) , $(repr (abspath (input))) , $(repr (depot_path)) , $(repr (dl_load_path)) ,
25062507 $(repr (load_path)) , $deps , $(repr (source_path (nothing ))) )
@@ -2509,6 +2510,17 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
25092510 return io
25102511end
25112512
2513+ const precompilation_stack = Vector {String} ()
2514+ # Helpful for debugging when precompilation is unexpectedly nested.
2515+ # Enable with `JULIA_DEBUG=nested_precomp`. Note that it expected to be nested in classical code-load precompilation
2516+ # TODO : Add detection if extension precompilation is nested and error / return early?
2517+ function track_nested_precomp (pkg_names:: Vector{String} )
2518+ append! (Base. precompilation_stack, pkg_names)
2519+ if length (Base. precompilation_stack) > 1
2520+ @debug " Nested precompilation: $(join (Base. precompilation_stack, " > " )) " _group= :nested_precomp
2521+ end
2522+ end
2523+
25122524function compilecache_dir (pkg:: PkgId )
25132525 entrypath, entryfile = cache_file_entry (pkg)
25142526 return joinpath (DEPOT_PATH [1 ], entrypath)
0 commit comments