@@ -1683,6 +1683,8 @@ function CacheFlags(cf::CacheFlags=CacheFlags(ccall(:jl_cache_flags, UInt8, ()))
16831683 opt_level === nothing ? cf. opt_level : opt_level
16841684 )
16851685end
1686+ # reflecting jloptions.c defaults
1687+ const DefaultCacheFlags = CacheFlags (use_pkgimages= true , debug_level= isdebugbuild () ? 2 : 1 , check_bounds= 0 , inline= true , opt_level= 2 )
16861688
16871689function _cacheflag_to_uint8 (cf:: CacheFlags ):: UInt8
16881690 f = UInt8 (0 )
@@ -1694,12 +1696,29 @@ function _cacheflag_to_uint8(cf::CacheFlags)::UInt8
16941696 return f
16951697end
16961698
1699+ function translate_cache_flags (cacheflags:: CacheFlags , defaultflags:: CacheFlags )
1700+ opts = String[]
1701+ cacheflags. use_pkgimages != defaultflags. use_pkgimages && push! (opts, cacheflags. use_pkgimages ? " --pkgimages=yes" : " --pkgimages=no" )
1702+ cacheflags. debug_level != defaultflags. debug_level && push! (opts, " -g$(cacheflags. debug_level) " )
1703+ cacheflags. check_bounds != defaultflags. check_bounds && push! (opts, (" --check-bounds=auto" , " --check-bounds=yes" , " --check-bounds=no" )[cacheflags. check_bounds + 1 ])
1704+ cacheflags. inline != defaultflags. inline && push! (opts, cacheflags. inline ? " --inline=yes" : " --inline=no" )
1705+ cacheflags. opt_level != defaultflags. opt_level && push! (opts, " -O$(cacheflags. opt_level) " )
1706+ return opts
1707+ end
1708+
16971709function show (io:: IO , cf:: CacheFlags )
1698- print (io, " use_pkgimages = " , cf. use_pkgimages)
1699- print (io, " , debug_level = " , cf. debug_level)
1700- print (io, " , check_bounds = " , cf. check_bounds)
1701- print (io, " , inline = " , cf. inline)
1702- print (io, " , opt_level = " , cf. opt_level)
1710+ print (io, " CacheFlags(" )
1711+ print (io, " ; use_pkgimages=" )
1712+ print (io, cf. use_pkgimages)
1713+ print (io, " , debug_level=" )
1714+ print (io, cf. debug_level)
1715+ print (io, " , check_bounds=" )
1716+ print (io, cf. check_bounds)
1717+ print (io, " , inline=" )
1718+ print (io, cf. inline)
1719+ print (io, " , opt_level=" )
1720+ print (io, cf. opt_level)
1721+ print (io, " )" )
17031722end
17041723
17051724struct ImageTarget
@@ -2950,7 +2969,8 @@ end
29502969
29512970const PRECOMPILE_TRACE_COMPILE = Ref {String} ()
29522971function create_expr_cache (pkg:: PkgId , input:: String , output:: String , output_o:: Union{Nothing, String} ,
2953- concrete_deps:: typeof (_concrete_dependencies), flags:: Cmd = ` ` , internal_stderr:: IO = stderr , internal_stdout:: IO = stdout , isext:: Bool = false )
2972+ concrete_deps:: typeof (_concrete_dependencies), flags:: Cmd = ` ` , cacheflags:: CacheFlags = CacheFlags (),
2973+ internal_stderr:: IO = stderr , internal_stdout:: IO = stdout , isext:: Bool = false )
29542974 @nospecialize internal_stderr internal_stdout
29552975 rm (output, force= true ) # Remove file if it exists
29562976 output_o === nothing || rm (output_o, force= true )
@@ -2993,24 +3013,29 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
29933013 deps = deps_eltype * " [" * join (deps_strs, " ," ) * " ]"
29943014 precomp_stack = " Base.PkgId[$(join (map (pkg_str, vcat (Base. precompilation_stack, pkg)), " , " )) ]"
29953015
3016+ if output_o === nothing
3017+ # remove options that make no difference given the other cache options
3018+ cacheflags = CacheFlags (cacheflags, opt_level= 0 )
3019+ end
3020+ opts = translate_cache_flags (cacheflags, CacheFlags ()) # julia_cmd is generated for the running system, and must be fixed if running for precompile instead
29963021 if output_o != = nothing
29973022 @debug " Generating object cache file for $(repr (" text/plain" , pkg)) "
29983023 cpu_target = get (ENV , " JULIA_CPU_TARGET" , nothing )
2999- opts = ` --output-o $( output_o) --output-ji $(output) --output-incremental=yes `
3024+ push! ( opts, " --output-o" , output_o)
30003025 else
30013026 @debug " Generating cache file for $(repr (" text/plain" , pkg)) "
30023027 cpu_target = nothing
3003- opts = ` -O0 --output-ji $(output) --output-incremental=yes`
30043028 end
3029+ push! (opts, " --output-ji" , output)
3030+ isassigned (PRECOMPILE_TRACE_COMPILE) && push! (opts, " --trace-compile=$(PRECOMPILE_TRACE_COMPILE[]) " )
30053031
3006- trace = isassigned (PRECOMPILE_TRACE_COMPILE) ? ` --trace-compile=$(PRECOMPILE_TRACE_COMPILE[]) --trace-compile-timing` : ` `
30073032 io = open (pipeline (addenv (` $(julia_cmd (;cpu_target):: Cmd )
3008- $(flags)
3009- $(opts)
3010- --startup-file=no --history-file=no --warn-overwrite =yes
3011- --color= $(have_color === nothing ? " auto " : have_color ? " yes" : " no " )
3012- $trace
3013- -` ,
3033+ $(flags)
3034+ $(opts)
3035+ --output-incremental =yes
3036+ --startup-file=no --history-file=no --warn-overwrite= yes
3037+ $(have_color === nothing ? " --color=auto " : have_color ? " --color=yes " : " --color=no " )
3038+ -` ,
30143039 " OPENBLAS_NUM_THREADS" => 1 ,
30153040 " JULIA_NUM_THREADS" => 1 ),
30163041 stderr = internal_stderr, stdout = internal_stdout),
@@ -3128,7 +3153,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
31283153 close (tmpio_o)
31293154 close (tmpio_so)
31303155 end
3131- p = create_expr_cache (pkg, path, tmppath, tmppath_o, concrete_deps, flags, internal_stderr, internal_stdout, isext)
3156+ p = create_expr_cache (pkg, path, tmppath, tmppath_o, concrete_deps, flags, cacheflags, internal_stderr, internal_stdout, isext)
31323157
31333158 if success (p)
31343159 if cache_objects
@@ -4133,5 +4158,5 @@ end
41334158
41344159precompile (include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof (_concrete_dependencies), Nothing)) || @assert false
41354160precompile (include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof (_concrete_dependencies), String)) || @assert false
4136- precompile (create_expr_cache, (PkgId, String, String, String, typeof (_concrete_dependencies), Cmd, IO, IO)) || @assert false
4137- precompile (create_expr_cache, (PkgId, String, String, Nothing, typeof (_concrete_dependencies), Cmd, IO, IO)) || @assert false
4161+ precompile (create_expr_cache, (PkgId, String, String, String, typeof (_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
4162+ precompile (create_expr_cache, (PkgId, String, String, Nothing, typeof (_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
0 commit comments