I have a function where I would like to move something from runtime to compile-time. It looks similar to this
function foo(x::Int, y::Val{Z}) where Z
table = calc_table(Z)
bar(table, x)
end
I would like to move the calc_table
to compile time, since the computation only depends on compile time constants. But the table allocates an array, filling it in, before converting it the returned tuple. I think somehow the allocation means the code is not side-effect free, and so the compiler will not move it to compile time.
How can I tell the compiler “you can consider this a pure function, just go ahead and constant fold it”?
Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message ) (More Info)