Polyester.jl
Polyester.jl copied to clipboard
Destructuring not recognized
Hi,
I've encountered a case where Polyester.jl does not know how to handle the destructuring syntax introduced in Julia 1.7:
using Polyester
struct A
a
b
end
x = A(1,2)
Threads.@threads for i in 1:2
(; a, b) = x
end
@batch for i in 1:2
(; a, b) = x
end
The @batch
loop returns
ERROR: LoadError: "Don't know how to handle:\n \$(Expr(:parameters, :a, :b))"
bump, do we need a pass in the macro to transform this into a bunch of getproperty?
bump, do we need a pass in the macro to transform this into a bunch of getproperty?
Yeah, that'd be a reasonable approach.
The alternative would be handling Expr(:parameters,...)
, where those parameters would be added to the symbols defined in the loop.
Want to take a stab at it?
https://github.com/JuliaSIMD/Polyester.jl/blob/f49a3081f0005e920fa7542cd3ce4710925efddb/src/closure.jl#L18-L30 can handle
julia> y = (1,2);
julia> @batch for i in 1:2
(a, b) = y
end
so it should be straightforward to adapt to support (; a, b) = x
.
Although preprocessing this into getproperty
calls would work too, and not require as much looking into the internals, at the cost of requiring an extra pass over the Expr
making macro expansion slower.
where even is this signature defined
define_tup!(defined, a)
also this doesn't quite work, this logic assumes each element in ex.args
gets replaced by a gensym
but when a
is a :parameters
expression, it needs to inflate into multiple entries in ex.args
where even is this signature defined
define_tup!(defined, a)
That method does not exist. That is a bug.