# \#generated

**URL:** https://discourse.julialang.org/tag/generated/1223.md

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

---

## [Method lookup in @generated functions](https://discourse.julialang.org/t/method-lookup-in-generated-functions/138047)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 12\
**Last updated:** [July 10, 2026, 10:51pm UTC](https://discourse.julialang.org/t/method-lookup-in-generated-functions/138047 "2026-07-10T22:51:55Z")

</div>

This works as I would expect it to… julia\> f(x::Int) = "Int" f(x::Float64) = "Float64" @generated function g(x) if hasmethod(f, Tuple{x}) return :(f(x)) else …

---

## [Limitations of generated functions versus macros or functions](https://discourse.julialang.org/t/limitations-of-generated-functions-versus-macros-or-functions/136910)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 11\
**Last updated:** [April 29, 2026, 3:46pm UTC](https://discourse.julialang.org/t/limitations-of-generated-functions-versus-macros-or-functions/136910 "2026-04-29T15:46:31Z")

</div>

Tentatively writing a generated function and relearning things, and ran into a couple questions: The most warned limitation of generated functions is most side effects in the method body (throwing errors is a notable e…

---

## [Extract unique types between two Tuples at compile time](https://discourse.julialang.org/t/extract-unique-types-between-two-tuples-at-compile-time/135476)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 10\
**Last updated:** [February 9, 2026, 7:20pm UTC](https://discourse.julialang.org/t/extract-unique-types-between-two-tuples-at-compile-time/135476 "2026-02-09T19:20:56Z")

</div>

Hello, I have two Tuples x and y containing objects of different types. I now want to create at compile time a list containing only the unique types. I have tried this function test2(x::T1, y::T2) where {T1 \<: Tuple, T…

---

## [Convert or Reinterpret Between NamedTuple and SVector](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 7\
**Last updated:** [December 17, 2025, 7:33pm UTC](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600 "2025-12-17T19:33:07Z")

</div>

My question is related to Vector to NamedTuple? Assume my NamedTuple contains only floating point values T and SVector{N, T} entries, e.g., using StaticArrays nt = ( a = rand(), b = SA\[1.0, 2.0 ,3.0\] ) Taking such a N…

---

## [What do generated functions actually disallow?](https://discourse.julialang.org/t/what-do-generated-functions-actually-disallow/133294)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 5\
**Last updated:** [October 21, 2025, 6:46am UTC](https://discourse.julialang.org/t/what-do-generated-functions-actually-disallow/133294 "2025-10-21T06:46:12Z")

</div>

The Manual states the following restrictions: Generated functions are only permitted to call functions that were defined before the definition of the generated function. (Failure to follow this may result in getting M…

---

## [Capturing warnings inside generated functions](https://discourse.julialang.org/t/capturing-warnings-inside-generated-functions/132535)

<div class="topic-metadata">

**Author:** [@giordano](https://discourse.julialang.org/u/giordano)\
**Replies:** 3\
**Last updated:** [September 21, 2025, 12:50pm UTC](https://discourse.julialang.org/t/capturing-warnings-inside-generated-functions/132535 "2025-09-21T12:50:53Z")

</div>

Is there a way to capture logging messages (e.g. warnings) issued during compilation, for example from inside a generated function? For example julia\> using Logging julia\> @generated foo() = @warn "this warning is emi…

---

## [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 to debug generated function and FunctionWrappers?](https://discourse.julialang.org/t/how-to-debug-generated-function-and-functionwrappers/115804)

<div class="topic-metadata">

**Author:** [@wangyunyueyueniao](https://discourse.julialang.org/u/wangyunyueyueniao)\
**Replies:** 0\
**Last updated:** [June 18, 2024, 12:45pm UTC](https://discourse.julialang.org/t/how-to-debug-generated-function-and-functionwrappers/115804 "2024-06-18T12:45:06Z")

</div>

I need to step through a wrapped generated function in OrdinaryDiffEq. However I don’t even know how to debug in a generated function nor a wrapped function (which is a pointer in wrapper). Could someone please show me a…

---

## [Questions about macro interpolation inside @generated](https://discourse.julialang.org/t/questions-about-macro-interpolation-inside-generated/103922)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 12\
**Last updated:** [September 17, 2023, 10:38pm UTC](https://discourse.julialang.org/t/questions-about-macro-interpolation-inside-generated/103922 "2023-09-17T22:38:26Z")

</div>

I would like to have a macro @m f g that produces @generated function f(x) quote g(x) end end where f and g are the macro parameters. This has essentially been discussed in @simeonschaub’s solution, adapted to my …

---

## [Why are functions that are never called getting compiled?](https://discourse.julialang.org/t/why-are-functions-that-are-never-called-getting-compiled/100072)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 8\
**Last updated:** [June 10, 2023, 10:25pm UTC](https://discourse.julialang.org/t/why-are-functions-that-are-never-called-getting-compiled/100072 "2023-06-10T22:25:28Z")

</div>

Previously I asked about, and solved, a problem with compilation of a function inside generated code - the problem was that multiple instances of a function were getting compiled without being called. I would like to avo…

---

## [Using ntuple() in generated function](https://discourse.julialang.org/t/using-ntuple-in-generated-function/100020)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 5\
**Last updated:** [June 8, 2023, 12:48am UTC](https://discourse.julialang.org/t/using-ntuple-in-generated-function/100020 "2023-06-08T00:48:47Z")

</div>

I have found that using ntuple in generated functions produces better code (faster, and with fewer allocations), than constructing the tuple expression manually. Presumably the code that ntuple generates is more inferabl…

---

## [@generated functions aggressively disallowing lambdas (and accusations of impurity! how impious!)](https://discourse.julialang.org/t/generated-functions-aggressively-disallowing-lambdas-and-accusations-of-impurity-how-impious/92072)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 0\
**Last updated:** [December 24, 2022, 1:10am UTC](https://discourse.julialang.org/t/generated-functions-aggressively-disallowing-lambdas-and-accusations-of-impurity-how-impious/92072 "2022-12-24T01:10:36Z")

</div>

This seems a bit aggressive: Code 1: julia\> @generated f(x) = :( map(i-\>i, x) ) f (generic function with 1 method) julia\> f((1,2,3)) ERROR: The function body AST defined by this @generated function is not pure. This l…

---

## [Metaprogramming with @generated](https://discourse.julialang.org/t/metaprogramming-with-generated/91248)

<div class="topic-metadata">

**Author:** [@chelseas](https://discourse.julialang.org/u/chelseas)\
**Replies:** 6\
**Last updated:** [December 6, 2022, 8:08am UTC](https://discourse.julialang.org/t/metaprogramming-with-generated/91248 "2022-12-06T08:08:34Z")

</div>

I would like to write a simple function where I give it the operator I would like to apply as a symbol and it returns a runnable function that I can actually use. e.g. @generated genmyfun( op , args) = :($op ( args )…
