From 10d05935dca01d0f6683ebd086e9e96e300d827b Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 26 Sep 2015 14:25:39 -0500 Subject: [PATCH 1/2] Circumvent type-instability of deepcopy --- base/deepcopy.jl | 2 +- test/copy.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/deepcopy.jl b/base/deepcopy.jl index c0d4e74d4a795..7ffeb232f02ff 100644 --- a/base/deepcopy.jl +++ b/base/deepcopy.jl @@ -5,7 +5,7 @@ # Note: deepcopy_internal(::Any, ::ObjectIdDict) is # only exposed for specialization by libraries -deepcopy(x) = deepcopy_internal(x, ObjectIdDict()) +deepcopy(x) = deepcopy_internal(x, ObjectIdDict())::typeof(x) deepcopy_internal(x::Union{Symbol,LambdaInfo,TopNode,GlobalRef,DataType,Union,Task}, stackdict::ObjectIdDict) = x diff --git a/test/copy.jl b/test/copy.jl index 781c6648d86eb..0d6b2c0fecf2a 100644 --- a/test/copy.jl +++ b/test/copy.jl @@ -50,7 +50,7 @@ end # test behavior of shallow and deep copying let a = Any[[1]], q = QuoteNode([1]) - ca = copy(a); dca = deepcopy(a) + ca = copy(a); dca = @inferred(deepcopy(a)) @test ca !== a @test ca[1] === a[1] @test dca !== a From 32e7d756c977de00ba8cce7fd9181bf286562732 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 5 Apr 2016 18:25:39 -0500 Subject: [PATCH 2/2] Fix deepcopy for SharedArray --- base/sharedarray.jl | 4 ++-- test/parallel_exec.jl | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 36b25ebe7092a..e15fdc05473f2 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -281,8 +281,8 @@ convert{TS,TA,N}(::Type{SharedArray{TS,N}}, A::Array{TA,N}) = (S = SharedArray(T function deepcopy_internal(S::SharedArray, stackdict::ObjectIdDict) haskey(stackdict, S) && return stackdict[S] - # Note: copy can be used here because SharedArrays are restricted to isbits types - R = copy(S) + R = SharedArray(eltype(S), size(S); pids = S.pids) + copy!(sdata(R), sdata(S)) stackdict[S] = R return R end diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index c72893cdf34e5..de087881ed66c 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -401,6 +401,15 @@ pids_d = procs(d) remotecall_fetch(setindex!, pids_d[findfirst(id->(id != myid()), pids_d)], d, 1.0, 1:10) @test ds != d @test s != d +copy!(d, s) +@everywhere setid!(A) = A[localindexes(A)] = myid() +@sync for p in procs(ds) + @async remotecall_wait(setid!, p, ds) +end +@test d == s +@test ds != s +@test first(ds) == first(procs(ds)) +@test last(ds) == last(procs(ds)) # SharedArray as an array @@ -841,4 +850,3 @@ end v15406 = remotecall_wait(() -> 1, id_other) fetch(v15406) remotecall_wait(t -> fetch(t), id_other, v15406) -