Skip to content
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

fix at-everywhere using in Distributed stdlib #30804

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions stdlib/Distributed/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,17 @@ end
extract_imports!(imports, x) = imports
function extract_imports!(imports, ex::Expr)
if Meta.isexpr(ex, (:import, :using))
m = ex.args[1]
if isa(m, Expr) && m.head === :(:)
push!(imports, m.args[1].args[1])
else
for a in ex.args
push!(imports, a.args[1])
end
end
push!(imports, ex)
elseif Meta.isexpr(ex, :let)
extract_imports!(imports, ex.args[2])
elseif Meta.isexpr(ex, (:toplevel, :block))
for i in eachindex(ex.args)
extract_imports!(imports, ex.args[i])
for arg in ex.args
extract_imports!(imports, arg)
end
end
return imports
end
extract_imports(x) = extract_imports!(Symbol[], x)
extract_imports(x) = extract_imports!(Any[], x)

"""
@everywhere [procs()] expr
Expand Down Expand Up @@ -183,7 +176,7 @@ macro everywhere(ex)
end

macro everywhere(procs, ex)
imps = [Expr(:import, m) for m in extract_imports(ex)]
imps = extract_imports(ex)
return quote
$(isempty(imps) ? nothing : Expr(:toplevel, imps...)) # run imports locally first
let ex = $(Expr(:quote, ex)), procs = $(esc(procs))
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Distributed: launch, manage
include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl"))

@test Distributed.extract_imports(:(begin; import Foo, Bar; let; using Baz; end; end)) ==
[:Foo, :Bar, :Baz]
Any[:(import Foo, Bar), :(using Baz)]

# Test a few "remote" invocations when no workers are present
@test remote(myid)() == 1
Expand Down