# I have a function where I would like to move something from runtime to compile-tim

**URL:** <https://discourse.julialang.org/t/i-have-a-function-where-i-would-like-to-move-something-from-runtime-to-compile-tim/56681>\
**Category:** General Usage\
**Created:** [March 7, 2021, 4:02pm UTC](https://discourse.julialang.org/t/i-have-a-function-where-i-would-like-to-move-something-from-runtime-to-compile-tim/56681 "2021-03-07T16:02:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 7, 2021, 4:02pm UTC](https://discourse.julialang.org/t/i-have-a-function-where-i-would-like-to-move-something-from-runtime-to-compile-tim/56681/1 "2021-03-07T16:02:28Z")

</div>

I have a function where I would like to move something from runtime to compile-time. It looks similar to this

```julia
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 :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615132921020200?thread_ts=1615132921.020200&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [March 7, 2021, 7:13pm UTC](https://discourse.julialang.org/t/i-have-a-function-where-i-would-like-to-move-something-from-runtime-to-compile-tim/56681/2 "2021-03-07T19:13:48Z")

</div>

From Slack:

This seems not to be possible. However, my use case was well suited for [generated functions](https://docs.julialang.org/en/v1/manual/metaprogramming/#Generated-functions), as suggested by Simeon Schaub.
