Open maartenvd opened 3 years ago
If anyone knows another way to get this to work, I would be very grateful.
You could take a look at https://github.com/c42f/FastClosures.jl.
I tried it out, but the allowed syntax is quite limited. For example, I usually write things like
eigsolve(x,1,:LM) do v
#some multiline function that applies a linear map
end
This is annoying to rewrite to use fastclosures, I think I would have to do things like
@closure function apply_map(v)
#transform v
end
eigsolve(apply_map,x,1;LM)
I also had problems where type stability was still incorrectly lost, and it will never be able to correct for the case where the closure changes a variable outside it's scope, but keeps the type.
EDIT : I was wrong about the syntax, fastclosures supports do blocks
A good workaround for now is:
function f(a::T) where T
a::T = a
...
While there are a number of bug reports open about stackoverflows when defining functions (so this issue is possibly a duplicate), the examples looked quite different : #36185 , #36804,#36544
The issue I'm actually trying to solve is that when inference fails, it causes really significant startup overhead (possibly because the packages I'm using are template heavy ?). I often lose type stability because I use anonymous functions, which depend on variables outside their scope (so like in the example). This is really annoying, and the only workaround I found so far was to sprinkle let blocks everywhere. Of course - ideally - the workaround shouldn't be necessary and julia would simply stop failing to infer those things. I was trying out the following macro as a workaround, which would then fix the types of the variables it get's passed to:
If anyone knows another way to get this to work, I would be very grateful.