diff --git a/base/loading.jl b/base/loading.jl index b85828e37a8b3..79d8674c940ce 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -746,11 +746,19 @@ function stale_cachefile(modpath::String, cachefile::String) modules, files, required_modules = parse_cache_header(io) # Check if transitive dependencies can be fullfilled - for mod in keys(required_modules) + for (mod, uuid) in required_modules if mod == :Main || mod == :Core || mod == :Base continue # Module is already loaded - elseif isdefined(Main, mod) + elseif isbindingresolved(Main, mod) + current_uuid = module_uuid(getfield(Main, mod)) + # Depends on the assumption that uuid monotonically increase + if current_uuid > uuid + # Module is newer, reject cache + return true + elseif current_uuid < uuid + warn("The currently loaded module $mod is older than the dependency for $cachefile and will be replaced.") + end continue end name = string(mod) diff --git a/src/dump.c b/src/dump.c index 7a32a63715d83..beeac990bc568 100644 --- a/src/dump.c +++ b/src/dump.c @@ -2282,8 +2282,12 @@ static jl_value_t *read_verify_mod_list(ios_t *s, arraylist_t *dependent_worlds) uint64_t uuid = read_uint64(s); jl_sym_t *sym = jl_symbol(name); jl_module_t *m = NULL; - if (jl_binding_resolved_p(jl_main_module, sym)) + if (jl_binding_resolved_p(jl_main_module, sym)) { m = (jl_module_t*)jl_get_global(jl_main_module, sym); + // Potentially two modules with the same name. + if (m && jl_is_module(m) && m->uuid != uuid) + m = NULL; + } if (!m) { static jl_value_t *require_func = NULL; if (!require_func)