Stream: helpdesk (published)

Topic: Recursive `ismutable`


view this post on Zulip Kyle Daruwalla (Aug 10 2021 at 23:08):

Does there already exist functionality for detecting whether a variable has any mutable data? So something like ismutable(x) except that it checks the mutability of the fields of x recursively.

view this post on Zulip chriselrod (Aug 11 2021 at 00:53):

Not exactly that, but isbits(x), although unions can yield false negatives.
Also Base.allocatedinline(typeof(x)) can avoid these:

julia> struct MaybeMissing{T}
           x::Union{Missing,T}
       end

julia> x = MaybeMissing(1.2)
MaybeMissing{Float64}(1.2)

julia> Base.isbits(x)
false

julia> Base.allocatedinline(typeof(x))
true

Last updated: Dec 28 2024 at 04:38 UTC