-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using and import only load on current process #19073
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,42 +151,19 @@ function _include_from_serialized(path::String) | |
end | ||
|
||
# returns an array of modules loaded, or an Exception that describes why it failed | ||
# and also attempts to load the same file across all nodes (if toplevel_node and myid() == master) | ||
# and it reconnects the Base.Docs.META | ||
function _require_from_serialized(node::Int, mod::Symbol, path_to_try::String, toplevel_load::Bool) | ||
function _require_from_serialized(mod::Symbol, path_to_try::String, toplevel_load::Bool) | ||
local restored = nothing | ||
local content::Vector{UInt8} | ||
if toplevel_load && myid() == 1 && nprocs() > 1 | ||
# broadcast top-level import/using from node 1 (only) | ||
if node == myid() | ||
if myid() == 1 | ||
if toplevel_load | ||
content = open(read, path_to_try) | ||
restored = _include_from_serialized(content) | ||
else | ||
content = remotecall_fetch(open, node, read, path_to_try) | ||
restored = _include_from_serialized(path_to_try) | ||
end | ||
restored = _include_from_serialized(content) | ||
isa(restored, Exception) && return restored | ||
others = filter(x -> x != myid(), procs()) | ||
refs = Any[ | ||
(p, @spawnat(p, | ||
let m = try | ||
_include_from_serialized(content) | ||
catch ex | ||
isa(ex, Exception) ? ex : ErrorException(string(ex)) | ||
end | ||
isa(m, Exception) ? m : nothing | ||
end)) | ||
for p in others ] | ||
for (id, ref) in refs | ||
m = fetch(ref) | ||
if m !== nothing | ||
warn("Node state is inconsistent: node $id failed to load cache from $path_to_try. Got:") | ||
warn(m, prefix="WARNING: ") | ||
end | ||
end | ||
elseif node == myid() | ||
restored = _include_from_serialized(path_to_try) | ||
else | ||
content = remotecall_fetch(open, node, read, path_to_try) | ||
content = remotecall_fetch(open, 1, read, path_to_try) | ||
restored = _include_from_serialized(content) | ||
end | ||
|
||
|
@@ -203,18 +180,18 @@ end | |
# returns `true` if require found a precompile cache for this mod, but couldn't load it | ||
# returns `false` if the module isn't known to be precompilable | ||
# returns the set of modules restored if the cache load succeeded | ||
function _require_search_from_serialized(node::Int, mod::Symbol, sourcepath::String, toplevel_load::Bool) | ||
if node == myid() | ||
function _require_search_from_serialized(mod::Symbol, sourcepath::String, toplevel_load::Bool) | ||
if 1 == myid() | ||
paths = find_all_in_cache_path(mod) | ||
else | ||
paths = @fetchfrom node find_all_in_cache_path(mod) | ||
paths = @fetchfrom 1 find_all_in_cache_path(mod) | ||
end | ||
|
||
for path_to_try in paths::Vector{String} | ||
if stale_cachefile(sourcepath, path_to_try) | ||
continue | ||
end | ||
restored = _require_from_serialized(node, mod, path_to_try, toplevel_load) | ||
restored = _require_from_serialized(mod, path_to_try, toplevel_load) | ||
if isa(restored, Exception) | ||
if isa(restored, ErrorException) && endswith(restored.msg, " uuid did not match cache file.") | ||
# can't use this cache due to a module uuid mismatch, | ||
|
@@ -399,7 +376,7 @@ function require(mod::Symbol) | |
# attempt to load the module file via the precompile cache locations | ||
doneprecompile = false | ||
if JLOptions().use_compilecache != 0 | ||
doneprecompile = _require_search_from_serialized(1, mod, path, last) | ||
doneprecompile = _require_search_from_serialized(mod, path, last) | ||
if !isa(doneprecompile, Bool) | ||
return # success | ||
end | ||
|
@@ -422,7 +399,7 @@ function require(mod::Symbol) | |
# spawn off a new incremental pre-compile task from node 1 for recursive `require` calls | ||
# or if the require search declared it was pre-compiled before (and therefore is expected to still be pre-compilable) | ||
cachefile = compilecache(mod) | ||
m = _require_from_serialized(1, mod, cachefile, last) | ||
m = _require_from_serialized(mod, cachefile, last) | ||
if isa(m, Exception) | ||
warn("The call to compilecache failed to create a usable precompiled cache file for module $name. Got:") | ||
warn(m, prefix="WARNING: ") | ||
|
@@ -435,23 +412,14 @@ function require(mod::Symbol) | |
# just load the file normally via include | ||
# for unknown dependencies | ||
try | ||
if last && myid() == 1 && nprocs() > 1 | ||
# include on node 1 first to check for PrecompilableErrors | ||
eval(Main, :(Base.include_from_node1($path))) | ||
|
||
# broadcast top-level import/using from node 1 (only) | ||
refs = Any[ @spawnat p eval(Main, :(Base.include_from_node1($path))) for p in filter(x -> x != 1, procs()) ] | ||
for r in refs; wait(r); end | ||
else | ||
eval(Main, :(Base.include_from_node1($path))) | ||
end | ||
eval(Main, :(Base.include_from_node1($path))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This risks making the node module state inconsistent since the behavior of |
||
catch ex | ||
if doneprecompile === true || JLOptions().use_compilecache == 0 || !precompilableerror(ex, true) | ||
rethrow() # rethrow non-precompilable=true errors | ||
end | ||
# the file requested `__precompile__`, so try to build a cache file and use that | ||
cachefile = compilecache(mod) | ||
m = _require_from_serialized(1, mod, cachefile, last) | ||
m = _require_from_serialized(mod, cachefile, last) | ||
if isa(m, Exception) | ||
warn(m, prefix="WARNING: ") | ||
# TODO: disable __precompile__(true) error and do normal include instead of error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove the
toplevel_load
bool and just always use this codepath. The other path is only relevant if it needed to also broadcast the file to all workers.