From bdf976b26069349d9f07b7327efc859aaa71e848 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 7 Jan 2023 12:36:12 -0500 Subject: [PATCH 1/2] make cache mismatch log more informative --- base/loading.jl | 30 +++++++++++++++++++++++++++++- src/staticdata_utils.c | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index f7ff11f1ae165..3f25b627460cc 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2505,6 +2505,30 @@ function check_clone_targets(clone_targets) end end +struct CacheFlags + # ??OOCDDP - see jl_cache_flags + use_pkgimages::Bool + debug_level::Int + check_bounds::Bool + opt_level::Int + + CacheFlags(f::Int) = CacheFlags(UInt8(f)) + function CacheFlags(f::UInt8) + s = bitstring(f) + use_pkgimages = parse(Bool, s[end]) + debug_level = parse(Int, s[end-2:end-1], base=2) + check_bounds = parse(Bool, s[end-3]) + opt_level = parse(Int, s[end-5:end-4], base=2) + new(use_pkgimages, debug_level, check_bounds, opt_level) + end +end +function show(io::IO, cf::CacheFlags) + print(io, "use_pkgimages = ", cf.use_pkgimages) + print(io, ", debug_level = ", cf.debug_level) + print(io, ", check_bounds = ", cf.check_bounds) + print(io, ", opt_level = ", cf.opt_level) +end + # returns true if it "cachefile.ji" is stale relative to "modpath.jl" and build_id for modkey # otherwise returns the list of dependencies to also check @constprop :none function stale_cachefile(modpath::String, cachefile::String; ignore_loaded::Bool = false) @@ -2523,7 +2547,11 @@ end return true # ignore empty file end if ccall(:jl_match_cache_flags, UInt8, (UInt8,), flags) == 0 - @debug "Rejecting cache file $cachefile for $modkey since the flags are mismatched" cachefile_flags=flags current_flags=ccall(:jl_cache_flags, UInt8, ()) + @debug """ + Rejecting cache file $cachefile for $modkey since the flags are mismatched + current session: $(CacheFlags(ccall(:jl_cache_flags, UInt8, ()))) + cache file: $(CacheFlags(flags)) + """ return true end pkgimage = !isempty(clone_targets) diff --git a/src/staticdata_utils.c b/src/staticdata_utils.c index 220a354847dfe..cb107b06a9585 100644 --- a/src/staticdata_utils.c +++ b/src/staticdata_utils.c @@ -621,6 +621,7 @@ JL_DLLEXPORT uint8_t jl_cache_flags(void) flags |= (jl_options.opt_level & 3) << 4; // NOTES: // In contrast to check-bounds, inline has no "observable effect" + // CacheFlags in loading.jl should be kept in-sync with this return flags; } From 6d08729858f41fdf3e9c3a0a8b1aaf236999fef8 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 7 Jan 2023 22:28:40 -0500 Subject: [PATCH 2/2] use bitmasking instead --- base/loading.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 3f25b627460cc..9137651007c30 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2514,11 +2514,10 @@ struct CacheFlags CacheFlags(f::Int) = CacheFlags(UInt8(f)) function CacheFlags(f::UInt8) - s = bitstring(f) - use_pkgimages = parse(Bool, s[end]) - debug_level = parse(Int, s[end-2:end-1], base=2) - check_bounds = parse(Bool, s[end-3]) - opt_level = parse(Int, s[end-5:end-4], base=2) + use_pkgimages = Bool(f & 1) + debug_level = Int((f >> 1) & 3) + check_bounds = Bool((f >> 2) & 1) + opt_level = Int((f >> 4) & 3) new(use_pkgimages, debug_level, check_bounds, opt_level) end end