-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deepcopy with non-trivial circular references fails in 1.11.2 #56775
Comments
Not sure if related: #26020 |
To offer another example, this caused me some trouble when handling arrays containing circular references: On 1.10.7 I see julia> function make_circular_reference_array()
p = Any[nothing]
p[1] = p
return p
end
make_circular_reference_array (generic function with 1 method)
julia> p = make_circular_reference_array()
1-element Vector{Any}:
1-element Vector{Any}:#= circular reference @-1 =#
julia> p2 = deepcopy(p)
1-element Vector{Any}:
1-element Vector{Any}:#= circular reference @-1 =#
julia> p === p[1]
true
julia> p2 === p2[1]
true which is what I had expected. On 1.11.2 I see julia> function make_circular_reference_array()
p = Any[nothing]
p[1] = p
return p
end
make_circular_reference_array (generic function with 1 method)
julia> p = make_circular_reference_array()
1-element Vector{Any}:
1-element Vector{Any}:#= circular reference @-1 =#
julia> p2 = deepcopy(p)
1-element Vector{Any}:
Any[Any[#= circular reference @-1 =#]]
julia> p === p[1]
true
julia> p2 === p2[1]
false |
Good reproducer @willtebbutt ! Line 127 in 083b24e
The deepcopy_internal construction should register the new copied item in the stackdict before recursing to the children. Failing that, we need to check again when ascending from the stack. So the fix is
|
Thanks for figuring this out @bbrehm -- are you interested in turning this fix into a PR? |
Not sure if this is just a symptom of deepcopy not having much in terms of guaranteed behaviour, but it is no longer consistent with serialize => deserialize.
I tried to recreate it with a simpler structure (e.g. just Arrays which contain themselves) but couldn't. This is the most stripped down version I could create:
Prints the following in Julia 1.11.2:
And this in Julia 1.10.7:
Fwiw: I can work around the problem on my side with the following:
Versioninfo 1.11.2:
Versioninfo 1.10.7:
The text was updated successfully, but these errors were encountered: