Skip to content

Commit

Permalink
serialize global bindings to Types and Modules (#22172)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmurthy authored Jun 1, 2017
1 parent f74e55e commit ecc3a81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions base/distributed/clusterserialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ecc3a81

Please sign in to comment.