I am trying to fix DocStringExtensions.jl/issues/67, for which I need to get the variable names also for destructured arguments. MWE:
f((x, y), z) = x + y + z
## how to extract something like
((:x, :y), :z)
## from
first(methods(f))
I am trying to fix DocStringExtensions.jl/issues/67, for which I need to get the variable names also for destructured arguments. MWE:
f((x, y), z) = x + y + z
## how to extract something like
((:x, :y), :z)
## from
first(methods(f))
I don’t think that x
and y
exists in the method signature after lowering but that this instead gets transformed to
function f(__xy, z)
x, y = __xy
return x + y + z
end
I guess the lowered form could be analyzed and retrieve back the original variable names but it requires a bit more work
julia> Meta.lower(Main, :(f((x, y), z) = x + y + z))
:($(Expr(:thunk, CodeInfo(
1 ─ $(Expr(:method, :f)) │
│ %2 = (Core.Typeof)(f) │
│ %3 = (Core.svec)(%2, Core.Any, Core.Any) │
│ %4 = (Core.svec)() │
│ %5 = (Core.svec)(%3, %4) │
│ $(Expr(:method, :f, :(%5), CodeInfo(quote │
(Base.indexed_iterate)(#temp#@_2, 1)
x = (Core.getfield)(%1, 1)
#temp#@_6 = (Core.getfield)(%1, 2)
(Base.indexed_iterate)(#temp#@_2, 2, #temp#@_6)
y = (Core.getfield)(%4, 1)
#temp#@_6 = (Core.getfield)(%4, 2)
x + y + z
return %7
end)))
└── return f │
))))