Skip to content

datadeps: Implement recursive move! function #622

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpsamaroo
Copy link
Member

Implement a recursive move!(to, from) function that works for generic objects.

From jules.google.com

Implement a recursive `move!(to, from)` function in `src/datadeps.jl`
that works when `to` and `from` objects are of the same type.

The function applies the following logic for each field:
- Simple types (primitives, Symbol, String, Type, Function): uses
  `getfield` and `setfield!`.
- AbstractArray types: uses `copyto!`.
- Skip condition: If the surrounding struct is immutable, the field
  is immutable, and `Base.datatype_pointerfree(typeof(field))` is
  true, the field is skipped.
- Immutable struct fields: If the parent struct is mutable, the
  immutable struct instance is replaced using `setfield!`. If the
  parent is also immutable, recursion occurs if the immutable struct
  field is not pointer-free (to handle mutable contents).
- Other struct types (typically mutable structs): Recurses.

Adds comprehensive tests in `test/datadeps.jl` covering various
scenarios, including simple types, arrays, nested structs (mutable
and immutable parents/fields), and LU factorization objects.

Note: The LU factorization test currently fails with an
`UndefVarError: ipiv_to_perm not defined in LinearAlgebra`. This
appears to be an issue with the Julia test environment or stdlib
loading in the sandbox for that specific function, as Julia 1.11.5
is used and `using LinearAlgebra` is present. The core `move!`
logic for LU objects (handling `factors` and `ipiv` fields) is
otherwise believed to be correct.
@jpsamaroo jpsamaroo changed the title feat: Implement recursive move! function datadeps: Implement recursive move! function Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant