Skip to content

Commit

Permalink
fix at-everywhere using in Distributed stdlib (#30804)
Browse files Browse the repository at this point in the history
(cherry picked from commit 17c4b02)
  • Loading branch information
JeffBezanson authored and KristofferC committed Feb 11, 2019
1 parent 268257d commit 092dd74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
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

0 comments on commit 092dd74

Please sign in to comment.