# Better compile-time computation facility

**URL:** <https://discourse.julialang.org/t/better-compile-time-computation-facility/101913>\
**Category:** Internals & Design\
**Created:** [July 21, 2023, 11:08pm UTC](https://discourse.julialang.org/t/better-compile-time-computation-facility/101913 "2023-07-21T23:08:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [July 21, 2023, 11:08pm UTC](https://discourse.julialang.org/t/better-compile-time-computation-facility/101913/1 "2023-07-21T23:08:38Z")

</div>

We need better things to ensure certain stuffs (like static array size or complicated types) gets computed at compile time. If only there were some function decorators or some “const-expression” which says “if the input is compile-time, run the function at compile time, compile-time if/else, etc…, maybe even error out if they aren’t at compile-time. Currently, lots of stuffs are left at the mercy of constant-propagation.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 21, 2023, 11:47pm UTC](https://discourse.julialang.org/t/better-compile-time-computation-facility/101913/2 "2023-07-21T23:47:48Z")

</div>

Have you considered macros? The concept of compile time can be a bit fuzzy in Julia since we are compiling code all the time. Macros on the other hand perform operations at parse time.

---

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [July 22, 2023, 12:46am UTC](https://discourse.julialang.org/t/better-compile-time-computation-facility/101913/3 "2023-07-22T00:46:27Z")

</div>

Yes, I should have added, “without going full macros”. Macros are solutions but it comes with all the headaches of metaprogramming.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 22, 2023, 12:56am UTC](https://discourse.julialang.org/t/better-compile-time-computation-facility/101913/4 "2023-07-22T00:56:17Z")

</div>

> [@Tarny\_GG\_Channie](#):
>
> “const-expression”

Not necessary because Julia is not AOT compiled. Instead you would just compute the expression, assign it to a `const` global, and use that in functions.

> [@Tarny\_GG\_Channie](#):
>
> static array size or complicated types

Generated functions do computations on argument types and parameters at guaranteed compile-time. Definitely a bit harder than generic functions, feels more like a macro because you’re generating function body expressions. So if you can call simple functions like `eltype(A)` and let the compiler do those at compile time in a generic function, do that before resorting to generated functions.
