From ecc3a811311f3a5bf4f5f45c1c5959bb581d26c2 Mon Sep 17 00:00:00 2001 From: Amit Murthy Date: Thu, 1 Jun 2017 21:18:08 +0530 Subject: [PATCH] serialize global bindings to Types and Modules (#22172) --- base/distributed/clusterserialize.jl | 3 +-- test/distributed_exec.jl | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/base/distributed/clusterserialize.jl b/base/distributed/clusterserialize.jl index 0454e1e668bf5..163d8d9636284 100644 --- a/base/distributed/clusterserialize.jl +++ b/base/distributed/clusterserialize.jl @@ -89,8 +89,7 @@ function serialize(s::ClusterSerializer, g::GlobalRef) sym = g.name if g.mod === Main && isdefined(g.mod, sym) v = getfield(Main, sym) - if !isa(v, DataType) && !isa(v, Module) && - (binding_module(Main, sym) === Main) && (s.anonfunc_id != 0) + if (binding_module(Main, sym) === Main) && (s.anonfunc_id != 0) push!(get!(s.glbs_in_tnobj, s.anonfunc_id, []), sym) end end diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index be074fedc9998..4583fbf237d31 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -1424,6 +1424,27 @@ global v4 = v3 @test remotecall_fetch(()->isdefined(Main, :v3), id_other) @test remotecall_fetch(()->isdefined(Main, :v4), id_other) +# Global references to Types and Modules should work if they are locally defined +global v5 = Int +global v6 = Base.Distributed +@test remotecall_fetch(()->v5, id_other) === Int +@test remotecall_fetch(()->v6, id_other) === Base.Distributed + +struct FooStructLocal end +module FooModLocal end +v5 = FooStructLocal +v6 = FooModLocal +@test_throws RemoteException remotecall_fetch(()->v5, id_other) +@test_throws RemoteException remotecall_fetch(()->v6, id_other) + +@everywhere struct FooStructEverywhere end +@everywhere module FooModEverywhere end +v5 = FooStructEverywhere +v6 = FooModEverywhere +@test remotecall_fetch(()->v5, id_other) === FooStructEverywhere +@test remotecall_fetch(()->v6, id_other) === FooModEverywhere + + # Test that a global is not being repeatedly serialized when # a) referenced multiple times in the closure # b) hash value has not changed.