Open
Description
Serialization/deserialization of anonymous functions with kwargs fails (no error if we remove the kwarg; p = 1
below, or if we define f(; p = 1) = 0
instead of with a lambda)
MWE
julia> using Serialization
julia> f = (; p = 2) -> 0;
julia> serialize("test.dat", f)
julia> ff = deserialize("test.dat")
#1 (generic function with 1 method)
julia> ff()
ERROR: MethodError: no method matching var"#1#2"(::Int64, ::Serialization.__deserialized_types__.var"##230")
The function `#1#2` exists, but no method is defined for this combination of argument types.
Closest candidates are:
var"#1#2"(::Any, ::var"#1#3")
@ Main REPL[2]:1
Stacktrace:
[1] (::Serialization.__deserialized_types__.var"##230")()
@ Main ./REPL[2]:1
[2] top-level scope
@ REPL[6]:1
Interestingly, if we do
julia> genf() = (; p = 2) -> 0; f = genf();
instead of f = (; p = 2) -> 0
, we get no error, and the deserialized ff()
evaluates correctly
The key difference between the two definitions is apparent in lowering, which may give a clue as to a possible cause/fix
julia> f = (; p = 2) -> 0; code_lowered(f)
1-element Vector{Core.CodeInfo}:
CodeInfo(
1 ─ %1 = Main.:(var"#17#18")
│ %2 = (%1)(2, #self#)
└── return %2
)
julia> genf() = (; p = 2) -> 0; f = genf(); code_lowered(f)
1-element Vector{Core.CodeInfo}:
CodeInfo(
1 ─ %1 = Core.getfield(#self#, Symbol("#24#25"))
│ %2 = (%1)(2, #self#)
└── return %2
)
Thanks to @exaexa for his help in slack isolating the core issue (which affects Distributed in particular)!
Xref: JuliaLang/Distributed.jl#104
CC: @exaexa
Activity