Skip to content

Commit 34070fa

Browse files
authored
add a warning to the docstring for deepcopy (#58416)
This function is surprisingly popular and we often need to warn people against using it. Somehow such a warning never made it into the docs, so here it is.
1 parent 94570e1 commit 34070fa

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

base/deepcopy.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ where `T` is the type to be specialized for, and `dict` keeps track of objects c
2323
so far within the recursion. Within the definition, `deepcopy_internal` should be used
2424
in place of `deepcopy`, and the `dict` variable should be
2525
updated as appropriate before returning.
26+
27+
!!! warning
28+
It is better to avoid this function in favor of custom `copy` methods or use-case-specific
29+
copying functions. `deepcopy` is slow and can easily copy too many objects, or generate an
30+
object that violates invariants, since it does not respect abstraction boundaries.
2631
"""
2732
function deepcopy(@nospecialize x)
2833
isbitstype(typeof(x)) && return x

0 commit comments

Comments
 (0)