# \#runtimegeneratedfunc

**URL:** https://discourse.julialang.org/tag/runtimegeneratedfunc/723.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Can I notify a generated function to recompile if called again](https://discourse.julialang.org/t/can-i-notify-a-generated-function-to-recompile-if-called-again/132271)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 4\
**Last updated:** [September 11, 2025, 1:22pm UTC](https://discourse.julialang.org/t/can-i-notify-a-generated-function-to-recompile-if-called-again/132271 "2025-09-11T13:22:10Z")

</div>

Let’s say I have a @generated function of some kind which already triggered compilation at some point given the types of some arguments. Say that something changes in those arguments (fields), and I can catch that this h…

---

## [Is this generated function for struct2tuple safe to use?](https://discourse.julialang.org/t/is-this-generated-function-for-struct2tuple-safe-to-use/132086)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 6\
**Last updated:** [September 4, 2025, 10:42pm UTC](https://discourse.julialang.org/t/is-this-generated-function-for-struct2tuple-safe-to-use/132086 "2025-09-04T22:42:56Z")

</div>

I’m not really sure if this function could be used safely when I have a struct with mutable fields in it: @generated function struct2tuple(x::T) where T n = fieldcount(T) exprs = \[:(getfield(x, $(i))) for i in 1…

---

## [How does RuntimeGeneratedFunction ensure correct dependencies are loaded?](https://discourse.julialang.org/t/how-does-runtimegeneratedfunction-ensure-correct-dependencies-are-loaded/119569)

<div class="topic-metadata">

**Author:** [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Replies:** 3\
**Last updated:** [September 19, 2024, 4:27am UTC](https://discourse.julialang.org/t/how-does-runtimegeneratedfunction-ensure-correct-dependencies-are-loaded/119569 "2024-09-19T04:27:22Z")

</div>

How does RuntimeGeneratedFunction ensure that the correct dependency libraries are available? This example compiles an expression which includes the constant twoπ which is defined in IrrationalConstants.jl and used in D…

---

## [How does RuntimeGeneratedFunctions.jl work?](https://discourse.julialang.org/t/how-does-runtimegeneratedfunctions-jl-work/112925)

<div class="topic-metadata">

**Author:** [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Replies:** 3\
**Last updated:** [September 2, 2024, 9:53am UTC](https://discourse.julialang.org/t/how-does-runtimegeneratedfunctions-jl-work/112925 "2024-09-02T09:53:34Z")

</div>

Hi, Could you help me by explaining how does RuntimeGeneratedFunctions.jl work, i.e., how it generates functions without world-age issue? I would really appreciate it.

---

## [Can RuntimeGeneratedFunctions.jl cause memory leak issue?](https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261)

<div class="topic-metadata">

**Author:** [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Replies:** 1\
**Last updated:** [March 31, 2024, 4:33pm UTC](https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261 "2024-03-31T16:33:34Z")

</div>

Hi, I am writing a Genetic Programming-styled code to search for solutions to specific problems. The solutions are in the form of functions. Thus, I use RuntimeGeneratedFunctions.jl to generate functions in runtime in o…

---

## [Symbolics build\_function and usage](https://discourse.julialang.org/t/symbolics-build-function-and-usage/101005)

<div class="topic-metadata">

**Author:** [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Replies:** 1\
**Last updated:** [August 5, 2023, 10:59pm UTC](https://discourse.julialang.org/t/symbolics-build-function-and-usage/101005 "2023-08-05T22:59:29Z")

</div>

Hi, I’m having some trouble using the build\_function tool within the Symbolics package, and a question about how build\_function works. The issue I am having is that executing the function generated by build\_function co…

---

## [Macro to create a generated function](https://discourse.julialang.org/t/macro-to-create-a-generated-function/99135)

<div class="topic-metadata">

**Author:** [@devetak-m](https://discourse.julialang.org/u/devetak-m)\
**Replies:** 3\
**Last updated:** [May 20, 2023, 7:51am UTC](https://discourse.julialang.org/t/macro-to-create-a-generated-function/99135 "2023-05-20T07:51:57Z")

</div>

Hello. I want to create a macro that reads: macro store(agent, value) f\_name = Symbol("store\_", value) f = quote @inline @generated function $f\_name(a, v) return quote a.value = v end …

---

## [Minimal self-containing example of code transformation using generated functions?](https://discourse.julialang.org/t/minimal-self-containing-example-of-code-transformation-using-generated-functions/88535)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 3\
**Last updated:** [October 25, 2022, 4:39pm UTC](https://discourse.julialang.org/t/minimal-self-containing-example-of-code-transformation-using-generated-functions/88535 "2022-10-25T16:39:12Z")

</div>

Cassette, IRTools, Diffractor and others use generated functions to transform a method’s CodeInfo / IRCode. Although I used these tools dozen times, I never managed to understand or reproduce it. Is there a minimal self-…

---

## [Improve this function for merging tuples so that the return type could be accurately inferred](https://discourse.julialang.org/t/improve-this-function-for-merging-tuples-so-that-the-return-type-could-be-accurately-inferred/84893)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [July 28, 2022, 6:57am UTC](https://discourse.julialang.org/t/improve-this-function-for-merging-tuples-so-that-the-return-type-could-be-accurately-inferred/84893 "2022-07-28T06:57:35Z")

</div>

I implemented the function merged\_tuples for merging tuples in given order while preserving intra-tuple order. It seems that Julia isn’t able to infer the return types accurately, however (using Test.@inferred): julia\> …

---

## [Losing type stability after passing function output from Symbolics.jl build\_function() as parameter elsewhere](https://discourse.julialang.org/t/losing-type-stability-after-passing-function-output-from-symbolics-jl-build-function-as-parameter-elsewhere/84844)

<div class="topic-metadata">

**Author:** [@allicient](https://discourse.julialang.org/u/allicient)\
**Replies:** 3\
**Last updated:** [July 27, 2022, 2:49am UTC](https://discourse.julialang.org/t/losing-type-stability-after-passing-function-output-from-symbolics-jl-build-function-as-parameter-elsewhere/84844 "2022-07-27T02:49:55Z")

</div>

This is probably expected behaviour but I don’t understand quite why it’s happening, and suspect it’d be useful to know. As part of a small library, I’ve been using Symbolics.jl to take user-supplied expressions, compil…

---

## [Recursive @generated functions with function barriers causes allocations](https://discourse.julialang.org/t/recursive-generated-functions-with-function-barriers-causes-allocations/76910)

<div class="topic-metadata">

**Author:** [@jg-854](https://discourse.julialang.org/u/jg-854)\
**Replies:** 6\
**Last updated:** [February 25, 2022, 1:49pm UTC](https://discourse.julialang.org/t/recursive-generated-functions-with-function-barriers-causes-allocations/76910 "2022-02-25T13:49:48Z")

</div>

Hey! I am using generated functions in a recursive manner, and I have formed a contrived example which highlights how unnecessary allocations can occur. First, I will show you the efficient case @generated function Fac…

---

## [Create a struct with uninitialized fields](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 4\
**Last updated:** [October 10, 2021, 2:08pm UTC](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967 "2021-10-10T14:08:06Z")

</div>

Having a mutable struct, e.g.: mutable struct Point x y end is it possible to construct its instance with uninitialized fields and set them later? E.g.: p = create\_uninitialized(Point) # \<-- anything like t…

---

## [Generated functions for performance auto-tuning](https://discourse.julialang.org/t/generated-functions-for-performance-auto-tuning/66821)

<div class="topic-metadata">

**Author:** [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Replies:** 7\
**Last updated:** [August 23, 2021, 2:31am UTC](https://discourse.julialang.org/t/generated-functions-for-performance-auto-tuning/66821 "2021-08-23T02:31:22Z")

</div>

To get the best performance across different inputs, we often have multiple implementations, and choose which one to use based on the input given. For example, for array traversals we may want to unroll loops for small a…

---

## [Exporting a \`RuntimeGeneratedFunction\`](https://discourse.julialang.org/t/exporting-a-runtimegeneratedfunction/63628)

<div class="topic-metadata">

**Author:** [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Replies:** 4\
**Last updated:** [June 28, 2021, 10:34pm UTC](https://discourse.julialang.org/t/exporting-a-runtimegeneratedfunction/63628 "2021-06-28T22:34:11Z")

</div>

I have a ModelingToolkit.ODESystem in a package called AstrodynamicalModels. I want to export an ODEFunction, which uses RuntimeGeneratedFunctions to avoid world-age issues. When I import AstrodynamicalModels, and try t…

---

## [How to get the current world age inside a generated function?](https://discourse.julialang.org/t/how-to-get-the-current-world-age-inside-a-generated-function/62969)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 5\
**Last updated:** [June 15, 2021, 10:57pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-world-age-inside-a-generated-function/62969 "2021-06-15T22:57:37Z")

</div>

A generated function I’m writing needs to determine if its allowed to call a function its been passed, or if that would result in a world-age error (in which case it would fall back to something else). As part of this, I…

---

## [Dynamically Create a Function - Initial Idea with eval failed due to World Age Issue](https://discourse.julialang.org/t/dynamically-create-a-function-initial-idea-with-eval-failed-due-to-world-age-issue/49139)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 19\
**Last updated:** [October 28, 2020, 2:51pm UTC](https://discourse.julialang.org/t/dynamically-create-a-function-initial-idea-with-eval-failed-due-to-world-age-issue/49139 "2020-10-28T14:51:42Z")

</div>

Hey all, I’m struggling to implement a certain problem. My current situation is the following: Some parts of my project consist of using Tullio functions. Since my arrays can be of arbitrary dimensions and I want to ap…

---

## [Macro to sum over short loop](https://discourse.julialang.org/t/macro-to-sum-over-short-loop/42574)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 9\
**Last updated:** [July 6, 2020, 9:23am UTC](https://discourse.julialang.org/t/macro-to-sum-over-short-loop/42574 "2020-07-06T09:23:23Z")

</div>

I find myself writing code like this repeatedly function ke(I::CartesianIndex{d},u::Array{Float64}) where d s = 0. for i in 1:d s+=u\[I,i\]^2 end return 0.5s end and wanted to give Julia’s macros a try.…

---

## [Understanding generated functions](https://discourse.julialang.org/t/understanding-generated-functions/10092)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 7\
**Last updated:** [October 27, 2019, 6:21am UTC](https://discourse.julialang.org/t/understanding-generated-functions/10092 "2019-10-27T06:21:05Z")

</div>

Hi all. I’m trying to understand how generated functions work. From the 0.6 manual: A very special macro is @generated, which allows you to define so-called generated functions. These have the capability to generate …

---

## [How do I write a macro for evaluating polynomial derivatives?](https://discourse.julialang.org/t/how-do-i-write-a-macro-for-evaluating-polynomial-derivatives/20410)

<div class="topic-metadata">

**Author:** [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Replies:** 13\
**Last updated:** [February 4, 2019, 3:42pm UTC](https://discourse.julialang.org/t/how-do-i-write-a-macro-for-evaluating-polynomial-derivatives/20410 "2019-02-04T15:42:53Z")

</div>

I am working with splines, and I would like to evaluate polynomials along with their derivatives using all sorts of nice tricks like @evalpoly and @SArray. The function below gives an idea. It does not look great, though…
