From 959a02980ff2ab61bfa38798f1fca59518dc1f49 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 23 Jan 2019 16:38:54 -0500 Subject: [PATCH] fix `at-everywhere using` in Distributed stdlib (JuliaLang/julia#30804) (cherry picked from commit a670e093b22b40bce661e4c71ea0b21f2b644a34) --- src/macros.jl | 17 +++++------------ test/distributed_exec.jl | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/macros.jl b/src/macros.jl index 15faadb..4285073 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -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 @@ -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)) diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index b82d66e..77341e4 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -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