Skip to content

Commit

Permalink
deepcopy: inform the compiler that the type is unchanged (#34066)
Browse files Browse the repository at this point in the history
This uses the internal jl_set_nth_field and arrayset functions which expect the type to be unchanged
(and we type-assert this elsewhere), so do it here before we would potentially reach the assert/abort in those functions.
  • Loading branch information
vtjnash authored Dec 11, 2019
1 parent 1432c5a commit 1baeb21
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ function deepcopy_internal(@nospecialize(x), stackdict::IdDict)
end
for i in 1:nfields(x)
if isdefined(x,i)
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), y, i-1,
deepcopy_internal(getfield(x,i), stackdict))
xi = getfield(x, i)
xi = deepcopy_internal(xi, stackdict)::typeof(xi)
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), y, i-1, xi)
end
end
return y::T
Expand All @@ -90,7 +91,7 @@ function _deepcopy_array_t(@nospecialize(x), T, stackdict::IdDict)
if ccall(:jl_array_isassigned, Cint, (Any, Csize_t), x, i-1) != 0
xi = ccall(:jl_arrayref, Any, (Any, Csize_t), x, i-1)
if !isbits(xi)
xi = deepcopy_internal(xi, stackdict)
xi = deepcopy_internal(xi, stackdict)::typeof(xi)
end
ccall(:jl_arrayset, Cvoid, (Any, Any, Csize_t), dest, xi, i-1)
end
Expand Down

0 comments on commit 1baeb21

Please sign in to comment.