I’m trying to understand how assigning a function to another variable affects type stability. Consider the following example:
f(x) = x # any function
g = f
ff(x) = f(x)
gg(x) = g(x)
Then
@code_warntype f(1) # good
@code_warntype g(1) # good
@code_warntype ff(1) # good
@code_warntype gg(1) # bad
More precisely, for gg
I get
Body::Any
1 ─ %1 = Main.g(x)::Any
In the application I have in mind, f
would be a closure returned by some function, and g
is the name I give to it early on in my code. Then using g
in other functions like gg
would lead to performance problems. Is there a way around this?