Julep: Efficient Hierarchical Mutable Data

My proposal above would look like

struct FieldRef{T}
owner::Any #for GC purposes only
ptr::Ptr{T}
end

and would rely on the hypothetical new Core.Intrinsics.interior_pointerset(owner, ptr, value) thing that writes value to ptr, while applying the GC write-barrier as if value had been written to a field of owner.

That would be relevant for

struct Inner
  x::Vector{Int}
end

mutable struct Owner
  part::Inner
end

reset!(ref::FieldRef{Inner}) = ref[] = Inner(Int[])

owner = Owner(Inner(Int[]))
reset!(getfieldref(owner, :inner)) #needs a GC barrier if owner is old-gen!
2 Likes